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: martin rudalics
Subject: bug#789: find-function fails on advised subrs
Date: Thu, 28 Aug 2008 17:33:51 +0200
User-agent: Thunderbird 2.0.0.16 (Windows/20080708)

> emacs -Q
> M-x find-function delete-window
>   -> works
>
> (defadvice delete-window (after foo activate)
>   ""
>   t)
>
> M-x find-function delete-window
>   -> fails

I attached a tentative fix.  Please try it.

martin
*** find-func.el.~1.91.~        2008-07-28 15:19:10.000000000 +0200
--- find-func.el        2008-08-28 17:15:40.156250000 +0200
***************
*** 165,195 ****
  If nil, do not try to find the source code of functions and variables
  defined in C.")
  
  (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."
!   (unless find-function-C-source-directory
!     (setq find-function-C-source-directory
!         (read-directory-name "Emacs C source dir: " nil nil t)))
!   (setq file (expand-file-name file find-function-C-source-directory))
!   (unless (file-readable-p file)
!     (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
!            (if type
                 (concat "DEFVAR[A-Z_]*[ \t\n]*([ \t\n]*\""
!                        (regexp-quote (symbol-name fun-or-var))
!                        "\"")
!              (concat "DEFUN[ \t\n]*([ \t\n]*\""
!                      (regexp-quote (subr-name fun-or-var))
!                      "\""))
!            nil t)
!       (error "Can't find source for %s" fun-or-var))
!     (cons (current-buffer) (match-beginning 0))))
  
  ;;;###autoload
  (defun find-library (library)
--- 165,205 ----
  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-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."
!   (let (advised)
!     (unless find-function-C-source-directory
!       (setq find-function-C-source-directory
!           (read-directory-name "Emacs C source dir: " nil nil t)))
!     (setq file (expand-file-name file find-function-C-source-directory))
!     (unless (file-readable-p file)
!       (error "The C source file %s is not available"
!            (file-name-nondirectory file)))
!     (cond
!      ((and (symbolp fun-or-var) (featurep 'advice)
!          (ad-get-advice-info fun-or-var))
!       (setq advised t))
!      ((not 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
!              (cond
!               (advised
!                (concat "DEFUN[ \t\n]*([ \t\n]*\""
!                        (regexp-quote (symbol-name fun-or-var)) "\""))
!               (type
                 (concat "DEFVAR[A-Z_]*[ \t\n]*([ \t\n]*\""
!                        (regexp-quote (symbol-name fun-or-var)) "\""))
!               (t
!                (concat "DEFUN[ \t\n]*([ \t\n]*\""
!                        (regexp-quote (subr-name fun-or-var)) "\"")))
!              nil t)
!       (error "Can't find source for %s" fun-or-var))
!       (cons (current-buffer) (match-beginning 0)))))
  
  ;;;###autoload
  (defun find-library (library)
***************
*** 291,312 ****
  If the file where FUNCTION is defined is not known, then it is
  searched for in `find-function-source-path' if non-nil, otherwise
  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
           (cond ((eq (car-safe def) 'autoload)
                  (nth 1 def))
--- 301,339 ----
  If the file where FUNCTION is defined is not known, then it is
  searched for in `find-function-source-path' if non-nil, otherwise
  in `load-path'."
!   (unless function
!     (error "You didn't specify a function"))
!   (let* ((advised (and (symbolp function) (featurep 'advice)
!                      (ad-get-advice-info function)))
!        ;; If the function is advised, use the symbol that has the
!        ;; real definition, if that symbol is already set up.
!        (real-function
!         (or (and advised
!                  (let ((origname (cdr (assq 'origname advised))))
!                    (and (fboundp origname) origname)))
!             function))
!        ;; Get the real definition.
!        (def (if (symbolp real-function)
!                 (symbol-function real-function)
!               function))
!        file-name string aliases)
!     (cond
!      (advised
!       (message "This function is advised"))
!      ((symbolp def)
!       (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)))
!       (when aliases
!       (message "%s" aliases))))
! 
      (let ((library
           (cond ((eq (car-safe def) 'autoload)
                  (nth 1 def))

reply via email to

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