Incremental highlighting for :g[lobal] and :al[ign]

This commit is contained in:
Henrik Lissner 2015-12-11 02:21:49 -05:00
parent e36f61047c
commit bc83f46349
4 changed files with 82 additions and 2 deletions

View file

@ -186,7 +186,37 @@
(setq file-name
(replace-regexp-in-string "\\\\\\([#%]\\)"
"\\1" file-name t)))
file-name)))
file-name))
;; Highlight buffer match interactive codes
(defvar narf-buffer-match-global evil-ex-substitute-global
"Whether or not buffer-match ex completion should add the ?g flag to searches.")
(evil-ex-define-argument-type buffer-match
:runner
(lambda (flag &optional arg)
(let ((hl-name 'evil-ex-buffer-match))
(with-selected-window (minibuffer-selected-window)
(narf/-ex-match-init hl-name)
(narf/-ex-buffer-match arg hl-name (list (if narf-buffer-match-global ?g)))))))
(evil-define-interactive-code "<//>"
"Ex buffer match argument."
:ex-arg buffer-match
(list (when (evil-ex-p) evil-ex-argument)))
;; Make :g[lobal] highlight matches
(evil-ex-define-argument-type global-match
:runner
(lambda (flag &optional arg)
(let ((hl-name 'evil-ex-global-match))
(with-selected-window (minibuffer-selected-window)
(narf/-ex-match-init hl-name)
(let ((result (car-safe (evil-ex-parse-global arg))))
(narf/-ex-buffer-match result hl-name nil (point-min) (point-max)))))))
(evil-define-interactive-code "<g/>"
"Ex global argument."
:ex-arg global-match
(when (evil-ex-p)
(evil-ex-parse-global evil-ex-argument))))
;; evil plugins
(use-package evil-anzu

View file

@ -39,5 +39,16 @@
(beginning-of-line))
(setq *linum-mdown-line* nil))))
;;;###autoload (autoload 'narf:align "defuns-editor" nil t)
(evil-define-operator narf:align (&optional beg end bang pattern)
(interactive "<r><!><//>")
(align-regexp
beg end
(concat "\\(\\s-*\\)"
(if bang
(regexp-quote pattern)
(rxt-pcre-to-elisp pattern)))
1 1))
(provide 'defuns-editor)
;;; defuns-editor.el ends here

View file

@ -94,5 +94,43 @@
(define-key evil-inner-text-objects-map ,key (quote ,inner-name))
(define-key evil-outer-text-objects-map ,key (quote ,outer-name)))))
;;; Custom argument handlers
;;;###autoload
(defun narf/-ex-match-init (name &optional face update-hook)
(with-current-buffer evil-ex-current-buffer
(cond
((eq flag 'start)
(evil-ex-make-hl name
:face (or face 'evil-ex-substitute-matches)
:update-hook (or update-hook #'evil-ex-pattern-update-ex-info))
(setq flag 'update))
((eq flag 'stop)
(evil-ex-delete-hl name)))))
;;;###autoload
(defun narf/-ex-buffer-match (arg &optional hl-name flags beg end)
(when (and (eq flag 'update)
evil-ex-substitute-highlight-all
(not (zerop (length arg))))
(condition-case lossage
(let ((pattern (evil-ex-make-substitute-pattern
(if evil-ex-bang (regexp-quote arg) arg)
(or flags (list))))
(range (or (evil-copy-range evil-ex-range)
(evil-range (or beg (line-beginning-position))
(or end (line-end-position))
'line
:expanded t))))
(evil-expand-range range)
(evil-ex-hl-set-region hl-name
(evil-range-beginning range)
(evil-range-end range))
(evil-ex-hl-change hl-name pattern))
(end-of-file
(evil-ex-pattern-update-ex-info nil "incomplete replacement"))
(user-error
(evil-ex-pattern-update-ex-info nil (format "?%s" lossage))))))
(provide 'defuns-evil)
;;; defuns-evil.el ends here

View file

@ -9,7 +9,8 @@
(exmap "ag[cw]d" 'narf:helm-ag-search-cwd)
(exmap "agr" 'narf:helm-ag-regex-search)
(exmap "agr[cw]d" 'narf:helm-ag-regex-search-cwd)
(exmap "al[ign]" 'narf:whitespace-align)
(exmap "al[ign]" 'narf:align)
(exmap "wal[ign]" 'narf:whitespace-align)
(exmap "bcomp[ile]" 'narf:compile-el)
(exmap "big" 'narf:toggle-big-mode)
(exmap "cap[ture]" 'helm-org-capture-templates)