Stefan Monnier | 1 Jul 2011 05:15
Picon

/srv/bzr/emacs/trunk r104825: * lisp/emacs-lisp/find-func.el (find-library--load-name): New fun.

------------------------------------------------------------
revno: 104825
fixes bug(s): http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8803
committer: Stefan Monnier <monnier <at> iro.umontreal.ca>
branch nick: trunk
timestamp: Thu 2011-06-30 23:15:02 -0400
message:
  * lisp/emacs-lisp/find-func.el (find-library--load-name): New fun.
  (find-library-name): Use it to find relative load names when provided
  absolute file name.
modified:
  lisp/ChangeLog
  lisp/emacs-lisp/find-func.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog	2011-06-30 23:19:45 +0000
+++ b/lisp/ChangeLog	2011-07-01 03:15:02 +0000
 <at>  <at>  -1,3 +1,9  <at>  <at> 
+2011-07-01  Stefan Monnier  <monnier <at> iro.umontreal.ca>
+
+	* emacs-lisp/find-func.el (find-library--load-name): New fun.
+	(find-library-name): Use it to find relative load names when provided
+	absolute file name (bug#8803).
+
 2011-06-30  Lars Magne Ingebrigtsen  <larsi <at> gnus.org>

 	* textmodes/flyspell.el (flyspell-word): Consider words that
 <at>  <at>  -14,7 +20,7  <at>  <at> 

 	* progmodes/cc-guess.el: New file.

-	* progmodes/cc-langs.el (c-mode-menu): Added "Style..." submenu.
+	* progmodes/cc-langs.el (c-mode-menu): Add "Style..." submenu.

 	* progmodes/cc-styles.el (cc-choose-style-for-mode): New function
 	derived from `c-basic-common-init'.

=== modified file 'lisp/emacs-lisp/find-func.el'
--- a/lisp/emacs-lisp/find-func.el	2011-01-25 04:08:28 +0000
+++ b/lisp/emacs-lisp/find-func.el	2011-07-01 03:15:02 +0000
 <at>  <at>  -141,6 +141,15  <at>  <at> 
     (dolist (suffix (get-load-suffixes) (nreverse suffixes))
       (unless (string-match "elc" suffix) (push suffix suffixes)))))

+(defun find-library--load-name (library)
+  (let ((name library))
+    (dolist (dir load-path)
+      (let ((rel (file-relative-name library dir)))
+        (if (and (not (string-match "\\`\\.\\./" rel))
+                 (< (length rel) (length name)))
+            (setq name rel))))
+    (unless (equal name library) name)))
+
 (defun find-library-name (library)
   "Return the absolute file name of the Emacs Lisp source of LIBRARY.
 LIBRARY should be a string (the name of the library)."
 <at>  <at>  -148,13 +157,23  <at>  <at> 
   ;; the same name.
   (if (string-match "\\.el\\(c\\(\\..*\\)?\\)\\'" library)
       (setq library (replace-match "" t t library)))
-  (or 
+  (or
    (locate-file library
 		(or find-function-source-path load-path)
 		(find-library-suffixes))
    (locate-file library
 		(or find-function-source-path load-path)
 		load-file-rep-suffixes)
+   (when (file-name-absolute-p library)
+     (let ((rel (find-library--load-name library)))
+       (when rel
+         (or
+          (locate-file rel
+                       (or find-function-source-path load-path)
+                       (find-library-suffixes))
+          (locate-file rel
+                       (or find-function-source-path load-path)
+                       load-file-rep-suffixes)))))
    (error "Can't find library %s" library)))

 (defvar find-function-C-source-directory

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog	2011-06-30 23:19:45 +0000
+++ b/lisp/ChangeLog	2011-07-01 03:15:02 +0000
 <at>  <at>  -1,3 +1,9  <at>  <at> 
+2011-07-01  Stefan Monnier  <monnier <at> iro.umontreal.ca>
+
+	* emacs-lisp/find-func.el (find-library--load-name): New fun.
+	(find-library-name): Use it to find relative load names when provided
+	absolute file name (bug#8803).
+
 2011-06-30  Lars Magne Ingebrigtsen  <larsi <at> gnus.org>

 	* textmodes/flyspell.el (flyspell-word): Consider words that
 <at>  <at>  -14,7 +20,7  <at>  <at> 

 	* progmodes/cc-guess.el: New file.

-	* progmodes/cc-langs.el (c-mode-menu): Added "Style..." submenu.
+	* progmodes/cc-langs.el (c-mode-menu): Add "Style..." submenu.

 	* progmodes/cc-styles.el (cc-choose-style-for-mode): New function
 	derived from `c-basic-common-init'.

=== modified file 'lisp/emacs-lisp/find-func.el'
--- a/lisp/emacs-lisp/find-func.el	2011-01-25 04:08:28 +0000
+++ b/lisp/emacs-lisp/find-func.el	2011-07-01 03:15:02 +0000
 <at>  <at>  -141,6 +141,15  <at>  <at> 
     (dolist (suffix (get-load-suffixes) (nreverse suffixes))
       (unless (string-match "elc" suffix) (push suffix suffixes)))))

+(defun find-library--load-name (library)
+  (let ((name library))
+    (dolist (dir load-path)
+      (let ((rel (file-relative-name library dir)))
+        (if (and (not (string-match "\\`\\.\\./" rel))
+                 (< (length rel) (length name)))
+            (setq name rel))))
+    (unless (equal name library) name)))
+
 (defun find-library-name (library)
   "Return the absolute file name of the Emacs Lisp source of LIBRARY.
 LIBRARY should be a string (the name of the library)."
 <at>  <at>  -148,13 +157,23  <at>  <at> 
   ;; the same name.
   (if (string-match "\\.el\\(c\\(\\..*\\)?\\)\\'" library)
       (setq library (replace-match "" t t library)))
-  (or 
+  (or
    (locate-file library
 		(or find-function-source-path load-path)
 		(find-library-suffixes))
    (locate-file library
 		(or find-function-source-path load-path)
 		load-file-rep-suffixes)
+   (when (file-name-absolute-p library)
+     (let ((rel (find-library--load-name library)))
+       (when rel
+         (or
+          (locate-file rel
+                       (or find-function-source-path load-path)
+                       (find-library-suffixes))
+          (locate-file rel
+                       (or find-function-source-path load-path)
+                       load-file-rep-suffixes)))))
    (error "Can't find library %s" library)))

 (defvar find-function-C-source-directory


Gmane