Port more next/previous motions from vim
They are: ]m, [m Jump to next/previous beginning of method/function. ]M, [M Jump to next/previous end of method/function ]#, [# Jump to next/previous preprocessor directive (only supports C-style directives for now) ]*, [* (or ]\, [\) Jump to next/previous comment
This commit is contained in:
parent
61502d7e31
commit
855ff34e2c
3 changed files with 86 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -229,6 +229,75 @@ the first match on each line)."
|
|||
(interactive "<r><!>")
|
||||
(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
|
||||
|
|
|
@ -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)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue