Add macros-evil.el and defmacro define-temp-ex-cmd!

This commit is contained in:
Henrik Lissner 2016-03-31 14:37:52 -04:00
parent 5b2874f410
commit 12a33391fd
4 changed files with 37 additions and 26 deletions

View file

@ -22,19 +22,14 @@
:n "c" 'realgud:cmd-continue) :n "c" 'realgud:cmd-continue)
;; Temporary Ex commands for the debugger ;; Temporary Ex commands for the debugger
;; TODO Turn temporary ex commands into macro (define-temp-ex-cmd! narf:def-debug-on narf:def-debug-off
(defun narf*debug-init (&rest _) ("n[ext]" . realgud:cmd-next)
(exmap "n[ext]" 'realgud:cmd-next) ("s[tep]" . realgud:cmd-step)
(exmap "s[tep]" 'realgud:cmd-step) ("b[reak]" . narf:debug-toggle-breakpoint)
(exmap "b[reak]" 'narf:debug-toggle-breakpoint) ("c[ontinue]" . realgud:cmd-continue))
(exmap "c[ontinue]" 'realgud:cmd-continue))
(defun narf*debug-quit (&rest _) (advice-add 'realgud-cmdbuf-init :after 'narf:def-debug-on)
(narf/evil-ex-undefine-cmd "n[ext]") (advice-add 'realgud:cmd-quit :after 'narf:def-debug-off))
(narf/evil-ex-undefine-cmd "s[tep]")
(narf/evil-ex-undefine-cmd "b[reak]")
(narf/evil-ex-undefine-cmd "c[ontinue]"))
(advice-add 'realgud-cmdbuf-init :after 'narf*debug-init)
(advice-add 'realgud:cmd-quit :after 'narf*debug-quit))
(provide 'core-debug) (provide 'core-debug)
;;; core-debug.el ends here ;;; core-debug.el ends here

View file

@ -75,18 +75,6 @@
(single-key-description (single-key-description
(or macro (read-char "@-")))))) (or macro (read-char "@-"))))))
;;;###autoload
(defmacro define-text-object! (key start-regex end-regex)
(let ((inner-name (make-symbol "narf--inner-name"))
(outer-name (make-symbol "narf--outer-name")))
`(progn
(evil-define-text-object ,inner-name (count &optional beg end type)
(evil-select-paren ,start-regex ,end-regex beg end type count nil))
(evil-define-text-object ,outer-name (count &optional beg end type)
(evil-select-paren ,start-regex ,end-regex beg end type count t))
(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 ;;; Custom argument handlers
;;;###autoload ;;;###autoload
(defun narf/-ex-match-init (name &optional face update-hook) (defun narf/-ex-match-init (name &optional face update-hook)

View file

@ -0,0 +1,28 @@
;;; macros-evil.el
;;;###autoload
(defmacro define-text-object! (key start-regex end-regex)
(let ((inner-name (make-symbol "narf--inner-name"))
(outer-name (make-symbol "narf--outer-name")))
`(progn
(evil-define-text-object ,inner-name (count &optional beg end type)
(evil-select-paren ,start-regex ,end-regex beg end type count nil))
(evil-define-text-object ,outer-name (count &optional beg end type)
(evil-select-paren ,start-regex ,end-regex beg end type count t))
(define-key evil-inner-text-objects-map ,key (quote ,inner-name))
(define-key evil-outer-text-objects-map ,key (quote ,outer-name)))))
;;;###autoload
(defmacro define-temp-ex-cmd! (cmd-on cmd-off &rest commands)
"Creates on-off defuns for a set of ex commands, named CMD-ON and CMD-OFF."
(declare (indent 2))
`(progn
(defun ,cmd-on (&rest _)
(mapc (lambda (cmd) (evil-ex-define-cmd (car cmd) (cdr cmd)))
',commands))
(defun ,cmd-off (&rest _)
(mapc (lambda (cmd) (narf/evil-ex-undefine-cmd (car cmd)))
',commands))))
(provide 'macros-evil)
;;; macros-evil.el ends here

View file

@ -61,7 +61,7 @@
"define-env-command" "define-text-object" "define-env-command" "define-text-object"
"add-yas-minor-mode" "define-docset" "add-yas-minor-mode" "define-docset"
"define-org-link!" "define-company-backend" "define-org-link!" "define-company-backend"
"define-org-section")) "define-org-section" "define-temp-ex-cmd"))
"!\\)") "!\\)")
(1 font-lock-keyword-face append)) (1 font-lock-keyword-face append))
;; Ert ;; Ert