2015-06-15 09:05:52 +02:00
|
|
|
;;; defuns-evil.el
|
|
|
|
;; for ../core-evil.el
|
|
|
|
|
|
|
|
;;;###autoload (autoload 'narf:evil-open-folds "defuns-evil" nil t)
|
|
|
|
(evil-define-command narf/evil-open-folds (count)
|
|
|
|
"Instead of `evil-open-folds'. Accepts COUNT for dictating fold level."
|
|
|
|
(interactive "P")
|
|
|
|
(unless (bound-and-true-p hs-minor-mode)
|
|
|
|
(hs-minor-mode 1))
|
|
|
|
(if count (hs-hide-level count) (evil-open-folds)))
|
|
|
|
|
|
|
|
;;;###autoload (autoload 'narf:evil-open-folds "defuns-evil" nil t)
|
|
|
|
(evil-define-command narf/evil-close-folds (count)
|
|
|
|
"Instead of `evil-close-folds'. Accepts COUNT for dictating fold level."
|
|
|
|
(interactive "P")
|
|
|
|
(unless (bound-and-true-p hs-minor-mode)
|
|
|
|
(hs-minor-mode 1))
|
|
|
|
(if count (hs-hide-level count) (evil-close-folds)))
|
|
|
|
|
2015-11-10 18:10:32 -05:00
|
|
|
;;;###autoload (autoload 'narf/multi-next-line "defuns-evil" nil t)
|
|
|
|
(evil-define-motion narf/multi-next-line (count)
|
2015-09-30 13:49:37 -04:00
|
|
|
"Move down 6 lines"
|
2016-03-27 18:14:08 -04:00
|
|
|
:type line
|
|
|
|
(let ((line-move-visual visual-line-mode))
|
|
|
|
(evil-line-move (* 6 (or count 1)))))
|
2015-09-30 13:49:37 -04:00
|
|
|
|
2015-11-10 18:10:32 -05:00
|
|
|
;;;###autoload (autoload 'narf/multi-previous-line "defuns-evil" nil t)
|
|
|
|
(evil-define-motion narf/multi-previous-line (count)
|
2015-09-30 13:49:37 -04:00
|
|
|
"Move up 6 lines"
|
2016-03-27 18:14:08 -04:00
|
|
|
:type line
|
|
|
|
(let ((line-move-visual visual-line-mode))
|
|
|
|
(evil-line-move (- (* 6 (or count 1))))))
|
2015-06-15 09:05:52 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun narf/evil-visual-line-state-p ()
|
|
|
|
"Returns non-nil if in visual-line mode, nil otherwise."
|
|
|
|
(and (evil-visual-state-p)
|
|
|
|
(eq (evil-visual-type) 'line)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun narf*evil-exchange-off ()
|
|
|
|
(when evil-exchange--overlays
|
|
|
|
(evil-exchange-cancel)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun narf/evil-surround-escaped ()
|
|
|
|
"Escaped surround characters."
|
2015-11-10 18:10:32 -05:00
|
|
|
(let* ((char (string (read-char "\\")))
|
|
|
|
(pair (cond ((string-match-p "[]})[{(]" char)
|
|
|
|
(let ((-pair (cdr (assoc (string-to-char char) evil-surround-pairs-alist))))
|
|
|
|
`(,(car -pair) . ,(cdr -pair))))
|
|
|
|
(t
|
|
|
|
`(,char . ,char))))
|
|
|
|
(format (if (sp-point-in-string) "\\\\%s" "\\%s")))
|
|
|
|
(cons (format format (car pair))
|
|
|
|
(format format (cdr pair)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun narf/evil-surround-latex ()
|
|
|
|
"LaTeX commands"
|
|
|
|
(let* ((command (read-string "\\")))
|
|
|
|
(cons (format "\\%s{" command) "}")))
|
2015-06-15 09:05:52 +02:00
|
|
|
|
2015-10-28 17:28:41 -04:00
|
|
|
;;;###autoload (autoload 'narf/evil-macro-on-all-lines "defuns-evil" nil t)
|
2015-11-25 06:00:49 -05:00
|
|
|
(evil-define-operator narf/evil-macro-on-all-lines (beg end &optional macro)
|
|
|
|
"Apply macro to each line."
|
|
|
|
:motion nil
|
|
|
|
:move-point nil
|
|
|
|
(interactive "<r><a>")
|
|
|
|
(unless (and beg end)
|
|
|
|
(setq beg (region-beginning)
|
|
|
|
end (region-end)))
|
|
|
|
(evil-ex-normal beg end
|
|
|
|
(concat "@"
|
|
|
|
(single-key-description
|
|
|
|
(or macro (read-char "@-"))))))
|
2015-10-28 17:28:41 -04:00
|
|
|
|
2015-12-11 02:21:49 -05:00
|
|
|
;;; 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
|
2016-02-18 04:07:59 -05:00
|
|
|
(max (evil-range-beginning range) (window-start))
|
|
|
|
(min (evil-range-end range) (window-end)))
|
2015-12-11 02:21:49 -05:00
|
|
|
(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))))))
|
|
|
|
|
2016-03-31 03:17:15 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun narf/evil-ex-undefine-cmd (cmd)
|
|
|
|
(if (string-match "^[^][]*\\(\\[\\(.*\\)\\]\\)[^][]*$" cmd)
|
|
|
|
(let ((abbrev (replace-match "" nil t cmd 1))
|
|
|
|
(full (replace-match "\\2" nil nil cmd 1)))
|
|
|
|
(setq evil-ex-commands (delq (assoc full evil-ex-commands) evil-ex-commands))
|
|
|
|
(setq evil-ex-commands (delq (assoc abbrev evil-ex-commands) evil-ex-commands)))
|
|
|
|
(setq evil-ex-commands (delq (assoc cmd evil-ex-commands) evil-ex-commands))))
|
|
|
|
|
2016-04-04 12:07:32 -04:00
|
|
|
(defvar narf:map-maps '())
|
|
|
|
|
|
|
|
;;;###autoload (autoload 'narf:map "defuns-evil" nil t)
|
|
|
|
(evil-define-command narf:map (bang input &optional mode)
|
|
|
|
"Map ex commands to keybindings. INPUT should be in the format [KEY] [EX COMMAND]."
|
|
|
|
(interactive "<!><a>")
|
|
|
|
(let* ((parts (s-split-up-to " " input 2 t))
|
|
|
|
(mode (or mode 'normal))
|
|
|
|
(key (kbd (car parts)))
|
|
|
|
(command (s-join " " (cdr parts)))
|
|
|
|
(map (cl-case mode
|
|
|
|
('normal evil-normal-state-local-map)
|
|
|
|
('insert evil-insert-state-local-map)
|
|
|
|
('visual evil-visual-state-local-map)
|
|
|
|
('motion evil-motion-state-local-map)
|
|
|
|
('operator evil-operator-state-local-map)))
|
|
|
|
(fn `(lambda () (interactive) (evil-ex-eval ,command))))
|
|
|
|
(if bang
|
|
|
|
(evil-define-key mode nil key fn)
|
|
|
|
(define-key map key fn))))
|
|
|
|
|
|
|
|
;;;###autoload (autoload 'narf:nmap "defuns-evil" nil t)
|
|
|
|
(evil-define-command narf:nmap (bang input &optional mode)
|
|
|
|
(interactive "<!><a>") (narf:map bang input 'normal))
|
|
|
|
|
|
|
|
;;;###autoload (autoload 'narf:imap "defuns-evil" nil t)
|
|
|
|
(evil-define-command narf:imap (bang input &optional mode)
|
|
|
|
(interactive "<!><a>") (narf:map bang input 'insert))
|
|
|
|
|
|
|
|
;;;###autoload (autoload 'narf:vmap "defuns-evil" nil t)
|
|
|
|
(evil-define-command narf:vmap (bang input &optional mode)
|
|
|
|
(interactive "<!><a>") (narf:map bang input 'visual))
|
|
|
|
|
|
|
|
;;;###autoload (autoload 'narf:mmap "defuns-evil" nil t)
|
|
|
|
(evil-define-command narf:mmap (bang input &optional mode)
|
|
|
|
(interactive "<!><a>") (narf:map bang input 'motion))
|
|
|
|
|
|
|
|
;;;###autoload (autoload 'narf:omap "defuns-evil" nil t)
|
|
|
|
(evil-define-command narf:omap (bang input &optional mode)
|
|
|
|
(interactive "<!><a>") (narf:map bang input 'operator))
|
|
|
|
|
2015-06-15 09:05:52 +02:00
|
|
|
(provide 'defuns-evil)
|
|
|
|
;;; defuns-evil.el ends here
|