【发布时间】:2015-10-06 23:05:21
【问题描述】:
我也想使用 Emacs 作为文件管理器并使用 xdg-open 打开大文件(在 dired 或 speedbar 中)。我可以将defadvice 用于abort-if-file-too-large 功能吗?如何正确使用?
【问题讨论】:
标签: elisp
我也想使用 Emacs 作为文件管理器并使用 xdg-open 打开大文件(在 dired 或 speedbar 中)。我可以将defadvice 用于abort-if-file-too-large 功能吗?如何正确使用?
【问题讨论】:
标签: elisp
通知abort-if-file-too-large 要求即使它从外部打开文件仍会引发错误,否则find-file-noselect 仍会尝试打开文件。此外,您只想在传递给abort-if-file-too-large 的操作类型指示正在打开文件时才调用外部程序。尽管您可能希望调整 call-process 的参数以使其更适合您的场景,但类似以下内容将起作用:
(defun open-outside-emacs (orig-fun size op-type filename)
(if (not (string-equal op-type "open"))
(apply orig-fun size op-type filename)
(call-process "/usr/bin/xdg-open" nil 0 nil (expand-file-name filename))
(error "opened externally")))
(advice-add 'abort-if-file-too-large :around #'open-outside-emacs)
【讨论】: