* lisp/emacs-lisp/advice.el (ad-read-advised-function):
authorKevin Ryde <user42@zip.com.au>
Mon, 23 May 2011 14:38:28 +0000 (11:38 -0300)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 23 May 2011 14:38:28 +0000 (11:38 -0300)
Use `function-called-at-point' as the default default, if it has
advice and passes PREDICATE.

lisp/ChangeLog
lisp/emacs-lisp/advice.el

index f246b8a..95cae40 100644 (file)
@@ -1,3 +1,9 @@
+2011-05-23  Kevin Ryde  <user42@zip.com.au>
+
+       * emacs-lisp/advice.el (ad-read-advised-function):
+       Use `function-called-at-point' as the default default, if it has
+       advice and passes PREDICATE.
+
 2011-05-23  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * emacs-lisp/bytecomp.el (byte-compile-function-form): Only call
index 5934975..a245a91 100644 (file)
@@ -2135,16 +2135,27 @@ Redefining advices affect the construction of an advised definition."
 ;; @@ Interactive input functions:
 ;; ===============================
 
+(declare-function 'function-called-at-point "help")
+
 (defun ad-read-advised-function (&optional prompt predicate default)
   "Read name of advised function with completion from the minibuffer.
 An optional PROMPT will be used to prompt for the function.  PREDICATE
 plays the same role as for `try-completion' (which see).  DEFAULT will
-be returned on empty input (defaults to the first advised function for
-which PREDICATE returns non-nil)."
+be returned on empty input (defaults to the first advised function or
+function at point for which PREDICATE returns non-nil)."
   (if (null ad-advised-functions)
       (error "ad-read-advised-function: There are no advised functions"))
   (setq default
        (or default
+           ;; Prefer func name at point, if it's in ad-advised-functions etc.
+           (let ((function (progn
+                             (require 'help)
+                             (function-called-at-point))))
+             (and function
+                  (assoc (symbol-name function) ad-advised-functions)
+                  (or (null predicate)
+                      (funcall predicate function))
+                  function))
            (ad-do-advised-functions (function)
              (if (or (null predicate)
                      (funcall predicate function))