diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 7fe9652ca..415385638 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -54,7 +54,17 @@ ;; misc :n "C-S-f" #'toggle-frame-fullscreen - ;; ported vim keys + ;; ported from vim + :m "]m" #'+evil/next-beginning-of-method + :m "[m" #'+evil/previous-beginning-of-method + :m "]M" #'+evil/next-end-of-method + :m "[M" #'+evil/previous-end-of-method + :m "]#" #'+evil/next-preproc-directive + :m "[#" #'+evil/previous-preproc-directive + :m "]*" #'+evil/next-comment + :m "[*" #'+evil/previous-comment + :m "]\\" #'+evil/next-comment + :m "[\\" #'+evil/previous-comment :nv "z=" #'flyspell-correct-word-generic :v "@" #'+evil:apply-macro @@ -94,6 +104,7 @@ :v "g=" #'evil-numbers/inc-at-pt-incremental :v "g-" #'evil-numbers/dec-at-pt-incremental :v "g+" #'evil-numbers/inc-at-pt + ;; custom evil keybinds :n "zx" #'kill-current-buffer :n "ZX" #'bury-buffer diff --git a/modules/editor/evil/autoload/evil.el b/modules/editor/evil/autoload/evil.el index 057b680cc..d95ebfcf2 100644 --- a/modules/editor/evil/autoload/evil.el +++ b/modules/editor/evil/autoload/evil.el @@ -229,6 +229,75 @@ the first match on each line)." (interactive "") (doom/clone-and-narrow-buffer beg end bang)) +;;;###autoload +(defun +evil/next-beginning-of-method (count) + "Jump to the beginning of the COUNT-th method/function after point." + (interactive "p") + (beginning-of-defun (- count))) + +;;;###autoload +(defun +evil/previous-beginning-of-method (count) + "Jump to the beginning of the COUNT-th method/function before point." + (interactive "p") + (beginning-of-defun count)) + +;;;###autoload +(defalias #'+evil/next-end-of-method #'end-of-defun + "Jump to the end of the COUNT-th method/function after point.") + +;;;###autoload +(defun +evil/previous-end-of-method (count) + "Jump to the end of the COUNT-th method/function before point." + (interactive "p") + (end-of-defun (- count))) + +;;;###autoload +(defun +evil/next-preproc-directive (count) + "Jump to the COUNT-th preprocessor directive after point. + +By default, this only recognizes C preproc directives. To change this see +`+evil-preprocessor-regexp'." + (interactive "p") + ;; TODO More generalized search, to support directives in other languages? + (if (re-search-forward +evil-preprocessor-regexp nil t count) + (goto-char (match-beginning 0)) + (user-error "No preprocessor directives %s point" + (if (> count 0) "after" "before")))) + +;;;###autoload +(defun +evil/previous-preproc-directive (count) + "Jump to the COUNT-th preprocessor directive before point. + +See `+evil/next-preproc-directive' for details." + (interactive "p") + (+evil/next-preproc-statement (- count))) + +;;;###autoload +(defun +evil/next-comment (count) + "Jump to the beginning of the COUNT-th commented region after point." + (interactive "p") + (let ((orig-pt (point))) + (require 'newcomment) + (dotimes (_ (abs count)) + (cond ((> count 0) + (while (and (not (eobp)) (sp-point-in-comment)) + (next-line)) + (unless (comment-search-forward (point-max) 'noerror) + (goto-char orig-pt) + (user-error "No comment after point"))) + (t + (while (and (not (bobp)) (sp-point-in-comment)) + (previous-line)) + (unless (comment-search-backward nil 'noerror) + (goto-char orig-pt) + (user-error "No comment before point"))))))) + +;;;###autoload +(defun +evil/previous-comment (count) + "Jump to the beginning of the COUNT-th commented region before point." + (interactive "p") + (+evil/next-comment (- count))) + ;; ;;; wgrep diff --git a/modules/editor/evil/config.el b/modules/editor/evil/config.el index ecdb5e51c..4bb018eb3 100644 --- a/modules/editor/evil/config.el +++ b/modules/editor/evil/config.el @@ -7,6 +7,11 @@ "If non-nil, the o/O keys will continue comment lines if the point is on a line with a linewise comment.") +(defvar +evil-preprocessor-regexp "^\\s-*#[a-zA-Z0-9_]" + "The regexp used by `+evil/next-preproc-directive' and +`+evil/previous-preproc-directive' on ]# and [#, to jump between preprocessor +directives. By default, this only recognizes C directives.") + ;; Set these defaults before `evil'; use `defvar' so they can be changed prior ;; to loading. (defvar evil-want-C-i-jump (or (daemonp) (display-graphic-p)))