emacs - 仅当从某个其他函数调用时才触发对函数的建议

标签 emacs elisp advising-functions defadvice

我正在尝试解决不能在当前和父目录 上调用 dired-do-shell-command(绑定(bind)到 !)的限制。 ..'。堆栈跟踪粘贴在底部。

我可以定义如下的建议来绕过这个错误:

(defadvice dired-get-filename (before h-no-error-if-not-filep activate)
  (ad-set-arg 1 t))

但这会影响对 dired-get-filename 的所有调用。 我希望它仅在堆栈为 dired-do-shell- 时触发命令 -> dired-get-marked-files -> dired-get-filename.

我能想到的唯一方法如下

  • 在建议定义中的 (with-output-to-string (backtrace)) 中搜索匹配项
  • 将周围的建议添加到其他方法以设置一些可以在建议定义中测试的变量。

有更好的方法吗?我想我正在寻找将当前堆栈跟踪作为数据结构而不是来自 (backtrace)

的字符串的访问权限
Debugger entered--Lisp error: (error "Cannot operate on `.' or `..'")
  signal(error ("Cannot operate on `.' or `..'"))
  error("Cannot operate on `.' or `..'")
  dired-get-filename(t)
  dired-get-marked-files(t nil)
  (let ((files (dired-get-marked-files t current-prefix-arg))) (list (dired-read-shell-command (concat "! on " "%s: ") current-prefix-arg files) current-prefix-arg files))
  call-interactively(dired-do-shell-command nil nil)

Why can dired-do-shell-command not operate on '.' or '..'?

最佳答案

您可以通过 backtrace-frame 一次访问一层堆栈跟踪。但这确实在插入黑客攻击。我还建议您 M-x report-emacs-bug 请求 !... 上工作。

关于emacs - 仅当从某个其他函数调用时才触发对函数的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13056273/

相关文章:

emacs - 将 CSV 导入组织模式属性

emacs - undo、save-excursion、delete-region 之间的交互

lisp - 预定义全局变量的词法绑定(bind)

emacs shell : type once, 到处运行

emacs - Elisp 获取函数参数?

clojure - 在 Clojure 中建议协议(protocol)方法

Emacs 光标移动建议

emacs - 如何强制 Emacs 不在特定窗口中显示缓冲区?

Emacs24 无法正确渲染字体

regex - 非交互式 emacs 正则表达式替代品