unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#789: find-function fails on advised subrs
@ 2008-08-28 15:33 martin rudalics
  2008-11-08 19:37 ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: martin rudalics @ 2008-08-28 15:33 UTC (permalink / raw)
  To: 789; +Cc: raman

[-- Attachment #1: Type: text/plain, Size: 234 bytes --]

 > 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

[-- Attachment #2: 789.diff --]
[-- Type: text/plain, Size: 5174 bytes --]

*** 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))

^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#789: find-function fails on advised subrs
  2008-08-28 15:33 bug#789: find-function fails on advised subrs martin rudalics
@ 2008-11-08 19:37 ` Glenn Morris
  2008-11-08 21:54   ` martin rudalics
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2008-11-08 19:37 UTC (permalink / raw)
  To: martin rudalics; +Cc: 789

martin rudalics wrote:

> I attached a tentative fix.  Please try it.

Hi martin, I finally tried this...

> !     (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))))

This fails if I have an alias to an advised function.

> ! 	 ;; Get the real definition.
> ! 	 (def (if (symbolp real-function)
> ! 		  (symbol-function real-function)
> ! 		function))
> ! 	 file-name string aliases)

file-name and string seem unused.

> !     (cond
> !      (advised
> !       (message "This function is advised"))

Should this function be printing if something is advised?
Again, what about aliases to advised functions?

Otherwise, it seems to work ok.






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#789: find-function fails on advised subrs
  2008-11-08 19:37 ` Glenn Morris
@ 2008-11-08 21:54   ` martin rudalics
  2008-11-14  6:19     ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: martin rudalics @ 2008-11-08 21:54 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 789

 > Hi martin, I finally tried this...

... and I've forgotten all about it ;-)

 >
 >> !     (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))))
 >
 > This fails if I have an alias to an advised function.
 >
 >> ! 	 ;; Get the real definition.
 >> ! 	 (def (if (symbolp real-function)
 >> ! 		  (symbol-function real-function)
 >> ! 		function))
 >> ! 	 file-name string aliases)
 >
 > file-name and string seem unused.
 >
 >> !     (cond
 >> !      (advised
 >> !       (message "This function is advised"))
 >
 > Should this function be printing if something is advised?
 > Again, what about aliases to advised functions?

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

martin






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#789: find-function fails on advised subrs
  2008-11-08 21:54   ` martin rudalics
@ 2008-11-14  6:19     ` Glenn Morris
  2008-11-15 10:00       ` martin rudalics
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2008-11-14  6:19 UTC (permalink / raw)
  To: martin rudalics; +Cc: 789

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






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#789: find-function fails on advised subrs
  2008-11-14  6:19     ` Glenn Morris
@ 2008-11-15 10:00       ` martin rudalics
  0 siblings, 0 replies; 5+ messages in thread
From: martin rudalics @ 2008-11-15 10:00 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 789

 > How about:
 >
 > *** find-func.el	28 Jul 2008 13:19:10 -0000	1.91
 > --- find-func.el	14 Nov 2008 06:16:53 -0000

Looks much simpler than my original proposal ;-)

I think you should install this ASAP, so we can find out whether there
are any remaining problems.

martin






^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-15 10:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-28 15:33 bug#789: find-function fails on advised subrs martin rudalics
2008-11-08 19:37 ` Glenn Morris
2008-11-08 21:54   ` martin rudalics
2008-11-14  6:19     ` Glenn Morris
2008-11-15 10:00       ` martin rudalics

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).