emacs: mark-ring and registers

This commit is contained in:
Pavel Korytov 2024-02-16 12:12:55 +03:00
parent 4549a1c804
commit c216cbec9d
2 changed files with 188 additions and 64 deletions

View file

@ -147,7 +147,8 @@
(erase-buffer)) (erase-buffer))
(my/dump-bindings-recursive prefix 0 buffer) (my/dump-bindings-recursive prefix 0 buffer)
(with-current-buffer buffer (with-current-buffer buffer
(goto-char (point-min))) (goto-char (point-min))
(setq-local buffer-read-only t))
(switch-to-buffer-other-window buffer))) (switch-to-buffer-other-window buffer)))
(use-package evil (use-package evil
@ -235,22 +236,6 @@
xref eshell helpful compile comint git-timemachine magit prodigy xref eshell helpful compile comint git-timemachine magit prodigy
slime forge deadgrep vc-annonate telega doc-view gnus outline))) slime forge deadgrep vc-annonate telega doc-view gnus outline)))
(use-package avy
:straight t
:config
(setq avy-timeout-seconds 0.5)
(setq avy-ignored-modes
'(image-mode doc-view-mode pdf-view-mode exwm-mode))
(general-define-key
:states '(normal motion)
"-" nil
"--" #'avy-goto-char-2
"-=" #'avy-goto-symbol-1))
(use-package ace-link
:straight t
:commands (ace-link-info ace-link-help ace-link-woman ace-link-eww))
(defun minibuffer-keyboard-quit () (defun minibuffer-keyboard-quit ()
"Abort recursive edit. "Abort recursive edit.
In Delete Selection mode, if the mark is active, just deactivate it; In Delete Selection mode, if the mark is active, just deactivate it;
@ -572,7 +557,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
) )
(use-package accent (use-package accent
:straight (:host github :repo "SqrtMinusOne/accent") :straight (:host github :repo "eliascotto/accent")
:init :init
(general-define-key (general-define-key
:states '(normal) :states '(normal)
@ -591,11 +576,6 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
(setq accent-custom '((a (ā)) (setq accent-custom '((a (ā))
(A (Ā))))) (A (Ā)))))
(use-package binky
:straight t
:init
(my-leader-def "j" #'binky-binky))
(use-package projectile (use-package projectile
:straight t :straight t
:config :config
@ -721,6 +701,72 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
:config :config
(advice-add #'deadgrep--buffer :around #'my/deadgrep-fix-buffer-advice)) (advice-add #'deadgrep--buffer :around #'my/deadgrep-fix-buffer-advice))
(defun my/register-clear (register)
(interactive (list (register-read-with-preview "Clear register: ")))
(setq register-alist (delq (assoc register register-alist) register-alist)))
(setq register-preview-delay which-key-idle-delay)
(my-leader-def
:infix "g"
"" '(:wk "registers & marks")
"y" #'copy-to-register
"p" #'insert-register
"o" #'point-to-register
"c" #'my/register-clear
"r" #'jump-to-register
"R" #'counsel-register
"w" #'window-configuration-to-register)
(defun my/push-mark-no-activate ()
"Pushes `point' to `mark-ring' and does not activate the region
Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
(interactive)
(push-mark (point) t nil)
(message "Pushed mark to ring"))
(defun my/mark-ring-clear ()
(interactive)
(setq mark-ring nil))
(defun my/counsel-global-mark-ring ()
"Browse `mark-ring' interactively.
Obeys `widen-automatically', which see."
(interactive)
(let* ((counsel--mark-ring-calling-point (point))
(marks (copy-sequence global-mark-ring))
(marks (delete-dups marks))
(candidates (counsel-mark--get-candidates marks)))
(if candidates
(counsel-mark--ivy-read "Mark: " candidates 'my/counsel-global-mark-ring)
(message "Mark ring is empty"))))
(my-leader-def
:infix "g"
"g" #'counsel-mark-ring
"G" #'my/counsel-global-mark-ring
"C" #'my/mark-ring-clear)
(general-define-key
:keymaps 'global
"C-SPC" #'my/push-mark-no-activate)
(use-package avy
:straight t
:config
(setq avy-timeout-seconds 0.5)
(setq avy-ignored-modes
'(image-mode doc-view-mode pdf-view-mode exwm-mode))
(general-define-key
:states '(normal motion)
"-" nil
"--" #'avy-goto-char-2
"-=" #'avy-goto-symbol-1))
(use-package ace-link
:straight t
:commands (ace-link-info ace-link-help ace-link-woman ace-link-eww))
(use-package ivy (use-package ivy
:straight t :straight t
:config :config
@ -3632,8 +3678,10 @@ With ARG, repeats or can move backward if negative."
(setq org-ql-regexp-part-ts-time (setq org-ql-regexp-part-ts-time
(rx " " (repeat 1 2 digit) ":" (repeat 2 digit) (rx " " (repeat 1 2 digit) ":" (repeat 2 digit)
(optional "-" (repeat 1 2 digit) ":" (repeat 2 digit)))) (optional "-" (repeat 1 2 digit) ":" (repeat 2 digit))))
(my-leader-def "ov" #'org-ql-view) (my-leader-def
(my-leader-def "oq" #'org-ql-search)) :infix "o"
"v" #'org-ql-view
"q" #'org-ql-search))
(with-eval-after-load 'org-ql (with-eval-after-load 'org-ql
(org-ql-defpred property (property &optional value &key inherit multi) (org-ql-defpred property (property &optional value &key inherit multi)

154
Emacs.org
View file

@ -348,7 +348,8 @@ A function to dump keybindings starting with a prefix to a buffer in a tree-like
(erase-buffer)) (erase-buffer))
(my/dump-bindings-recursive prefix 0 buffer) (my/dump-bindings-recursive prefix 0 buffer)
(with-current-buffer buffer (with-current-buffer buffer
(goto-char (point-min))) (goto-char (point-min))
(setq-local buffer-read-only t))
(switch-to-buffer-other-window buffer))) (switch-to-buffer-other-window buffer)))
#+end_src #+end_src
*** Evil *** Evil
@ -477,32 +478,6 @@ Do ex search in other buffer. Like =*=, but switch to other buffer and search th
xref eshell helpful compile comint git-timemachine magit prodigy xref eshell helpful compile comint git-timemachine magit prodigy
slime forge deadgrep vc-annonate telega doc-view gnus outline))) slime forge deadgrep vc-annonate telega doc-view gnus outline)))
#+end_src #+end_src
*** Avy
[[https://github.com/abo-abo/avy][Avy]] is a package that helps navigate Emacs in a tree-like manner.
References:
- [[https://karthinks.com/software/avy-can-do-anything/][Avy can do anything]]
#+begin_src emacs-lisp
(use-package avy
:straight t
:config
(setq avy-timeout-seconds 0.5)
(setq avy-ignored-modes
'(image-mode doc-view-mode pdf-view-mode exwm-mode))
(general-define-key
:states '(normal motion)
"-" nil
"--" #'avy-goto-char-2
"-=" #'avy-goto-symbol-1))
#+End_src
[[https://github.com/abo-abo/ace-link][ace-link]] is a package to jump to links with avy.
#+begin_src emacs-lisp
(use-package ace-link
:straight t
:commands (ace-link-info ace-link-help ace-link-woman ace-link-eww))
#+end_src
*** My keybindings *** My keybindings
Various keybinding settings that I can't put anywhere else. Various keybinding settings that I can't put anywhere else.
@ -1030,7 +1005,7 @@ Input accented characters.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package accent (use-package accent
:straight (:host github :repo "SqrtMinusOne/accent") :straight (:host github :repo "eliascotto/accent")
:init :init
(general-define-key (general-define-key
:states '(normal) :states '(normal)
@ -1049,15 +1024,6 @@ Input accented characters.
(setq accent-custom '((a (ā)) (setq accent-custom '((a (ā))
(A (Ā))))) (A (Ā)))))
#+end_src #+end_src
**** binky
Experimenting with this package.
#+begin_src emacs-lisp
(use-package binky
:straight t
:init
(my-leader-def "j" #'binky-binky))
#+end_src
** Working with projects ** Working with projects
Packages related to managing projects. Packages related to managing projects.
@ -1238,6 +1204,114 @@ Somehow I couldn't hook =toogle-truncate-lines= into the existing package hooks,
:config :config
(advice-add #'deadgrep--buffer :around #'my/deadgrep-fix-buffer-advice)) (advice-add #'deadgrep--buffer :around #'my/deadgrep-fix-buffer-advice))
#+end_src #+end_src
** Navigation
Things to navigate in Emacs.
*** Registers
References:
- [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Registers.html][Registers (GNU Emacs Manual)]]
Somehow there's no built-in function to clear a register.
#+begin_src emacs-lisp
(defun my/register-clear (register)
(interactive (list (register-read-with-preview "Clear register: ")))
(setq register-alist (delq (assoc register register-alist) register-alist)))
#+end_src
#+begin_src emacs-lisp
(setq register-preview-delay which-key-idle-delay)
(my-leader-def
:infix "g"
"" '(:wk "registers & marks")
"y" #'copy-to-register
"p" #'insert-register
"o" #'point-to-register
"c" #'my/register-clear
"r" #'jump-to-register
"R" #'counsel-register
"w" #'window-configuration-to-register)
#+End_src
*** Marks
References:
- [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Mark.html][The Mark and the Region (GNU Emacs Manual)]]
- [[https://www.masteringemacs.org/article/fixing-mark-commands-transient-mark-mode][Fixing the mark commands in transient mark mode - Mastering Emacs]]
=transient-mark-mode= makes using marks for navigation a bit more cumbersome, but I'm not sure of potential side effects of disabling it... As of now, I want only to push a mark without activating it, so here's a function for that (taken from Mickey Peterson's article):
#+begin_src emacs-lisp
(defun my/push-mark-no-activate ()
"Pushes `point' to `mark-ring' and does not activate the region
Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
(interactive)
(push-mark (point) t nil)
(message "Pushed mark to ring"))
#+end_src
Also a function to clear the current mark ring.
#+begin_src emacs-lisp
(defun my/mark-ring-clear ()
(interactive)
(setq mark-ring nil))
#+end_src
A variant of =counsel-mark-ring= to work with =global-mark-ring=:
#+begin_src emacs-lisp
(defun my/counsel-global-mark-ring ()
"Browse `mark-ring' interactively.
Obeys `widen-automatically', which see."
(interactive)
(let* ((counsel--mark-ring-calling-point (point))
(marks (copy-sequence global-mark-ring))
(marks (delete-dups marks))
(candidates (counsel-mark--get-candidates marks)))
(if candidates
(counsel-mark--ivy-read "Mark: " candidates 'my/counsel-global-mark-ring)
(message "Mark ring is empty"))))
#+end_src
Keybindings:
#+begin_src emacs-lisp
(my-leader-def
:infix "g"
"g" #'counsel-mark-ring
"G" #'my/counsel-global-mark-ring
"C" #'my/mark-ring-clear)
(general-define-key
:keymaps 'global
"C-SPC" #'my/push-mark-no-activate)
#+end_src
*** Avy
[[https://github.com/abo-abo/avy][Avy]] is a package that helps navigate Emacs in a tree-like manner.
References:
- [[https://karthinks.com/software/avy-can-do-anything/][Avy can do anything]]
#+begin_src emacs-lisp
(use-package avy
:straight t
:config
(setq avy-timeout-seconds 0.5)
(setq avy-ignored-modes
'(image-mode doc-view-mode pdf-view-mode exwm-mode))
(general-define-key
:states '(normal motion)
"-" nil
"--" #'avy-goto-char-2
"-=" #'avy-goto-symbol-1))
#+End_src
[[https://github.com/abo-abo/ace-link][ace-link]] is a package to jump to links with avy.
#+begin_src emacs-lisp
(use-package ace-link
:straight t
:commands (ace-link-info ace-link-help ace-link-woman ace-link-eww))
#+end_src
** Completion ** Completion
*** Ivy, counsel, swiper *** Ivy, counsel, swiper
@ -5053,8 +5127,10 @@ It doesn't look great with org-bars mode, so...
(setq org-ql-regexp-part-ts-time (setq org-ql-regexp-part-ts-time
(rx " " (repeat 1 2 digit) ":" (repeat 2 digit) (rx " " (repeat 1 2 digit) ":" (repeat 2 digit)
(optional "-" (repeat 1 2 digit) ":" (repeat 2 digit)))) (optional "-" (repeat 1 2 digit) ":" (repeat 2 digit))))
(my-leader-def "ov" #'org-ql-view) (my-leader-def
(my-leader-def "oq" #'org-ql-search)) :infix "o"
"v" #'org-ql-view
"q" #'org-ql-search))
#+end_src #+end_src
***** Add :multi argument to the property predicate ***** Add :multi argument to the property predicate