2017-07-21 99 views
1

我看到邪惡變化或邪惡刪除等一些功能在邪惡視覺狀態下的視覺區域的開始和結束。 我已經看過這些函數的「evil-commands.el」中的源代碼,但它們的'beg'和'end'參數似乎無處不在。有些(如下面的)甚至沒有交互性。在邪惡視覺模式下自動輸入結束參數

爲什麼這是我在自己的方法中可以做同樣的事情?

以下只是我看着的方法之一的一個例子:

;; Defined in ~/.emacs.d/elpa/evil-20170712.2350/evil-commands.el 
(evil-define-operator evil-invert-char (beg end type) 
    "Invert case of character." 
    :motion evil-forward-char 
    (if (eq type 'block) 
     (evil-apply-on-block #'evil-invert-case beg end nil) 
    (evil-invert-case beg end) 
    (when evil-this-motion 
     (goto-char end) 
     (when (and evil-cross-lines 
       evil-move-cursor-back 
       (not evil-move-beyond-eol) 
       (not (evil-visual-state-p)) 
       (not (evil-operator-state-p)) 
       (eolp) (not (eobp)) (not (bolp))) 
     (forward-char))))) 

回答

1

evil-invert-char使用常規defun,但用宏evil-define-operator,可以在evil-macros.el發現沒有定義。使用M-x describe-function RET evil-define-operator RET

evil-define-operator is a Lisp macro in ‘evil-macros.el’. 

(evil-define-operator OPERATOR (BEG END ARGS...) DOC [[KEY VALUE]...] BODY...) 

Define an operator command OPERATOR. 

您可以使用優秀的macrostep模式(這勢必, d m在我Spacemacs,在emacs-lisp-mode時)擴大evil-define-operator。第一次擴展將把evil-define-operator宏視爲evil-define-command宏視圖,其中包括致電interactive。由於這個宏擴展是由elisp解釋器完成的,或者在字節編譯之前,可以使用由宏插入的interactive調用來分配變量BEGEND