2016-10-27 5 views
0

조언을 추가 할 때 elisp 함수에서 본문의 특정 표현식을 어떻게 일치 시킵니까? 특히 다음 예제에서는 find-file 대신 find-file-noselect을 사용하는 기능을 권장합니다. (find-file path)(find-file-noselect path)입니다.조언을 사용하여 elisp 함수 본문의 표현식 변경

(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로 할 것이다, 그러나 다만이 먼저 작업을 진행하려합니다.

+0

조언 기능은 권고 기능의 이전, 이후 또는 대신 실행되지만 원래 기능 자체의 작동 방식은 수정하지 않습니다. – Barmar

+0

@Barmar 그래서,'ad-do-it'을'(cdr ad-do-it)'으로 설정하는 것과 같은 일을 할 방법이 없습니까? – jenesaisquoi

+0

그러면'tst-fun'가 호출되고 반환되는 값의'cdr'가 반환됩니다. – Barmar

답변

2

조언에서 find-filefind-file-noselect으로 일시적으로 다시 정의 할 수 있습니다.

(require 'cl) 
(defadvice tst-fun (around noselect activate) 
    (flet ((find-file (&rest args) 
      (apply 'find-file-noselect args))) 
    ad-do-it)) 
+0

나는 그것을 할 방법이 없다고 확신한다. 다른 Lisp 사투리에는': INSIDE' 조언이 있는데'tst-fun' 내부에서만'find-file '을 조언 할 수 있지만 Elisp는 이것을 가지고 있지 않습니다. – Barmar

+1

"현대"Elisp에서는 다음과 같이 보일 것입니다 :'(require-cl-lib) (advice-add 'tst-fun : around (람다 (orig & rest args) 파일) # 'find-file-noselect)) (orig args 적용))'. – Stefan