changeset 81039:fc951d52295d

(find-source-lisp-file): New function. (describe-function-1): Use find-source-lisp-file to find source file in compile tree.
author Jan Djärv <jan.h.d@swipnet.se>
date Tue, 22 May 2007 13:45:44 +0000
parents a5b210b4b0d3
children daf60d1c2ce8
files lisp/help-fns.el
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/help-fns.el	Tue May 22 12:51:42 2007 +0000
+++ b/lisp/help-fns.el	Tue May 22 13:45:44 2007 +0000
@@ -232,6 +232,23 @@
 	      libname)
 	  file))))
 
+(defun find-source-lisp-file (file-name)
+  (let* ((elc-file (locate-file (concat file-name
+				 (if (string-match "\\.el" file-name)
+				     "c"
+				   ".elc"))
+				 load-path))
+	 (str (if (and elc-file (file-readable-p elc-file))
+		  (with-temp-buffer 
+		    (insert-file-contents-literally elc-file nil 0 256)
+		    (buffer-string))))
+	 (src-file (and str
+			(string-match ";;; from file \\(.*\\.el\\)" str)
+			(match-string 1 str))))
+    (if (and src-file (file-readable-p src-file))
+	src-file
+      file-name)))
+
 ;;;###autoload
 (defun describe-function-1 (function)
   (let* ((def (if (symbolp function)
@@ -309,6 +326,10 @@
       ;; but that's completely wrong when the user used load-file.
       (princ (if (eq file-name 'C-source) "C source code" file-name))
       (princ "'")
+      ;; See if lisp files are present where they where installed from.
+      (if (not (eq file-name 'C-source))
+	  (setq file-name (find-source-lisp-file file-name)))
+
       ;; Make a hyperlink to the library.
       (with-current-buffer standard-output
         (save-excursion