Skip to content

Commit

Permalink
Added the possibility to consult-rip/grep the selected region
Browse files Browse the repository at this point in the history
Starting to experiment with combobulate
  • Loading branch information
mattiasdrp committed Apr 7, 2024
1 parent a0aece6 commit 2dbef2d
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 43 deletions.
2 changes: 1 addition & 1 deletion emacs
Submodule emacs updated 54 files
+2 −0 CONTRIBUTE
+593 −1 ChangeLog.4
+1 −1 README
+3 −1 admin/authors.el
+7 −0 admin/make-tarball.txt
+2 −2 admin/notes/bugtracker
+1 −1 configure.ac
+9 −2 doc/emacs/basic.texi
+7 −1 doc/emacs/files.texi
+19 −9 doc/emacs/killing.texi
+4 −1 doc/emacs/rmail.texi
+1 −1 doc/lispref/control.texi
+7 −2 doc/lispref/display.texi
+8 −6 doc/lispref/minibuf.texi
+1 −1 doc/lispref/strings.texi
+7 −5 doc/lispref/tips.texi
+1 −1 doc/misc/trampver.texi
+29 −21 etc/AUTHORS
+2 −0 etc/HISTORY
+32 −9 etc/NEWS
+26 −0 etc/PROBLEMS
+1 −1 lisp/calendar/calendar.el
+1 −1 lisp/emacs-lisp/cl-macs.el
+12 −9 lisp/emacs-lisp/comp.el
+8 −4 lisp/emacs-lisp/edebug.el
+1 −1 lisp/emacs-lisp/shortdoc.el
+6 −2 lisp/emacs-lisp/warnings.el
+8 −0 lisp/files.el
+3 −3 lisp/format-spec.el
+1 −0 lisp/gnus/mm-view.el
+12 −4 lisp/image.el
+1 −1 lisp/info.el
+1 −1 lisp/keymap.el
+29 −16 lisp/ldefs-boot.el
+27 −27 lisp/leim/quail/vnvni.el
+4 −4 lisp/net/trampver.el
+8 −1 lisp/org/org-macro.el
+25 −2 lisp/org/org.el
+13 −2 lisp/progmodes/csharp-mode.el
+1 −0 lisp/progmodes/typescript-ts-mode.el
+4 −3 lisp/sqlite.el
+9 −2 lisp/term.el
+1 −1 lisp/textmodes/bibtex.el
+1 −1 msdos/sed2v2.inp
+1 −1 nt/README.W32
+8 −2 src/buffer.c
+21 −5 src/composite.c
+1 −1 src/fileio.c
+3 −3 src/lread.c
+10 −7 src/window.c
+97 −0 test/lisp/progmodes/csharp-mode-resources/indent.erts
+30 −0 test/lisp/progmodes/csharp-mode-tests.el
+14 −0 test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
+51 −0 test/lisp/sqlite-tests.el
92 changes: 71 additions & 21 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,9 @@ debian, and derivatives). On most it's 'fd'.")
"M-u" 'upcase-dwim
"C-f" 'fill-region
"C-q" 'selected-off
"M-s r" 'reverse-region
"M-s s" 'sort-lines
"M-s w" 'mdrp/sort-words
"C-c s r" 'reverse-region
"C-c s s" 'sort-lines
"C-c s w" 'mdrp/sort-words
"C-<return>" 'hide-region-hide
"C-p" '(hide-region-pin :which-key "Pins the selected region on top of the current window"))
:config (message "`selected' loaded"))
Expand Down Expand Up @@ -2092,7 +2092,7 @@ with a prefix ARG."
"C-M-p" #'vertico-previous-group
"?" #'minibuffer-completion-help
"M-RET" #'embark-dwim ;; pick some comfortable binding
"C-<up>" #'other-window
;; "C-<up>" #'other-window
)
(:keymaps 'minibuffer-local-map
"M-h" #'backward-kill-word)
Expand Down Expand Up @@ -2241,8 +2241,20 @@ with a prefix ARG."
;; after lazily loading the package.
:config

;; (defun consult-line-repeat ()
;; (interactive)
(defun mdrp/consult-with-region (old-consult-function &optional dir given-initial)
"Pass the region to consult-grep/ripgrep if available.
DIR and GIVEN-INITIAL match the method signature of `consult-wrapper'."
(interactive "P")
(message "wrapper")
(let ((initial
(or given-initial
(when (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))))))
(funcall old-consult-function dir initial)))

(advice-add #'consult-ripgrep :around #'mdrp/consult-with-region)
(advice-add #'consult-grep :around #'mdrp/consult-with-region)

(defun mdrp/consult-ripgrep-always-prompt-dir ()
(interactive)
Expand All @@ -2257,6 +2269,24 @@ with a prefix ARG."
(define-key map "\C-s" #'previous-history-element)
map))

(defun consult-ripgrep-up-directory ()
(interactive)
(let ((parent-dir (file-name-directory (directory-file-name default-directory))))
(when parent-dir
(run-at-time 0 nil
#'consult-ripgrep
parent-dir
(ignore-errors
(buffer-substring-no-properties
(1+ (minibuffer-prompt-end)) (point-max))))))
(minibuffer-quit-recursive-edit))

(consult-customize
consult-ripgrep
:keymap (let ((map (make-sparse-keymap)))
(define-key map (kbd "M-l") #'consult-ripgrep-up-directory)
map))

(consult-customize consult-line :keymap mdrp/consult-line-map)
;; Optionally configure preview. The default value
;; is 'any, such that any key triggers the preview.
Expand All @@ -2277,27 +2307,27 @@ with a prefix ARG."
consult-xref consult--source-bookmark
:preview-key '(:debounce 0.5 "M-."))

;; Optionally configure the narrowing key.
;; Both < and C-+ work reasonably well.
(setq consult-narrow-key "<") ;; (kbd "C-+")
;; Optionally configure the narrowing key.
;; Both < and C-+ work reasonably well.
(setq consult-narrow-key "<") ;; (kbd "C-+")

;; Optionally make narrowing help available in the minibuffer.
;; You may want to use `embark-prefix-help-command' or which-key instead.
;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)
;; Optionally make narrowing help available in the minibuffer.
;; You may want to use `embark-prefix-help-command' or which-key instead.
;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)

;; By default `consult-project-function' uses `project-root' from project.el.
;; Optionally configure a different project root function.
;; There are multiple reasonable alternatives to chose from.
;; By default `consult-project-function' uses `project-root' from project.el.
;; Optionally configure a different project root function.
;; There are multiple reasonable alternatives to chose from.
;;;; 1. project.el (the default)
;; (setq consult-project-function #'consult--default-project--function)
;; (setq consult-project-function #'consult--default-project--function)
;;;; 2. projectile.el (projectile-project-root)
(autoload 'projectile-project-root "projectile")
(setq consult-project-function (lambda (_) (projectile-project-root)))
(autoload 'projectile-project-root "projectile")
(setq consult-project-function (lambda (_) (projectile-project-root)))
;;;; 3. vc.el (vc-root-dir)
;; (setq consult-project-function (lambda (_) (vc-root-dir)))
;; (setq consult-project-function (lambda (_) (vc-root-dir)))
;;;; 4. locate-dominating-file
;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git")))
(message "`consult' loaded"))
;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git")))
(message "`consult' loaded"))

(use-package embark
:defer t
Expand Down Expand Up @@ -3109,6 +3139,25 @@ with a prefix ARG."
(setq ts-fold-indicators-priority 100)
(message "`ts-fold-indicators' loaded"))

(use-package combobulate
:after treesit
:preface
;; You can customize Combobulate's key prefix here.
;; Note that you may have to restart Emacs for this to take effect!
(setq combobulate-key-prefix "C-c c")
:hook
((python-ts-mode . combobulate-mode)
(js-ts-mode . combobulate-mode)
(html-ts-mode . combobulate-mode)
(css-ts-mode . combobulate-mode)
(yaml-ts-mode . combobulate-mode)
(typescript-ts-mode . combobulate-mode)
(json-ts-mode . combobulate-mode)
(tsx-ts-mode . combobulate-mode))
;; Amend this to the directory where you keep Combobulate's source
;; code.
:load-path "lisp/combobulate")

(defgroup pokemacs-languages nil
"Pokemacs languages options."
:group 'pokemacs
Expand Down Expand Up @@ -3747,6 +3796,7 @@ with a prefix ARG."

(when use-python
(use-package python
:ensure nil
:defer t
:hook (python-mode . semantic-mode)
:config
Expand Down
96 changes: 75 additions & 21 deletions init.org
Original file line number Diff line number Diff line change
Expand Up @@ -1411,9 +1411,9 @@ Useful packages that allows to see the possible keys after starting a combinatio
"M-u" 'upcase-dwim
"C-f" 'fill-region
"C-q" 'selected-off
"M-s r" 'reverse-region
"M-s s" 'sort-lines
"M-s w" 'mdrp/sort-words
"C-c s r" 'reverse-region
"C-c s s" 'sort-lines
"C-c s w" 'mdrp/sort-words
"C-<return>" 'hide-region-hide
"C-p" '(hide-region-pin :which-key "Pins the selected region on top of the current window"))
:config (message "`selected' loaded"))
Expand Down Expand Up @@ -3445,7 +3445,7 @@ Vertico works with the default completion system instead of reimplementing a who
"C-M-p" #'vertico-previous-group
"?" #'minibuffer-completion-help
"M-RET" #'embark-dwim ;; pick some comfortable binding
"C-<up>" #'other-window
;; "C-<up>" #'other-window
)
(:keymaps 'minibuffer-local-map
"M-h" #'backward-kill-word)
Expand Down Expand Up @@ -3626,8 +3626,20 @@ TODO: Test all the possible minibuffers and customize them as I'd like them to b
;; after lazily loading the package.
:config

;; (defun consult-line-repeat ()
;; (interactive)
(defun mdrp/consult-with-region (old-consult-function &optional dir given-initial)
"Pass the region to consult-grep/ripgrep if available.

DIR and GIVEN-INITIAL match the method signature of `consult-wrapper'."
(interactive "P")
(message "wrapper")
(let ((initial
(or given-initial
(when (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))))))
(funcall old-consult-function dir initial)))

(advice-add #'consult-ripgrep :around #'mdrp/consult-with-region)
(advice-add #'consult-grep :around #'mdrp/consult-with-region)

(defun mdrp/consult-ripgrep-always-prompt-dir ()
(interactive)
Expand All @@ -3642,6 +3654,24 @@ TODO: Test all the possible minibuffers and customize them as I'd like them to b
(define-key map "\C-s" #'previous-history-element)
map))

(defun consult-ripgrep-up-directory ()
(interactive)
(let ((parent-dir (file-name-directory (directory-file-name default-directory))))
(when parent-dir
(run-at-time 0 nil
#'consult-ripgrep
parent-dir
(ignore-errors
(buffer-substring-no-properties
(1+ (minibuffer-prompt-end)) (point-max))))))
(minibuffer-quit-recursive-edit))

(consult-customize
consult-ripgrep
:keymap (let ((map (make-sparse-keymap)))
(define-key map (kbd "M-l") #'consult-ripgrep-up-directory)
map))

(consult-customize consult-line :keymap mdrp/consult-line-map)
;; Optionally configure preview. The default value
;; is 'any, such that any key triggers the preview.
Expand All @@ -3662,27 +3692,27 @@ TODO: Test all the possible minibuffers and customize them as I'd like them to b
consult-xref consult--source-bookmark
:preview-key '(:debounce 0.5 "M-."))

;; Optionally configure the narrowing key.
;; Both < and C-+ work reasonably well.
(setq consult-narrow-key "<") ;; (kbd "C-+")
;; Optionally configure the narrowing key.
;; Both < and C-+ work reasonably well.
(setq consult-narrow-key "<") ;; (kbd "C-+")

;; Optionally make narrowing help available in the minibuffer.
;; You may want to use `embark-prefix-help-command' or which-key instead.
;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)
;; Optionally make narrowing help available in the minibuffer.
;; You may want to use `embark-prefix-help-command' or which-key instead.
;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)

;; By default `consult-project-function' uses `project-root' from project.el.
;; Optionally configure a different project root function.
;; There are multiple reasonable alternatives to chose from.
;; By default `consult-project-function' uses `project-root' from project.el.
;; Optionally configure a different project root function.
;; There are multiple reasonable alternatives to chose from.
;;;; 1. project.el (the default)
;; (setq consult-project-function #'consult--default-project--function)
;; (setq consult-project-function #'consult--default-project--function)
;;;; 2. projectile.el (projectile-project-root)
(autoload 'projectile-project-root "projectile")
(setq consult-project-function (lambda (_) (projectile-project-root)))
(autoload 'projectile-project-root "projectile")
(setq consult-project-function (lambda (_) (projectile-project-root)))
;;;; 3. vc.el (vc-root-dir)
;; (setq consult-project-function (lambda (_) (vc-root-dir)))
;; (setq consult-project-function (lambda (_) (vc-root-dir)))
;;;; 4. locate-dominating-file
;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git")))
(message "`consult' loaded"))
;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git")))
(message "`consult' loaded"))
#+end_src

** [[https://github.com/oantolin/embark][Embark]]
Expand Down Expand Up @@ -4794,6 +4824,29 @@ Code folding based on tree-sitter tree.

#+end_src

** [[https://github.com/mattiasdrp/combobulate][Combobulate]]

#+begin_src emacs-lisp
(use-package combobulate
:after treesit
:preface
;; You can customize Combobulate's key prefix here.
;; Note that you may have to restart Emacs for this to take effect!
(setq combobulate-key-prefix "C-c c")
:hook
((python-ts-mode . combobulate-mode)
(js-ts-mode . combobulate-mode)
(html-ts-mode . combobulate-mode)
(css-ts-mode . combobulate-mode)
(yaml-ts-mode . combobulate-mode)
(typescript-ts-mode . combobulate-mode)
(json-ts-mode . combobulate-mode)
(tsx-ts-mode . combobulate-mode))
;; Amend this to the directory where you keep Combobulate's source
;; code.
:load-path "lisp/combobulate")
#+end_src

* Programming languages
:PROPERTIES:
:CUSTOM_ID: programming-languages
Expand Down Expand Up @@ -5687,6 +5740,7 @@ In order to use this package you need to run ~M-x pdf-tools-install~ the first t
#+begin_src emacs-lisp
(when use-python
(use-package python
:ensure nil
:defer t
:hook (python-mode . semantic-mode)
:config
Expand Down

0 comments on commit 2dbef2d

Please sign in to comment.