建议使用 emacs 交互功能:之前

2024-02-28

我想先建议一些使用交互式参数的函数,例如find-dired:

(defadvice find-dired (before eab-find-dired activate)
  (message "before!")
  (setq find-args '("-iname '**'" . 10)))

但 emacs 仅在之后执行此建议find-dired交互式会话,我无法设置find-args前。矛盾如何化解?

更新。注意defadvice宏是已弃用 https://www.gnu.org/software/emacs/manual/html_node/elisp/Porting-old-advices.html#Porting-old-advices.


artscan https://stackoverflow.com/users/1937596/artscan用可行的答案回答了他自己的问题,但它有点不完整且具有误导性。这还涉及到'interactive http://www.gnu.org/software/emacs/manual/html_mono/elisp.html#Using-Interactive,它本身可能会令人困惑 - 因为它看起来像是在命令体内定义的,但实际上是使用的before输入函数 - 并且在执行任何建议之前(除非该建议已'interactive打电话...)

The documentation for advice http://www.gnu.org/software/emacs/manual/html_mono/elisp.html#Combined-Definition lacks a number of details that would help in this situation, so the better place to look is actually the source: advice.el http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/advice.el. Look at that and find the comment section @ Foo games: An advice tutorial. You can also find the source in your Emacs itself with M-x find-library advice RET.

具体来说,对于这个问题,请查看中的部分advice.el贴上标签@@ Advising interactive behavior:- 因为这正是你想要做的。

如果您仔细阅读,您会发现该建议确实not需要采用以下形式around,但可以是before以及,并且它可以是after——虽然那只是自找麻烦。这是因为interactive是(并且必须)受到特殊对待的。

所以,下面的代码可以工作(注意before):

(defadvice find-dired (before eab-find-dired (dir args) activate)
  "ignore find-args, hard code \"-iname '**'\""
  (interactive
   (list (read-directory-name "Run find in directory: " nil "" t)
         (read-string "Run find (with args): " '("-iname '**'" . 10)
                      '(find-args-history . 1)))))

正如其他人所建议的,可能更干净的方法是编写自己的函数,我认为最简单的是林迪舞者 https://stackoverflow.com/users/623133/lindydancer's answer https://stackoverflow.com/a/14607894/6148.

建议是一个非常诱人的工具,但很容易被过度使用。我不会说它很危险,但应该谨慎使用。当编写自己的函数不起作用时,它似乎是最好的使用 - 例如,更改由您无法修改的代码调用的函数的行为。我认为这种情况可以找到很好的例子here https://stackoverflow.com/a/334600/6148, here https://stackoverflow.com/a/607866/6148, and here http://trey-jackson.blogspot.com/2010/10/emacs-tip-38-automatically-diff-binary.html(自吹自擂)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

建议使用 emacs 交互功能:之前 的相关文章

  • 如何让 Emacs 在保存文件时创建中间目录?

    有没有办法在 emacs 中创建文件夹树 类似于 mkdir p in bash 基本上 我希望 emacs 创建所有中间模具 如果它们不存在 当我保存文件时 功能make directory这样做 您的具体问题可能会这样解决 add ho
  • Emacs 在 haskell 模式下挂起,并调用 下面的 haskell-load-file 调用

    当在 Haskell 文件中时 我使用C c C l运行命令inferior haskell load file其目的是将当前文件加载到 GHCI 解释器中 但 Emacs 会挂起 直到我点击C g 有人知道我怎样才能让它发挥作用吗 all
  • 在 post-command-hook 中,这个用于kill-word的命令已经以某种方式变成了kill-region

    In my post command hook回调 当我这样做时kill word the this command var is kill region 并不是kill word正如预期的那样 我想那是因为kill word uses k
  • ESS 在 Windows 上找不到 Rterm.exe

    我将 R 安装在名为 X alphaAndOmega R R 的目录中 所以Rterm exe 32位版本 位于 X alphaAndOmega R R bin i386 我知道它不是 标准 R 目录 并且 标准 R 目录 例如 R 3 0
  • 在 Emacs 中定义新的工具提示

    我想向 emacs 添加自定义工具提示 更具体地说 每当我将鼠标悬停在符号 函数 变量 名称上时 用我的鼠标我想看到带有符号定义的工具提示 我知道我可以使用 cscope 这样的工具找到此类信息 但我不知道如何找到 将 cscope 的输出
  • Emacs 中的 C 注释 - Linux 内核风格

    我在用着 setq default comment style multi line and my region comments when doing M are void main int i int b printf format s
  • Emacs 关于 python 模式函数的默认提示

    在 python 模式下 有一个名为 py execute region 的函数 它将突出显示的代码区域发送到 Python 缓冲区进行评估 评估后 光标位于 Python 缓冲区中 但我希望它保留在脚本缓冲区中 以便我可以继续生成更多代码
  • 符号的函数定义为 void:declare-function

    emacs 新手 OSX 上的 GNU Emacs 22 1 1 按照说明安装了邪恶 我得到 Symbol s function definition is void declare function emacs debug init gi
  • emacs24 语义补全

    我正在尝试使用 emacs 24 及其附带的 cedet 版本来完成语义 补全适用于我在自己的源文件中定义的类 但补全不适用于标准库或 STL 内容这是我的 emacs 配置 require cedet require semantic r
  • windows下无法用emacs + sbcl启动slime

    我想配置我的 emacs 以使用 SLIME 和 SBCL emacs 文件如下所示 add to list load path D app slime setq inferior lisp program sbcl require sli
  • 如何根据文件位置运行钩子

    我参与了使用选项卡的 python 项目 但是我没有在我编写的所有其他代码中使用它们 在该特定项目中使用它们至关重要 项目位于特定目录下的一个目录中 IE main folder project1 project2 project3 etc
  • eshell (elisp shell) 启动时读取什么设置文件? eshell 如何设置它的 PATH?

    使用 emacs eshell echo PATH 显示与 PATH 环境变量不同的路径 我还检查了 eshell 不读取 bashrc 或 profile 我认为这就是路径不同的原因 eshell 启动时读取什么设置文件 eshell 如
  • 如何在组织模式议程树视图中显示条目的完整上下文

    在组织模式的每日 每周议程视图中 有没有办法显示条目的完整上下文 我对代码的解读是 它找到时间戳上方的第一个标题并显示它 然而 就我而言 该标题通常有 3 4 层深度 如果没有上面的项目符号 就没有意义 似乎也没有办法可以轻松改变这一点 过
  • 让 Emacs ansiterm 和 Zsh 更好地发挥作用

    我一直在尝试在 emacs 会话中使用 Zsh 而无需 emacs 重新映射所有 Zsh 键 我发现 ansi term 对此非常有效 但是我仍然遇到一些问题 我输出了很多垃圾字符 我可以用以下方法修复它 Setup proper term
  • 配置jedi不自动完成?

    我在 emacs 中安装了 jedi mode 来进行 python 编辑 因为我发现C and C 对于跳转到定义并返回非常有用 然而 自动完成并不是我想要的 当我尝试在安装了 jedi 的情况下使用 emacs 时 它会不断尝试提供建议
  • Emacs:在缓冲区求值期间将参数传递给下级 Python shell

    最近我开始使用 Emacs 作为 Python IDE 它不太直观 我现在遇到的问题是当使用 C c C c 评估缓冲区时如何将命令行参数传递给下级 python shell 感谢帮助 这似乎并不容易实现 管理的劣质流程python el模
  • emacs 临时文件的 .gitignore 正则表达式

    我正在尝试 gitignore emacs 临时 自动保存文件 我在用着 在我的 gitignore 中 But git add A在子文件夹中运行仍然给我 new file make collections py new file nor
  • 将字符定义为单词边界

    我已经定义了 字符在乳胶模式下充当单词组成部分 我对结果非常满意 唯一困扰我的是像这样的序列 alpha beta被视为单个单词 当然 这是预期的行为 有没有办法让 emacs 将特定字符解释为单词 starter 这样 它将始终被视为其后
  • 为什么在 emacs-lisp 中的函数参数之前使用#'?

    我熟悉 Emacs Lisp 但不熟悉 Common 或任何其他 Lisp 一些 Lisp 程序员建议 例如emacs 的基本功能 https stackoverflow com questions 17076646 a basic fun
  • Emacs C++,打开相应的头文件

    我是 emacs 新手 我想知道 是否有在头文件 源文件和相应的源文件 头文件之间切换的快捷方式 是否有像通用 emacs 参考卡那样的参考卡 Thanks There s ff find other file 您可以使用以下方法将其绑定到

随机推荐