diff options
Diffstat (limited to '.config/emacs')
-rw-r--r-- | .config/emacs/editing.el | 27 | ||||
-rw-r--r-- | .config/emacs/modules/mm-keybindings.el | 3 |
2 files changed, 30 insertions, 0 deletions
diff --git a/.config/emacs/editing.el b/.config/emacs/editing.el index 064793d..95160f8 100644 --- a/.config/emacs/editing.el +++ b/.config/emacs/editing.el @@ -221,4 +221,31 @@ If `consult' is available than this command instead calls (t (call-interactively #'yank-from-kill-ring))))) +(defun mm-search-forward-char (char &optional n) + "Search forwards to the Nth occurance of CHAR. +If called interactively CHAR is read from the minibuffer and N is given +by the prefix argument. + +If N is negative then this function searches backwards. + +When searching forwards point is left before CHAR while when searching +backwards point is left after CHAR." + (interactive + (list (read-char) + (prefix-numeric-value current-prefix-arg))) + (when (and (> n 0) (= char (char-after (point)))) + (forward-char)) + (search-forward (char-to-string char) nil nil n) + (when (> n 0) + (backward-char))) + +(defun mm-search-backward-char (char &optional n) + "Search backwards to the Nth occurance of CHAR. +This function is identical to `mm-search-forward-char' with N negated." + (declare (interactive-only t)) + (interactive + (list (read-char) + (prefix-numeric-value current-prefix-arg))) + (mm-search-forward-char char (- n))) + (provide 'editing) diff --git a/.config/emacs/modules/mm-keybindings.el b/.config/emacs/modules/mm-keybindings.el index a025a82..746d95c 100644 --- a/.config/emacs/modules/mm-keybindings.el +++ b/.config/emacs/modules/mm-keybindings.el @@ -115,6 +115,9 @@ the first command is remapped to the second command." "C-^" #'e/split-line "C-/" #'e/mark-line-dwim + "C-]" #'mm-search-forward-char + "M-]" #'mm-search-backward-char + "C-c d" #'duplicate-dwim "C-c t a" #'e/align-regexp "C-c t f" #'fill-paragraph |