在Evil-Visual-Mode中自动输入Beg End参数 [英] Enter Beg End parameters automatically in Evil-Visual-Mode

查看:141
本文介绍了在Evil-Visual-Mode中自动输入Beg End参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一些功能,例如邪恶改变或邪恶删除,在邪恶视觉状态的视觉区域的开始和结束处都具有. 我已经在这些函数的"evil-commands.el"中查看了源代码,但是它们的"beg"和"end"参数似乎无处不在.还有一些(例如下面的一个)甚至不是交互式的.

I see some functions like evil-change or evil-delete are take in the beginning and end of a visual region in evil-visual-state. I've looked at the source code in "evil-commands.el" of these functions but their 'beg' and 'end' parameters just seem to come out of nowhere. And some (such as the one below) aren't even interactive.

这是为什么?我如何用自己的方法做同样的事情?

Why this is and how I can do the same thing in my own methods?

下面只是我看过的一种方法的示例:

Below is just an example of one of the methods I looked at:

;; 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)))))

推荐答案

evil-invert-char不是使用常规defun定义的,而是使用宏evil-define-operator定义的,该宏可以在evil-macros.el中找到.使用M-x describe-function RET evil-define-operator RET:

evil-invert-char is not defined using a regular defun, but using the macro evil-define-operator, which can be found in evil-macros.el. Using 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模式(在emacs-lisp-mode中时绑定到我的Spacemacs中的, d m)来扩展evil-define-operator.第一个扩展会将evil-define-operator-宏重写为evil-define-command -macro,其中包括对interactive的调用.由于此宏扩展是由elisp解释器完成的,或者是在字节编译之前进行的,因此可以使用宏插入的interactive调用来分配变量BEGEND.

You can use the excellent macrostep mode (which is bound to , d m in my Spacemacs, when in emacs-lisp-mode) to expand evil-define-operator. The first expansion will rewrite the evil-define-operator-macro into an evil-define-command-macro, which includes a call to interactive. As this macroexpansion is done by the elisp interpreter or before byte compilation, the variables BEG and END can be assigned using the interactive call inserted by the macro.

这篇关于在Evil-Visual-Mode中自动输入Beg End参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆