bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#789: find-function fails on advised subrs


From: Glenn Morris
Subject: bug#789: find-function fails on advised subrs
Date: Fri, 14 Nov 2008 01:19:04 -0500
User-agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/)

martin rudalics wrote:

> If you can think of an easy fix for these, please go ahead.  Otherwise,
> I'll look into this next week.

How about:

*** find-func.el        28 Jul 2008 13:19:10 -0000      1.91
--- find-func.el        14 Nov 2008 06:16:53 -0000
***************
*** 165,170 ****
--- 165,181 ----
  If nil, do not try to find the source code of functions and variables
  defined in C.")
  
+ (declare-function ad-get-advice-info "advice" (function))
+ 
+ (defun find-function-advised-original (func)
+   "Return the original function symbol of an advised function FUNC.
+ If FUNC is not advised, or not a symbol, just returns FUNC."
+   (or (and (symbolp func)
+          (featurep 'advice)
+          (let ((ofunc (cdr (assq 'origname (ad-get-advice-info func)))))
+            (and (fboundp ofunc) ofunc)))
+       func))
+ 
  (defun find-function-C-source (fun-or-var file type)
    "Find the source location where FUN-OR-VAR is defined in FILE.
  TYPE should be nil to find a function, or `defvar' to find a variable."
***************
*** 176,182 ****
      (error "The C source file %s is not available"
           (file-name-nondirectory file)))
    (unless type
!     (setq fun-or-var (indirect-function fun-or-var)))
    (with-current-buffer (find-file-noselect file)
      (goto-char (point-min))
      (unless (re-search-forward
--- 187,195 ----
      (error "The C source file %s is not available"
           (file-name-nondirectory file)))
    (unless type
!     (setq fun-or-var (find-function-advised-original
!                     (indirect-function
!                      (find-function-advised-original fun-or-var)))))
    (with-current-buffer (find-file-noselect file)
      (goto-char (point-min))
      (unless (re-search-forward
***************
*** 293,310 ****
  in `load-path'."
    (if (not function)
        (error "You didn't specify a function"))
!   (let ((def (symbol-function function))
        aliases)
      (while (symbolp def)
        (or (eq def function)
          (if aliases
              (setq aliases (concat aliases
                                    (format ", which is an alias for `%s'"
                                            (symbol-name def))))
!           (setq aliases (format "`%s' an alias for `%s'"
                                  function (symbol-name def)))))
!       (setq function (symbol-function function)
!           def (symbol-function function)))
      (if aliases
        (message "%s" aliases))
      (let ((library
--- 306,325 ----
  in `load-path'."
    (if (not function)
      (error "You didn't specify a function"))
!   (let ((def (symbol-function (find-function-advised-original function)))
        aliases)
+     ;; FIXME for completeness, it might be nice to print something like:
+     ;; foo (which is advised), which is an alias for bar (which is advised).
      (while (symbolp def)
        (or (eq def function)
          (if aliases
              (setq aliases (concat aliases
                                    (format ", which is an alias for `%s'"
                                            (symbol-name def))))
!           (setq aliases (format "`%s' is an alias for `%s'"
                                  function (symbol-name def)))))
!       (setq function (symbol-function (find-function-advised-original 
function))
!           def (symbol-function (find-function-advised-original function))))
      (if aliases
        (message "%s" aliases))
      (let ((library






reply via email to

[Prev in Thread] Current Thread [Next in Thread]