1

添加建议时,如何在 elisp 函数的主体中匹配特定表达式?具体来说,在下面的示例中,我想建议使用该函数来find-file-noselect代替find-file,即。该行将(find-file path)生效(find-file-noselect path)

(defun tst-fun (path line column)
  (find-file path)
  (goto-char (point-min))
  (forward-line (1- line))
  (forward-char column))

;; not sure how to structure this
(defadvice tst-fun (around noselect activate)
  (find-file-noselect (ad-get-arg 0))
  ad-do-it)

我宁愿把它当作ad-add-function,但我想先让它工作。

4

1 回答 1

3

您可以按照建议临时重新find-file定义find-file-noselect

(require 'cl)
(defadvice tst-fun (around noselect activate)
  (flet ((find-file (&rest args)
           (apply 'find-file-noselect args)))
    ad-do-it))
于 2016-10-27T22:40:40.210 回答