unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* locate-library, the NOSUFFIX arg and a [PATCH]
@ 2010-01-19 22:28 MON KEY
  2010-01-21 14:08 ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: MON KEY @ 2010-01-19 22:28 UTC (permalink / raw)
  To: emacs-devel

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

`locate-libary' is either broken, doesn't work as documented, or both.

(documentation 'locate-library)

,----
| It can omit the suffix (a.k.a. file-name extension) if NOSUFFIX is
| nil (which is the default, see below).
`----

,----
| Optional second arg NOSUFFIX non-nil means don't add suffixes `load-suffixes'
| to the specified name LIBRARY.
`----

Aren't these two statements mutually exclusive?

I don't think the docstring even reflects the intent of locate-library's
NOSUFFIX arg esp. as it doesn't appear to be _able_ to return a library name
sans extension when not called-interactively.

FWICG there is a problem occuring with the return value of
`load-file-rep-suffixes', which returns an empty string "" as the first elt of
its return value (unless bound otherwise).

This appears to be happening at the variables primitive definition per lread.c's
`Fcons'ing of `empty_unibyte_string'. Which among other things may be causing
problems like this:

(locate-file-completion-table load-path '("") "subr" #'(lambda (y)
(string-match-p ".*z" y)) 'nil)
=> "subr.el.gz"

Which, as it relates to locate-library, causes wonkiness with the local variable
`file'.  Following shows this with NOSUFFIX both t and nil:

(let (nosuffix)
  (append (unless nosuffix (get-load-suffixes))
          load-file-rep-suffixes))
=> (".elc" ".elc.gz" ".el" ".el.gz" "" ".gz")

(let ((nosuffix t))
  (append (unless nosuffix (get-load-suffixes))
          load-file-rep-suffixes))
=> ("" ".gz")

IOW, even if where the empty string problem is corrected, if my reading is
correct `locate-library' still won't perform according to the docstring as
written.

The attached patch corrects the problem without mucking with
`load-file-rep-suffixes' and changes the semanics of nosuffix to mean:

"When called from a program and NOSUFFIX is a boolean, string, or list of
strings, return LIBRARY's file-truename as if by `file-name-sans-extension'."

Following are examples of the behavior provided by the patch:

(locate-library "subr")
=> "/usr/share/emacs/23.1.90/lisp/subr.elc"

(locate-library "subr" ".elc")
=> "/usr/share/emacs/23.1.90/lisp/subr"

(locate-library "subr" ".el")
=> "/usr/share/emacs/23.1.90/lisp/subr"

(locate-library "subr.el" ".gz")
=> "/usr/share/emacs/23.1.90/lisp/subr"

(locate-library "subr" ".el.gz")
=> "/usr/share/emacs/23.1.90/lisp/subr"

(locate-library "subr" ".gz")
=> nil

(locate-library "subr" t)
=> "/usr/share/emacs/23.1.90/lisp/subr"

(apply 'locate-library "subr" '(nil nil t))
=> "/usr/share/emacs/23.1.90/lisp/subr.elc"

(apply 'locate-library "subr" '(".el.gz" nil t))
=> "/usr/share/emacs/23.1.90/lisp/subr"

(apply 'locate-library "subr" '(".elc" nil t))
=> "/usr/share/emacs/23.1.90/lisp/subr"

(let (with-symbolic)
  (shell-command (concat "ln -s "
                         (locate-file "subr.el.gz" load-path)
                         " ~/subr.el.gz"))
  (prog1
      (setq with-symbolic
            (list (locate-library "subr" t '("~/"))
                  (locate-library "subr" ".el" '("~/"))
                  (locate-library "subr" '(".el" ".el.gz" ".elc"
".bubba") '("~/"))
                  (locate-library "subr" nil '("~/"))
                  (locate-library "subr" ".elc" '("~/")) ;<- return nil
                  (apply 'locate-library "subr" '(".el" nil t))
                  (apply 'locate-library "subr" '(".el" nil t))
                  ;; follwing returns nil a PATH can't override intractive's
                  ;; load-path arg to `locate-file-completion-table'
                  (apply 'locate-library "subr" '(t '("~/") t))))
    (shell-command "rm -f ~/subr.el.gz")))

=> ("/usr/share/emacs/23.1.90/lisp/subr"
    "/usr/share/emacs/23.1.90/lisp/subr"
    "/usr/share/emacs/23.1.90/lisp/subr"
    "/home/MON/subr.el.gz"
    nil
    "/usr/share/emacs/23.1.90/lisp/subr"
    "/usr/share/emacs/23.1.90/lisp/subr"
    nil)

;;; ==============================
--- subr.el~99304~	2010-01-19 15:34:00.000000000 -0500
+++ subr.el	2010-01-19 17:05:24.000000000 -0500
@@ -1586,16 +1586,34 @@
                                        load-path (get-load-suffixes)))
 		     nil nil
 		     t))
-  (let ((file (locate-file library
-			   (or path load-path)
-			   (append (unless nosuffix (get-load-suffixes))
-				   load-file-rep-suffixes))))
+  (let* ((lfrs (remove "" load-file-rep-suffixes))
+         (sfx  (cond ((booleanp nosuffix)
+                      (delete-dups (append lfrs (get-load-suffixes))))
+                     ((and nosuffix (stringp nosuffix))
+                      `(,nosuffix
+                        ,@(mapcar #'(lambda (z)
+                                      (concat nosuffix z))
+                                  lfrs)))
+                     ((consp nosuffix)
+                      (delete-dups (append nosuffix lfrs)))
+                     (t (append lfrs(get-load-suffixes)))))
+         (file (locate-file library
+                            (or path load-path)
+                            sfx)))
+    (when (and file nosuffix)
+      (setq file (file-truename file))
+      (setq file (concat (file-name-directory file)
+                         (if (string-match-p ".*.gz" file)
+                             (file-name-sans-extension
+                              (file-name-nondirectory
+                               (file-name-sans-extension file)))
+                             (file-name-sans-extension
+                              (file-name-nondirectory file))))))
     (if interactive-call
-	(if file
-	    (message "Library is file %s" (abbreviate-file-name file))
-	  (message "No library %s in search path" library)))
+        (if file
+            (message "Library is file %s" (abbreviate-file-name file))
+            (message "No library %s in search path" library)))
     file))
-
 \f
 ;;;; Specifying things to do later.

;;; ==============================

[-- Attachment #2: subr.el.diff --]
[-- Type: application/octet-stream, Size: 1925 bytes --]

--- subr.el~99304~	2010-01-19 15:34:00.000000000 -0500
+++ subr.el	2010-01-19 17:05:24.000000000 -0500
@@ -1586,16 +1586,34 @@
                                        load-path (get-load-suffixes)))
 		     nil nil
 		     t))
-  (let ((file (locate-file library
-			   (or path load-path)
-			   (append (unless nosuffix (get-load-suffixes))
-				   load-file-rep-suffixes))))
+  (let* ((lfrs (remove "" load-file-rep-suffixes))
+         (sfx  (cond ((booleanp nosuffix)
+                      (delete-dups (append lfrs (get-load-suffixes))))
+                     ((and nosuffix (stringp nosuffix))
+                      `(,nosuffix 
+                        ,@(mapcar #'(lambda (z)
+                                      (concat nosuffix z))
+                                  lfrs)))
+                     ((consp nosuffix)
+                      (delete-dups (append nosuffix lfrs)))
+                     (t (append lfrs(get-load-suffixes)))))
+         (file (locate-file library
+                            (or path load-path)
+                            sfx)))
+    (when (and file nosuffix)
+      (setq file (file-truename file))
+      (setq file (concat (file-name-directory file)
+                         (if (string-match-p ".*.gz" file)
+                             (file-name-sans-extension
+                              (file-name-nondirectory 
+                               (file-name-sans-extension file)))
+                             (file-name-sans-extension
+                              (file-name-nondirectory file))))))
     (if interactive-call
-	(if file
-	    (message "Library is file %s" (abbreviate-file-name file))
-	  (message "No library %s in search path" library)))
+        (if file
+            (message "Library is file %s" (abbreviate-file-name file))
+            (message "No library %s in search path" library)))
     file))
-
 \f
 ;;;; Specifying things to do later.
 

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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-19 22:28 locate-library, the NOSUFFIX arg and a [PATCH] MON KEY
@ 2010-01-21 14:08 ` Stefan Monnier
  2010-01-21 23:58   ` MON KEY
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2010-01-21 14:08 UTC (permalink / raw)
  To: MON KEY; +Cc: emacs-devel

> ,----
> | It can omit the suffix (a.k.a. file-name extension) if NOSUFFIX is
> | nil (which is the default, see below).
> `----

This is poorly worded but means that it will not only look for files
of the form DIR/FILE.SUFFIX but also for DIR/FILE (i.e. it will add the
empty string as a valid suffix).

> I don't think the docstring even reflects the intent of locate-library's
> NOSUFFIX arg esp. as it doesn't appear to be _able_ to return a library name
> sans extension when not called-interactively.

Indeed, this arg only controls how the search is performed, not in which
form the result will be returned.

> (locate-file-completion-table load-path '("") "subr" #'(lambda (y)
> (string-match-p ".*z" y)) 'nil)
  ^^^^^^^^^^^^^^^^^^^^^^^^
  aka (string-match "z" y)

> => "subr.el.gz"

Looks right to me.

> (let (nosuffix)
>   (append (unless nosuffix (get-load-suffixes))
>           load-file-rep-suffixes))
> => (".elc" ".elc.gz" ".el" ".el.gz" "" ".gz")

> (let ((nosuffix t))
>   (append (unless nosuffix (get-load-suffixes))
>           load-file-rep-suffixes))
> => ("" ".gz")

All looks as expected.

> "When called from a program and NOSUFFIX is a boolean, string, or list of
> strings, return LIBRARY's file-truename as if by `file-name-sans-extension'."

That completely changes the meaning of this argument.  Why don't you
call file-name-sans-extension outside of locate-library instead, if you
want that?


        Stefan




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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-21 14:08 ` Stefan Monnier
@ 2010-01-21 23:58   ` MON KEY
  2010-01-22 15:18     ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: MON KEY @ 2010-01-21 23:58 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

Hi Stefan,

On Thu, Jan 21, 2010 at 9:08 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> ,----
>> | It can omit the suffix (a.k.a. file-name extension) if NOSUFFIX is
>> | nil (which is the default, see below).
>> `----
>
> This is poorly worded but means that it will not only look for files
> of the form DIR/FILE.SUFFIX but also for DIR/FILE (i.e. it will add the
> empty string as a valid suffix).
>

A library is not a file. It is an abstraction of one. This is a subtle but
important difference as you are no doubt well aware.

The current docstring begins:

,----
| Show the precise file name of Emacs library library.
`----

There can not be a precise file name for an abstraction...

(get-load-suffixes)
=> (".elc" ".elc.gz" ".el" ".el.gz") ;and sometimes ""

Unless there is a most bona fide of the library suffixe.
Or, some pigs are more equal than others.

> This is poorly worded but means that it will not only look for files
> of the form DIR/FILE.SUFFIX but also for DIR/FILE (i.e. it will add the
> empty string as a valid suffix).

A) It doesn't do that now.

B) If the empty string is a valid suffix then all strings are potentially valid
   library suffixes.

With regards A my patch and the newly modified version below address this.

With regards B, is this your intention here?. If so, I don't believe this a case
of poor wording. It is a situation where the user visible ``spec'' (i.e. the
docstring) says one thing but the function does something entirely different
(badly) b/c the empty string becomes the operative factor _not_ the value of
`load-suffixes'.

Regardless, you've ignored the second portion of the docs which negates _your_
interpretation above, and have neglected to explain or address my initial query:

 "Aren't these two statements mutually exclusive?"

,----
| Optional second arg NOSUFFIX non-nil means don't add suffixes `load-suffixes'
| to the specified name LIBRARY.
`----

According to the docs we have:

o If NOSUFFIX is nil - omit the suffix
o If NOSUFIX is non-nil don't add suffixes `load-suffixes'.

What other suffixes are there other than `load-suffixes'?

The docs don't explicitly mention that the values of `load-file-rep-suffixes',
and `get-load-suffixes' _also_ affect the return value.

load-suffixes
=> (".elc" ".el")

(locate-library "subr")
=> "{...}/emacs/lisp/subr.elc"

(locate-library "subr" t)
=> nil

Again, according to the docs the `t' arg should elide ".elc" and ".el"
suffixes. Still, this shouldn't cause locate-library to return nil, none the
less this is the value returned in lieu of empty string element from
`load-file-rep-suffixes'.

>> I don't think the docstring even reflects the intent of locate-library's
>> NOSUFFIX arg esp. as it doesn't appear to be _able_ to return a library name
>> sans extension when not called-interactively.
>
> Indeed, this arg only controls how the search is performed, not in which
> form the result will be returned.
>

Come on Stefan! Are you implying that (locate-library "subr" t) should return
non-nil regardless the second arg? It doesn't. If the search directs the
outcome of the result then it also controls the form returned.

Directing the search to, "not add suffixes `load-suffixes'" will not cause it to
search all but ".elc" and ".el", nor will it cause it to return the precise
library file name.

>> "When called from a program and NOSUFFIX is a boolean, string, or list of
>> strings, return LIBRARY's file-truename as if by `file-name-sans-extension'."
>
> That completely changes the meaning of this argument.

Only to the extent that:

a) The existing NOSUFFIX arg works as advertised. It doesn't, see item A above.

b) There is fixity w/re the meaning of the NOSUFFIX argument...

W/re to a and A above one can't break what is already broken.

  "He's only mostly dead." "She's only a 'lil bit pregnant"

Apropos b, you've already acknowledged that the meaning is poorly specified.
I don't understand how my patch can change the meaning of a poorly specified and
malfunctioning argument.

> Why don't you call file-name-sans-extension outside of locate-library instead,
> if you want that?
>
>        Stefan

Because a library is not a file.

Indeed, if I wanted to strip the suffix I would use `locate-file'. Which begs
the question, why can't one _add/filter_ the most appropriate extension to the
return value of locate-library if that is what is wanted?

This is the intention of my proposed patch.

I've attached a modified version of the original patch.

The existing change to the NOSUFFIX arg from the previous patch remains. This is
IMO a non-breaking semantic change.

In addition, I've added a new optional arg SHOW-COMPRESSED which allows
revealing whether the located library has the ".el[c]?.gz" extension. This arg
is applicable both as an interactive prefix arg and when called programatically.

The _ONLY_ potentially breaking change to the existing procedure I can find is
that where one supplies a non-nil argument for NOSUFFIX instead of returning
nil, it will now filter the suffix from the return result or any matching
library found. The benefit here being that it will now actually return
_something_ if there is a library-ish looking thing in the path.  This shouldn't
be a big deal esp. as the existing procedure just bails out...  albeit not
before first lying to me:

(locate-library "subr" t)
=> nil

Even though there _IS_ a "subr" library in the loadpath (maybe more than one).

Following are some more example test evaluations to give you an idea of what the
revised patch attached below is intended to accomplish:

;;; ==============================
;; These files were present in path when testing:
(directory-files "/home/MON/fnd-sbr" nil "s.*")
=> ("subr.el" "subr.el.gz" "subr.elc" "subr.elc.gz")

;; Return value from existing unpatched `locate-library':
(locate-library "subr" nil '("/home/MON/fnd-sbr"))
=> "/home/MON/fnd-sbr/subr.elc"

(locate-library "subr" "" '("/home/MON/fnd-sbr"))
=> nil ;You keep using that word. I do not think it means what you
think it means.

(locate-library "subr" t '("/home/MON/fnd-sbr/"))
=> nil  ;You make me feel so cheap and used.

;; Now with patched version and the new optional arg SHOW-COMPRESSED
(locate-library "subr" nil '("/home/MON/fnd-sbr"))
=> "/home/MON/fnd-sbr/subr.elc" ;Same as it ever was.

(locate-library "subr" t '("/home/MON/fnd-sbr"))
=> "/home/MON/fnd-sbr/subr" ;Hey, thats much better.

(locate-library "i-dont-exist" t '("/home/MON/fnd-sbr"))
=> nil ;At least you didn't lie to me. Maybe, we can still be friends?

(locate-library "subr" ".bad-ext" '("/home/MON/fnd-sbr"))
=> nil  ;Are you sure you've turned a new leaf?

(locate-library "subr" ".elc" '("/home/MON/fnd-sbr"))
=> "/home/MON/fnd-sbr/subr" ;OK, but could you be less vague?

(locate-library "subr" ".elc.gz" '("/home/MON/fnd-sbr"))
=> "/home/MON/fnd-sbr/subr" ;Apparently not.

(locate-library "subr" ".elc.gz" '("/home/MON/fnd-sbr") nil t)
=> "/home/MON/fnd-sbr/subr.elc.gz" ;So... you do grok Lempel-Ziv.

(locate-library "subr" '(".el.gz" ".elc.gz") '("/home/MON/fnd-sbr"))
=> "/home/MON/fnd-sbr/subr" ;But now which one did we match?

(locate-library "subr" '(".elc" ".elc.gz") '("/home/MON/fnd-sbr") nil t)
=> "/home/MON/fnd-sbr/subr" ;Was it most specific first?

(locate-library "subr" '(".elc.gz" ".elc") '("/home/MON/fnd-sbr"))
=>  "/home/MON/fnd-sbr/subr" ;Or, was it mostest specific firster morely?

(locate-library "subr" '(".elc.gz" ".elc") '("/home/MON/fnd-sbr") nil t)
=> "/home/MON/fnd-sbr/subr.elc.gz" ;Now we know she's a compressed lib.

;; Example of current  unpatched behavior:
(apply 'locate-library "subr" '(nil nil t))
=> "/usr/share/emacs/23.1.90/lisp/subr.elc" ;Same as it ever was.

;; Now with the newest patch.

;; In following two examples we supply the NOSUFIX arg as proof of concept that
;; NOPREFIX arg could find and filter the library file with suffix for each of
;; the file suffixes: .el, .elc, .el.gz, .elc.gz

;; Example of an interactive call;

(apply 'locate-library "subr" '(".el" nil t))
=> "/usr/share/emacs/23.1.90/lisp/subr"

(apply 'locate-library "subr" '(".el.gz" nil t))
=> "/usr/share/emacs/23.1.90/lisp/subr"

(apply 'locate-library "subr" '(".elc" nil t))
=> "/usr/share/emacs/23.1.90/lisp/subr"

(apply 'locate-library "subr" '(".elc.gz" nil t))
=> "/usr/share/emacs/23.1.90/lisp/subr"

;; Example of an interactive call with NOPREFIX as prefix arg
(apply 'locate-library "subr" '(t nil t))
=> "/usr/share/emacs/23.1.90/lisp/subr"

;; Example of an interactive call with SHOW-COMPRESSED as prefix arg.
(apply 'locate-library "subr" '(".el.gz" nil t 2))
=> "/usr/share/emacs/23.1.90/lisp/subr.el.gz"

;; Example2 of interactive call with SHOW-COMPRESSED as prefix arg.
(apply 'locate-library "subr" '(".elc.gz" nil t 2))
=> "/usr/share/emacs/23.1.90/lisp/subr.elc.gz" ;<- (assuming it exists)

;; Example3 of interactive call with SHOW-COMPRESSED as prefix arg.
(apply 'locate-library "subr" '(nil nil t 2))
=> "/usr/share/emacs/23.1.90/lisp/subr"

;; Example4 of interactive call with SHOW-COMPRESSED as prefix-arg.
;; This example shows that even where we force finding ".elc" we can't make it
;; return the library's file with a suffix.
(apply 'locate-library "subr" '(".elc" nil t 2))
=> "/usr/share/emacs/23.1.90/lisp/subr"

(let ((sfxs '(".bubba" ".el" ".elc" "" ".el.gz" ".elc.gz"))
      (in-paths '("/home/MON/fnd-sbr"))
      gthr-rslts
      tmp-rslts)
  (progn
    (push `(:booleans
            ,(dolist (l sfxs (setq show-libs (nreverse tmp-rslts)))
                     (push (if (locate-library "subr" l in-paths) t
nil) tmp-rslts)))
          gthr-rslts)
    (setq tmp-rslts nil)
    (push `(:paths-nocompress
            ,(dolist (l sfxs (setq show-libs (nreverse tmp-rslts)))
                     (push (locate-library "subr" l in-paths) tmp-rslts)))
          gthr-rslts)
    (setq tmp-rslts nil)
    (push `(:paths-w-compress
            ,(dolist (l sfxs (setq show-libs (nreverse tmp-rslts)))
                     (push (locate-library "subr" l in-paths nil t) tmp-rslts)))
          gthr-rslts)
    (setq gthr-rslts (nreverse gthr-rslts))))

;: :NOTE When empty string is provided to NOSUFFIX returns nil.
;;       Nothing new about that.

=> ((:booleans (nil t t nil t t))
    (:paths-nocompress
     (nil "/home/MON/fnd-sbr/subr" "/home/MON/fnd-sbr/subr"
      nil "/home/MON/fnd-sbr/subr" "/home/MON/fnd-sbr/subr"))
    (:paths-w-compress
     (nil "/home/MON/fnd-sbr/subr" "/home/MON/fnd-sbr/subr"
      nil "/home/MON/fnd-sbr/subr.el.gz" "/home/MON/fnd-sbr/subr.elc.gz")))

;; This last example illustrates that as we know the argument(s) to NOSUFFIX one
;; can now use `locate-library' to actually find a _precise_ library
filename(s).

;;; ==============================

--- subr.el~99304~	2010-01-19 15:34:00.000000000 -0500
+++ subr.el	2010-01-21 16:39:46.000000000 -0500
@@ -1564,7 +1564,7 @@
 	(setq files (cdr files)))
       file)))

-(defun locate-library (library &optional nosuffix path interactive-call)
+(defun locate-library (library &optional nosuffix path
interactive-call show-compressed)
   "Show the precise file name of Emacs library LIBRARY.
 LIBRARY should be a relative file name of the library, a string.
 It can omit the suffix (a.k.a. file-name extension) if NOSUFFIX is
@@ -1585,17 +1585,37 @@
                                        'locate-file-completion-table
                                        load-path (get-load-suffixes)))
 		     nil nil
-		     t))
-  (let ((file (locate-file library
-			   (or path load-path)
-			   (append (unless nosuffix (get-load-suffixes))
-				   load-file-rep-suffixes))))
+		     t (if current-prefix-arg t)))
+  (let* ((lfrs (remove "" load-file-rep-suffixes))
+         (sfx  (cond ((booleanp nosuffix)
+                      (delete-dups (append lfrs (get-load-suffixes))))
+                     ((and nosuffix (stringp nosuffix))
+                      `(,nosuffix
+                        ,@(mapcar #'(lambda (z)
+                                      (concat nosuffix z))
+                                  lfrs)))
+                     ((consp nosuffix)
+                      (delete-dups (append nosuffix lfrs)))
+                     (t (append  lfrs(get-load-suffixes)))))
+         (file (locate-file library
+                            (or path load-path)
+                            sfx)))
+    (when (and file (or nosuffix (and show-compressed (not nosuffix))))
+      (setq file (file-truename file))
+      (let ((smp-gz (string-match-p ".*.gz" file)))
+        (setq file (concat (file-name-directory file)
+                           (cond ((or (not show-compressed)
+                                      (and show-compressed (not smp-gz)))
+                                  (file-name-sans-extension
+                                   (file-name-nondirectory
+                                    (file-name-sans-extension file))))
+                                 ((or (and show-compressed smp-gz) t)
+                                  (file-name-nondirectory file)))))))
     (if interactive-call
-	(if file
-	    (message "Library is file %s" (abbreviate-file-name file))
-	  (message "No library %s in search path" library)))
+        (if file
+            (message "Library is file %s" (abbreviate-file-name file))
+            (message "No library %s in search path" library)))
     file))
-
 \f
 ;;;; Specifying things to do later.

[-- Attachment #2: subr.el.diff2 --]
[-- Type: application/octet-stream, Size: 2665 bytes --]

--- subr.el~99304~	2010-01-19 15:34:00.000000000 -0500
+++ subr.el	2010-01-21 16:39:46.000000000 -0500
@@ -1564,7 +1564,7 @@
 	(setq files (cdr files)))
       file)))
 
-(defun locate-library (library &optional nosuffix path interactive-call)
+(defun locate-library (library &optional nosuffix path interactive-call show-compressed)
   "Show the precise file name of Emacs library LIBRARY.
 LIBRARY should be a relative file name of the library, a string.
 It can omit the suffix (a.k.a. file-name extension) if NOSUFFIX is
@@ -1585,17 +1585,37 @@
                                        'locate-file-completion-table
                                        load-path (get-load-suffixes)))
 		     nil nil
-		     t))
-  (let ((file (locate-file library
-			   (or path load-path)
-			   (append (unless nosuffix (get-load-suffixes))
-				   load-file-rep-suffixes))))
+		     t (if current-prefix-arg t)))
+  (let* ((lfrs (remove "" load-file-rep-suffixes))
+         (sfx  (cond ((booleanp nosuffix)
+                      (delete-dups (append lfrs (get-load-suffixes))))
+                     ((and nosuffix (stringp nosuffix))
+                      `(,nosuffix 
+                        ,@(mapcar #'(lambda (z)
+                                      (concat nosuffix z))
+                                  lfrs)))
+                     ((consp nosuffix)
+                      (delete-dups (append nosuffix lfrs)))
+                     (t (append  lfrs(get-load-suffixes)))))
+         (file (locate-file library
+                            (or path load-path)
+                            sfx)))
+    (when (and file (or nosuffix (and show-compressed (not nosuffix))))
+      (setq file (file-truename file))
+      (let ((smp-gz (string-match-p ".*.gz" file)))
+        (setq file (concat (file-name-directory file)
+                           (cond ((or (not show-compressed)
+                                      (and show-compressed (not smp-gz)))
+                                  (file-name-sans-extension
+                                   (file-name-nondirectory 
+                                    (file-name-sans-extension file))))
+                                 ((or (and show-compressed smp-gz) t)
+                                  (file-name-nondirectory file)))))))
     (if interactive-call
-	(if file
-	    (message "Library is file %s" (abbreviate-file-name file))
-	  (message "No library %s in search path" library)))
+        (if file
+            (message "Library is file %s" (abbreviate-file-name file))
+            (message "No library %s in search path" library)))
     file))
-
 \f
 ;;;; Specifying things to do later.
 

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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-21 23:58   ` MON KEY
@ 2010-01-22 15:18     ` Stefan Monnier
  2010-01-23  2:10       ` MON KEY
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2010-01-22 15:18 UTC (permalink / raw)
  To: MON KEY; +Cc: emacs-devel

>> This is poorly worded but means that it will not only look for files
>> of the form DIR/FILE.SUFFIX but also for DIR/FILE (i.e. it will add the
>> empty string as a valid suffix).

> A) It doesn't do that now.

What makes you think so?

> B) If the empty string is a valid suffix then all strings are
> potentially valid library suffixes.

What makes you think so?

> Regardless, you've ignored the second portion of the docs which
> negates _your_ interpretation above, and have neglected to explain or
> address my initial query:

>  "Aren't these two statements mutually exclusive?"

I did explain it, tho obvious you didn't understand it.

> o If NOSUFFIX is nil - omit the suffix

No: if NOSUFFIX is nil, also include the empty suffix.

> o If NOSUFIX is non-nil don't add suffixes `load-suffixes'.
> What other suffixes are there other than `load-suffixes'?

The empty suffix.

> The docs don't explicitly mention that the values of `load-file-rep-suffixes',
> and `get-load-suffixes' _also_ affect the return value.

> load-suffixes
> => (".elc" ".el")

> (locate-library "subr")
> => "{...}/emacs/lisp/subr.elc"

> (locate-library "subr" t)
> => nil

> Again, according to the docs the `t' arg should elide ".elc" and ".el"
> suffixes.

Again, no, because this argument describes which extensions might be
added to the provided string in order to find a file name.  None of the
file name's suffixes are ever removed by locate-library.

[Stopped reading at this point, sorry]


        Stefan




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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-22 15:18     ` Stefan Monnier
@ 2010-01-23  2:10       ` MON KEY
  2010-01-23 11:23         ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: MON KEY @ 2010-01-23  2:10 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Fri, Jan 22, 2010 at 10:18 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>>> This is poorly worded but means that it will not only look for files
>>> of the form DIR/FILE.SUFFIX but also for DIR/FILE (i.e. it will add the
>>> empty string as a valid suffix).
>
>> A) It doesn't do that now.
>
> What makes you think so?

Assume I have the files subr, subr.el, and subr.gz in the directory:
/home/mon/fnd-sbr

(locate-library "subr" t '("/home/mon/fnd-sbr"))

That is, I ask locate-library:

``Please find me a library "subr", and while your doing this don't add the
  load-suffixes ".elc" ".el" to "subr", but _do_ match files with the name
  "subr""" if you happen to see those''.

IOW find me anything named "subr" or anything named "subr""".

So, locate-library returns:
=> /home/mon/fnd-sbr/subr

Now, assume I have only subr.el and subr.gz in the same directory.

I make the same request:
(locate-library "subr" t '("/home/mon/fnd-sbr"))

locate-library returns
=> "/home/mon/fnd-sbr/subr.gz"

Now, kindly point out to me the empty string at the end of subr?

Now, assume I have only of subr.el.gz in same directory?
(locate-library "subr" t '("/home/mon/fnd-sbr"))
=> nil

What is the difference between subr.gz and subr.el.gz?

The difference is due to `load-file-rep-suffixes' matching `".gz"'.

>
> I did explain it, tho obvious you didn't understand it.

I understood well enough how you explained it, I just don't buy it.

>
> Again, no, because this argument describes which extensions might be
> added to the provided string in order to find a file name.  None of the
> file name's suffixes are ever removed by locate-library.

Except ".el.gz" right?

>
> [Stopped reading at this point, sorry]

This is unfortunate.
Maybe you can try the patch one day when your not so busy, or the next
time your rootin' through the comments in files like ffap.el e.g. its
`ffap-locate-file'...

>
>        Stefan

/s_P\




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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-23  2:10       ` MON KEY
@ 2010-01-23 11:23         ` Stefan Monnier
  2010-01-24  1:39           ` MON KEY
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2010-01-23 11:23 UTC (permalink / raw)
  To: MON KEY; +Cc: emacs-devel

> I make the same request:
> (locate-library "subr" t '("/home/mon/fnd-sbr"))

> locate-library returns
> => "/home/mon/fnd-sbr/subr.gz"

Thanks!  Yes, this is a good example of a problematic case.  I wish you
had started with it.  Indeed, the docstring would need adjustment for
it.  Not sure how best to do it.  Basically the compression extensions
like ".gz" are treated as "non-suffixes".  Or maybe the code should be
changed to not add the compression suffixes in this case.  I can't
remember enough of why the code is doing it now: maybe it's simple
accidental consequence of the implementation, or maybe there's an actual
use case for which it matters.

>> Again, no, because this argument describes which extensions might be
>> added to the provided string in order to find a file name.  None of the
>> file name's suffixes are ever removed by locate-library.

> Except ".el.gz" right?

Again, please give me a relevant example.


        Stefan




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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-23 11:23         ` Stefan Monnier
@ 2010-01-24  1:39           ` MON KEY
  2010-01-25  3:23             ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: MON KEY @ 2010-01-24  1:39 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Sat, Jan 23, 2010 at 6:23 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> I make the same request:
>> (locate-library "subr" t '("/home/mon/fnd-sbr"))
>
>> locate-library returns
>> => "/home/mon/fnd-sbr/subr.gz"
>
> Thanks!  Yes, this is a good example of a problematic case.  I wish you
> had started with it.

Your welcome.  I'll jump out of sequence this time lest you hit ye 'olde wall of
verbosity too soon. ;)

>
>> Except ".el.gz" right?
>
> Again, please give me a relevant example.
>

As per the examples provided above:

,----
| Now, assume I have only subr.el and subr.gz in the same directory.
|
| locate-library returns
| => "/home/mon/fnd-sbr/subr.gz"
|
| {...}
|
| Now, assume I have only of subr.el.gz in same directory?
| (locate-library "subr" t '("/home/mon/fnd-sbr"))
| => nil
`----

Where `locate-library' returns with "subr.gz" in the former it does not return
with "subr.el.gz" in the later.  As both are relevant file-names of "subr", and
as in other less extreme corner cases either of these might return, it is not
unreasonable to assume that in the latter example above the ".el.gz" suffix has
been pathologically ``removed'' - IOW, the file is there, it is a rationale
return value, yet we don't get to see it.

> Indeed, the docstring would need adjustment for
> it.  Not sure how best to do it.

The cheap way would be to adjust docs for both `locate-library' and
`load-library' by indicating that the default suffixes are:

 (".elc" ".elc.gz" ".el" ".el.gz" "" ".gz")

e.g.:  (append (get-load-suffixes) load-file-rep-suffixes)
		
Except when NOSUFFIX is non-nil, in which case the default suffixes are:

 ("" ".gz")

Knock yourself explaining that empty string after 2.5 double negatives :P

You could punt as with `load-library's:

,----
| See Info node `(emacs)Lisp Libraries' for more details.
`----

Or, do as with `locate-file's:

,----
| If suffixes is nil, it is equivalent to '("").
`----

IMO, the full suite of docs for the "lo.*-\\(file\\|library\\)" fncns and vars
are suspect though b/c they conflate filenames with libraries.

>  Basically the compression extensions like ".gz" are treated as
> "non-suffixes".

In this case, the default compression extension ".gz" is the only extension.

> Or maybe the code should be changed to not add the compression suffixes in
> this case.

Assuming the compression suffix can be found correctly in all cases there are
more situations where compression suffixe are wanted than not. However, this
is not the case now.  And, so long as Emacs can be built with compressed
libraries, those so suffixed _will_ be sought. Hence my proposal(s):

o That NOSUFFIX be allowed to return a non-suffixed library name-string
  conditioned on the type of argument given (which buys you bckw-compat).

o In lieu of a potentially breaking change above, the addition of an optional
  SHOW-COMPRESSED arg which conditionally reveals the compression suffix if
  found.

> I can't remember enough of why the code is doing it now: maybe it's simple
> accidental consequence of the implementation, or maybe there's an actual use
> case for which it matters.

I'm not sure of which use case you are referring.

My impression is that the use cases don't arise that often (or aren't reported)
because users have avoided using `locate-library' in these situations.

Whether this _matters_ is prob. a maintenance consideration w/re code
duplication vs. backwards compatibility. Again, see my quip about ffap's
`ffap-locate-file' as one case in point...

FWIW this is the (un)use(able) case that piqued my interest:

(kill-new (locate-library "subr"))

Stripping the extension is not the issue. I asked to kill a library namestring.

>
>        Stefan
>

/s_P\




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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-24  1:39           ` MON KEY
@ 2010-01-25  3:23             ` Stefan Monnier
  2010-01-27  4:25               ` MON KEY
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2010-01-25  3:23 UTC (permalink / raw)
  To: MON KEY; +Cc: emacs-devel

>>> Except ".el.gz" right?
>> Again, please give me a relevant example.
> As per the examples provided above:

> ,----
> | Now, assume I have only subr.el and subr.gz in the same directory.
> |
> | locate-library returns
> | => "/home/mon/fnd-sbr/subr.gz"
> |
> | {...}
> |
> | Now, assume I have only of subr.el.gz in same directory?
> | (locate-library "subr" t '("/home/mon/fnd-sbr"))
> | => nil
> `----

This is not removing ".el.gz" from the return value.  This is removing
it from the search.

> Assuming the compression suffix can be found correctly in all cases
> there are more situations where compression suffixe are wanted than
> not.  However, this is not the case now.  And, so long as Emacs can be
> built with compressed libraries, those so suffixed _will_ be
> sought. Hence my proposal(s):

> o That NOSUFFIX be allowed to return a non-suffixed library name-string
>   conditioned on the type of argument given (which buys you bckw-compat).

I still do not know what this would be used for.  Could you explain the
actual use case you're thinking of?

>> I can't remember enough of why the code is doing it now: maybe it's
>> simple accidental consequence of the implementation, or maybe there's
>> an actual use case for which it matters.
> I'm not sure of which use case you are referring.

As mentioned, I don't know them.  But they'd look like a situation where
it would be problematic if (locate-library "foo" t) did not find
"/bar/foo.gz".

> My impression is that the use cases don't arise that often (or aren't
> reported) because users have avoided using `locate-library' in
> these situations.

Coulod be.  Couldn't blame them.  Now that locate-file is available, I'd
recommend they use that instead.

> FWIW this is the (un)use(able) case that piqued my interest:
> (kill-new (locate-library "subr"))

What does this use case show?  What's the problem with it?

> Stripping the extension is not the issue. I asked to kill
> a library namestring.

What is "a library namestring"?


        Stefan




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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-25  3:23             ` Stefan Monnier
@ 2010-01-27  4:25               ` MON KEY
  2010-01-27 14:55                 ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: MON KEY @ 2010-01-27  4:25 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Hi Stefan,

On Sun, Jan 24, 2010 at 10:23 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> This is not removing ".el.gz" from the return value.  This is removing
> it from the search.

You fist indicated that `locate-library' doesn't remove extensions.
Now you acknowledge that it does.

The locus of the removal is irrelevant in lieu of the fact that it is getting
removed from the return value and shouldn't be.

I pass a permissible non-nil value for NOSUFFIX and I get a non-sensical result.
This is an error.

> I still do not know what this would be used for.  Could you explain the
> actual use case you're thinking of?

Assume I have the file "library.el.gz" in the directory "/home/mon/fnd-lib"
Right if i ask for the location of "library" I get:

 (locate-library "libary" t '("/home/mon/fnd-lib"))
 => nil

It would be really great to ask with:
 (locate-library "libary" t '("/home/mon/fnd-lib") t)

and get:
 => "/home/mon/fnd-lib/library.el.gz"

See my earlier posts (presumably as yet unread) for examples of `mapping' loops
which might take advantage of the proposed behavior.

Hint, look for the lisp with the keys:
 `:booleans', `:paths-w-compress', `:paths-nocompress'

> As mentioned, I don't know them.  But they'd look like a situation where
> it would be problematic if (locate-library "foo" t) did not find
> "/bar/foo.gz".

Indeed.

> Coulod be.  Couldn't blame them.  Now that locate-file is available, I'd
> recommend they use that instead.

A file is not a library.

Which library file shall I ask to locate when I don't yet know which
library file
I am looking for?

IOW, why bother locating when you already know with specificity what
your looking for?

> What does this use case show?

I asked to kill a library, I maybe kill a file-name or maybe I kill a nil. Where
I do kill a file-name it is unspecified which file-name I killed.

> What's the problem with it?

The problem is that at best I kill an unspecific file name.

> Stripping the extension is not the issue. I asked to kill
> a library namestring.

> What is "a library namestring"?

A string that names the location of a library up to but not including that
library's extension.

IOW what you _should_ get when you want to know where a library lives but don't
want a filename.

Think Common Lisp's `directory-namestring', `enough-namestring',
`file-namestring', `host-namestring', `parse-namestring', `namestring', etc.

> Stefan

/s_P\




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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-27  4:25               ` MON KEY
@ 2010-01-27 14:55                 ` Stefan Monnier
  2010-01-28  1:09                   ` MON KEY
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2010-01-27 14:55 UTC (permalink / raw)
  To: MON KEY; +Cc: emacs-devel

>> This is not removing ".el.gz" from the return value.  This is removing
>> it from the search.
> You fist indicated that `locate-library' doesn't remove extensions.
> Now you acknowledge that it does.

I see that my explanation still left room for confusion:
1- «removing ".el.gz" from the return value» means that instead of
   returning "/bar/foo.el.gz" it would return "/bar/foo".
2- «removing it from the search» means that locate-library will not look
   for files that end in ".el.gz" at all.

I hope this is more clear now.  These two are completely different.
NOSUFFIX does what the case (2) does, not what the case (1) does.

>> I still do not know what this would be used for.  Could you explain the
>> actual use case you're thinking of?

> Assume I have the file "library.el.gz" in the directory "/home/mon/fnd-lib"
> Right if i ask for the location of "library" I get:

>  (locate-library "libary" t '("/home/mon/fnd-lib"))
>  => nil

> It would be really great to ask with:
>  (locate-library "libary" t '("/home/mon/fnd-lib") t)

> and get:
>  => "/home/mon/fnd-lib/library.el.gz"

I don't follow you.  If you want that, then why do you specify a non-nil
value for NOSUFFIX??

>> Could be.  Couldn't blame them.  Now that locate-file is available, I'd
>> recommend they use that instead.
> A file is not a library.

That's irrelevant.  `locate-library' returns a file name, not a library name.

>>> (kill-new (locate-library "subr"))
>> What does this use case show?
> I asked to kill a library,

No, you didn't.  Check the docstring of locate-library:

  "Show the precise file name of Emacs library LIBRARY."

I.e. it returns a file name, so you asked to "kill" a file name.

> I maybe kill a file-name or maybe I kill a nil.  Where I do kill
> a file-name it is unspecified which file-name I killed.

I have no idea what kind of "specification" you'd expect other than the
one you currently get from locate-library's docstring.

>> What's the problem with it?
> The problem is that at best I kill an unspecific file name.

Then don't do that.  Seen from here, it looks like you're using
locate-library to do something else than what it does; although I'm not
100% positive it's the case because I don't really know what it is you
want (kill-new (locate-library "subr")) to do.

>> Stripping the extension is not the issue. I asked to kill
>> a library namestring.
>> What is "a library namestring"?
> A string that names the location of a library up to but not including that
> library's extension.

Ah, now I see.  This notion of "library name stripped of its extension"
is not one that Emacs uses much, AFAIK.

Why do you want it without the extension?
Depending on this question, we may be able to determine things like
whether you'd like (your-locate-library "foo.el" t) to return "/bar/foo"
or "/bar/foo.el".

> IOW what you _should_ get when you want to know where a library lives
> but don't want a filename.

Since locate-library returns a filename and you "don't want a filename",
it's no wonder you don't like the return value of locate-library.


        Stefan




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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-27 14:55                 ` Stefan Monnier
@ 2010-01-28  1:09                   ` MON KEY
  2010-01-28  2:46                     ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: MON KEY @ 2010-01-28  1:09 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Wed, Jan 27, 2010 at 9:55 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>
> I see that my explanation still left room for confusion:

Stefan, I'm not the dimmest bulb in the drawer; This is your third attempt at
rephrasing the existing functionality.

>
> I hope this is more clear now.  These two are completely different.
> NOSUFFIX does what the case (2) does, not what the case (1) does.

Thank you for this explanation.

Following is a rhetorical question; but if it helps you to see the problem then
by all means feel free to continue with the enumeratiation. Why won't it return
for "/my/bar/foo.el" either but it will return for "/my/bar/foo.gz"? e.g.

 (locate-library "foo" t '("/my/bar"))

>> It would be really great to ask with:
>>  (locate-library "libary" t '("/home/mon/fnd-lib") t)
>
>> and get:
>>  => "/home/mon/fnd-lib/library.el.gz"
>
> I don't follow you.  If you want that, then why do you specify a non-nil
> value for NOSUFFIX??

Look closely. The fourth arg of the second example is using the proposed
SHOW-COMPRESSED. Which says, "Show me the file name sans extension unless
library name is a compressed file in which case let me know by showing me the
extension.

>
> That's irrelevant.  `locate-library' returns a file name, not a library name.
>

Not entirely irrelevant.  What is a library name then?

If there is a distinction between a library and a file it is not clear.

How exactly should one specify a library name for the LIBRARY arg to
locate-library if this is not the same object(s) as a file name?

Please understand, my intention is not to be pedantic. It is important
that if there is a distinction between the two that it be specified.

>> I asked to kill a library,
>
> No, you didn't.  Check the docstring of locate-library:
>
>  "Show the precise file name of Emacs library LIBRARY."
>
> I.e. it returns a file name, so you asked to "kill" a file name.
>

Hrmmm. Precisely what is, "the precise file name of an Emacs library"?

>
> I have no idea what kind of "specification" you'd expect other than the
> one you currently get from locate-library's docstring.
>

Agreed. Hence the conundrum.

>
> Then don't do that.
> Seen from here, it looks like you're using
> locate-library to do something else than what it does;

Indeed. It is obviously pathological (as was indicated in the orignial context).

> although I'm not 100% positive it's the case because I don't really know what
> it is you want (kill-new (locate-library "subr")) to do.
>

This was provided as an example where I found the expected behavior surprising.

A better example use-case for the proposed patch might be where one would like
to generate a list from which one could inform/extend/override
`emacs-lisp-file-regexp', `byte-compile-dest-file', `declare-function',
`check-declare-directory', `byte-compiler-base-file-name', etc. to
select/operate on a library per case based conditionals of the list elements.

>
> Ah, now I see.  This notion of "library name stripped of its extension"
> is not one that Emacs uses much, AFAIK.

You say this is an esoteric feature but if it does indeed exist please tell me
its name maybe I can use it to scratch this itch...

It is a notion used all the time just from the other direction, i.e. by
stripping instead of adding it back on. Likewise, it is a notion which will be
required more with increased package support and distributed/versioned code and
is IMHO a likely eventuality required in each arena. This NOSUFFIX problem is
compounded when there are duplicate library's across multiple dir
hierarchies. FWIW you have a fully fleshed abstraction for objects
now... This is
exactly the type of feature they are great at abstracting.

>
> Why do you want it without the extension?
>

Why wouldn't I? :)

I do do want the extension, but I would prefer to set the conditions upon which
the extensions are made available.

> Depending on this question, we may be able to determine things like
> whether you'd like (your-locate-library "foo.el" t) to return "/bar/foo"
> or "/bar/foo.el".

Exactly.

>
> Since locate-library returns a filename and you "don't want a filename",
> it's no wonder you don't like the return value of locate-library.
>

Don't twist me off axis.
What I don't want is a file name where a library name is requested.

To the extent that `locate-library' is essentially obsoleted by `locate-file'
what is the big deal changing it ;-)

>
>        Stefan

/s_P\




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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-28  1:09                   ` MON KEY
@ 2010-01-28  2:46                     ` Stefan Monnier
  2010-01-29  2:55                       ` MON KEY
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2010-01-28  2:46 UTC (permalink / raw)
  To: MON KEY; +Cc: emacs-devel

>>> It would be really great to ask with:
>>> (locate-library "libary" t '("/home/mon/fnd-lib") t)
>> 
>>> and get:
>>> => "/home/mon/fnd-lib/library.el.gz"
>> 
>> I don't follow you.  If you want that, then why do you specify a non-nil
>> value for NOSUFFIX??

> Look closely. The fourth arg of the second example is using the proposed
> SHOW-COMPRESSED.

That was definitely too subtle for me: Emacs-CVS's locate-library
already has a 4th argument, used for a completely different purpose.

> Which says, "Show me the file name sans extension unless library name
> is a compressed file in which case let me know by showing me
> the extension.

This said, I'm really lost as to why/when you'd want this kind of behavior.

> How exactly should one specify a library name for the LIBRARY arg to
> locate-library if this is not the same object(s) as a file name?

The argument provided to locate-library is the library name, so the
difference is pretty clear: "subr" is a library name and "/bar/subr.el"
is a file name.

>>> I asked to kill a library,
>> No, you didn't.  Check the docstring of locate-library:
>> "Show the precise file name of Emacs library LIBRARY."
>> I.e. it returns a file name, so you asked to "kill" a file name.
> Hrmmm. Precisely what is, "the precise file name of an Emacs library"?

You lost me here.

>> I have no idea what kind of "specification" you'd expect other than the
>> one you currently get from locate-library's docstring.
> Agreed. Hence the conundrum.

Even more lost.

>> although I'm not 100% positive it's the case because I don't really
>> know what it is you want (kill-new (locate-library "subr")) to do.

> This was provided as an example where I found the expected
> behavior surprising.

Unless you explain what other behavior you expect, that doesn't help us.

> A better example use-case for the proposed patch might be where one would
> like to generate a list from which one could inform/extend/override
> `emacs-lisp-file-regexp', `byte-compile-dest-file', `declare-function',
> `check-declare-directory', `byte-compiler-base-file-name', etc. to
> select/operate on a library per case based conditionals of the list elements.

I have no idea how you suggested change would help do any of this.

>> Depending on this question, we may be able to determine things like
>> whether you'd like (your-locate-library "foo.el" t) to return "/bar/foo"
>> or "/bar/foo.el".
> Exactly.

Now that was helpful.  I'm just wasting my time here.


        Stefan




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

* Re: locate-library, the NOSUFFIX arg and a [PATCH]
  2010-01-28  2:46                     ` Stefan Monnier
@ 2010-01-29  2:55                       ` MON KEY
  0 siblings, 0 replies; 13+ messages in thread
From: MON KEY @ 2010-01-29  2:55 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

On Wed, Jan 27, 2010 at 9:46 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>
>>> Depending on this question, we may be able to determine things like
>>> whether you'd like (your-locate-library "foo.el" t) to return "/bar/foo"
>>> or "/bar/foo.el".
>> Exactly.
>
> Now that was helpful.  I'm just wasting my time here.
>

Indeed, it appears you are wasting time.

Your question contained the answer(s) I have already given.
These are the determinations sought. What else would you have me reply???

I've gone out of my way to identify the perceived problem, along with my
expectations, as I understand them.

I've included two patches (now three) to transparently identify with unambiguous
Elisp both the perceived problem and a perceived solution. I've indicated
multiple times that the proposed solution needn't be breaking.

I'm including some elisp source which:

a) A function which does to not alter the semantics of NOSUFFIX and uses an
   external functional call to tdo the work.

b) A revised version of the previously proposed patch that does alter the
   semantics of NOSUFFIX. This newest revision fixes a bug where the return
   value of the altered NOSUFFIX semantic was orthogonal to the existing
   unmodified locate-library. With this bug fixed the revised version should be
   transparent to the user.

I've written adequate documentation for b) which clarifies the existing
behavior of locate-library and illustrates the proposed semantics of the
proposed patch.

I won't bother wasting your time your with those details unless you should find
them useful. Let me know and I'll forward them along.

Following is the elisp. Knock yourself out...

;;; ==============================
;;; :UNMODIFIED `locate-library'. Evaluate me later to get back to Kansas.
(defun locate-library (library &optional nosuffix path interactive-call)
  (interactive (list (completing-read "Locate library: "
				      (apply-partially
                                       'locate-file-completion-table
                                       load-path (get-load-suffixes)))
		     nil nil
		     t))
  (let ((file (locate-file library
			   (or path load-path)
			   (append (unless nosuffix (get-load-suffixes))
				   load-file-rep-suffixes))))
    (if interactive-call
	(if file
	    (message "Library is file %s" (abbreviate-file-name file))
	  (message "No library %s in search path" library)))
    file))

;;; ==============================
;;; :MODIFIED `locate-library'.
;;; NOSUFFIX with alternative semantics and new arg SHOW-COMPRESSED.
;;; Revised version of previous patch(s).
;;; <Timestamp: #{2010-01-28T21:45:20-05:00Z}#{10044} - by MON>
(defun locate-library (library &optional nosuffix path
interactive-call show-compressed)
  (interactive (list (completing-read "Locate library: "
				      (apply-partially
                                       'locate-file-completion-table
                                       load-path (get-load-suffixes)))
		     nil nil
		     t (if current-prefix-arg t)))
  (let* ((lfrs (remove "" load-file-rep-suffixes))
         (gls (sort (get-load-suffixes) #'(lambda (l1 l2) (< (length
l1) (length l2)))))
         (sfx  (cond ((booleanp nosuffix)
                      (delete-dups (append gls lfrs)))
                     ((and nosuffix (stringp nosuffix))
                      `(,nosuffix
                        ,@(mapcar #'(lambda (z)
                                      (concat nosuffix z))
                                  lfrs)))
                     ((consp nosuffix) (delete-dups (append nosuffix lfrs)))
                     (t (append gls lfrs))))
         (cln-lib (if (string= (file-name-sans-extension library) library)
                      library
                      (let ((lib-cln library))
                        (mapc #'(lambda (rgx)
                                  (let ((ms (string-match-p rgx lib-cln)))
                                    (when ms (setq lib-cln (substring
lib-cln 0 ms)))))
                              '("\\(\\(\\.elc\\|\\.el\\)\\.gz\\)" ; ->
1 .el[c].gz
                                "\\(\\.elc\\|\\.el\\)"            ; ->
1 .elc | .el
                                "\\(\\.gz\\)"))                   ; -> 1 .gz
                        lib-cln)))
         (file (locate-file cln-lib (or path load-path) sfx)))
    (when (and file (or nosuffix (and show-compressed (not nosuffix))))
      (setq file (file-truename file))
      (let ((smp-gz ;;(string-match-p ".*.gz" file)))
             (string-match-p ".*\\.gz" file)))
        (setq file (concat (file-name-directory file)
                           (cond ((or (not show-compressed)
                                      (and show-compressed (not smp-gz)))
                                  (file-name-sans-extension
                                   (file-name-nondirectory
                                    (file-name-sans-extension file))))
                                 ((or (and show-compressed smp-gz) t)
                                  (file-name-nondirectory file)))))))
    (if interactive-call
        (if file
            (message "Library is file %s" (abbreviate-file-name file))
            (message "No library %s in search path" library)))
    file))

;;; ==============================
;;; :MODIFIED `locate-library'. Semantics of NOSUFFIX untouched.
;;; Additional arg STRIPSUFFIX when non-nil evaluates `locate-library-rmv-sfx'
;;; <Timestamp: #{2010-01-28T21:45:33-05:00Z}#{10044} - by MON>
(defun locate-library (library &optional nosuffix path
interactive-call stripsuffix)
  (interactive (list (completing-read "Locate library: "
				      (apply-partially
                                       'locate-file-completion-table
                                       load-path (get-load-suffixes)))
		     nil nil
		     t))
  (let ((file
         (if (and (not nosuffix) stripsuffix)
             (locate-library-rmv-sfx library path stripsuffix)
             (locate-file library
                          (or path load-path)
                          (append (unless nosuffix (get-load-suffixes))
                                  load-file-rep-suffixes)))))
    (if interactive-call
	(if file
	    (message "Library is file %s" (abbreviate-file-name file))
            (message "No library %s in search path" library)))
    file))
;;;
;;; Assume the following files are present in "/home/MON/loc-libr":
;;; "subr" "subr.bubba" "subr.bubba.gz" "subr.el" "subr.el.gz"
"subr.elc.gz" "subr.el~"
;;;
;;; :TEST-ME (locate-library "subr.el" nil '("/home/MON/loc-libr") nil
 '((".bubba" ".el" ".el.gz") . t))
;;;          => "/home/MON/loc-libr/subr.el.gz"
;;;
;;; :TEST-ME (locate-library "subr.el" nil '("/home/MON/loc-libr") nil
 '((".bubba" ".el" ".el.gz") . nil))
;;;           => "/home/MON/loc-libr/subr"
;;;
;;; :TEST-ME (locate-library "subr.el" t)
;;;          => "/home/MON/loc-libr/subr"
;;;

;;; ==============================
;;; :NOTE For backwards compat we strip the extension in the `cln-lib' var.
;;;       Not using `file-name-extension'/`file-name-extension' b/c:
;;;       (file-name-extension "subr.elc.gz") => "gz"
;;;       (file-name-sans-extension "subr.elc.gz") => "subr.elc"
;;;
;;; <Timestamp: #{2010-01-28T19:31:03-05:00Z}#{10044} - by MON>
(defun locate-library-rmv-sfx (library locpath rmvsfx-shw-gz)
  "LIBRARY is a string naming the library to locate.
LOCPATH is a list of paths in which to locate LIBRARY
RMVSFX-SHW-GZ is a dotted list with the form:\n
 '\(\(\".el\" \".el.gz\" \".bubba\"\) . t\)\"
The first element is a list of suffix names which LIBRARY might have.
When present the second element is a boolean, t or nil. If t when LIBRARY is
found in PATH with a suffix matching the first element of RMVSFX-SHW-GZ and that
element represents a compressed file extension show the file name with the
extension."
  (let* ((gls (sort (get-load-suffixes) #'(lambda (l1 l2) (< (length
l1) (length l2)))))
         (lfrs   (remove "" load-file-rep-suffixes))
         (cln-lib (if (string= (file-name-sans-extension library) library)
                      library
                      (let ((lib-cln library))
                        (mapc #'(lambda (rgx)
                                  (let ((ms (string-match-p rgx lib-cln)))
                                    (when ms (setq lib-cln (substring
lib-cln 0 ms)))))
                              '("\\(\\(\\.elc\\|\\.el\\)\\.gz\\)" ; ->
1 .el[c].gz
                                "\\(\\.elc\\|\\.el\\)" ; -> 1 .elc | .el
                                "\\(\\.gz\\)"))        ; -> 1 .gz
                        lib-cln)))
         ;; :NOTE arg
         (shw-gz  (cdr rmvsfx-shw-gz))  ; => t
         (rmvsfx (car rmvsfx-shw-gz))   ; => (".el" ".el.gz" ".bubba")
         (sfx  (cond ((booleanp rmvsfx) (delete-dups (append gls lfrs)))
                     ((and rmvsfx (stringp rmvsfx))
                      `(,rmvsfx ,@(mapcar #'(lambda (z) (concat rmvsfx
z)) lfrs)))
                     ((consp rmvsfx) (delete-dups (append rmvsfx lfrs)))
                     ;; (t (append  gls lfrs)))) ;; <-should not happen.
                     ))
         (file (locate-file cln-lib locpath sfx 'exists)))
    (when file
      (setq file (file-truename file))
      (let ((smp-gz (string-match-p ".*\\.gz" file)))
        (setq file (concat (file-name-directory file)
                           (cond ((or (not shw-gz) (and shw-gz (not smp-gz)))
                                  ;; Call it twice to knock the .gz
off the .el.gz
                                  (file-name-sans-extension
                                   (file-name-nondirectory
                                    (file-name-sans-extension file))))
                                 ((or (and shw-gz smp-gz) t)
                                  (file-name-nondirectory file)))))))
    file))
;;
;;;
;;; :TEST-ME (locate-library-rmv-sfx "subr.el" '("/home/MON/loc-libr")
'((".bubba" ".el" ".el.gz") . t))
;;;          => "/home/MON/loc-libr/subr"
;;; :TEST-ME (locate-library-rmv-sfx "subr.el" '("/home/MON/loc-libr")
'((".bubba" ".el" ".el.gz")))
;;;          => "/home/MON/loc-libr/subr"
;;; :TEST-ME (locate-library-rmv-sfx "subr" '("/home/MON/loc-libr")
'((".el.gz" ".bubba"  ".el") . t))
;;;          =>"/home/MON/loc-libr/subr.el.gz"
;;; :TEST-ME (locate-library-rmv-sfx "subr.el" '("/home/MON/loc-libr")
'((".el.gz" ".bubba"  ".el") . nil))
;;;          => "/home/MON/loc-libr/subr"
;;; :TEST-ME (locate-library-rmv-sfx "subr.el.gz"
'("/home/MON/loc-libr") '((".el.gz" ".bubba"  ".el") . nil))
;;;          => "/home/MON/loc-libr/subr"
;;; :TEST-ME (locate-library-rmv-sfx "subr.el.gz"
'("/home/MON/loc-libr") '((".el.gz" ".bubba"  ".el") . t))
;;;           => "/home/MON/loc-libr/subr.el.gz"
;;; :TEST-ME (locate-library-rmv-sfx "subr.el.gz"
'("/home/MON/loc-libr") '((".el.gz" ".bubba"  ".el") . t))
;;;
;;; :TEST-ME (locate-library-rmv-sfx "subr.el.gz"
'("/home/MON/loc-libr" "/usr/share/emacs/23.1.90/lisp")
;;;                        '((".el.gz" ".bubba"  ".el") . t))
;;;            => "/home/MON/loc-libr/subr.el.gz"
;;;
;;; :TEST-ME (locate-library-rmv-sfx "subr.el.gz"
'("/usr/share/emacs/23.1.90/lisp" "/home/MON/loc-libr" )
;;;                    '((".el.gz" ".bubba"  ".el") . t))
;;;           => "/usr/share/emacs/23.1.90/lisp/subr.el.gz"
;;;
;;; :TEST-ME (locate-library-rmv-sfx "subr"
'("/usr/share/emacs/23.1.90/lisp""/home/MON/loc-libr")
;;;                    '((".el.gz" ".bubba"  ".el") . t))
;;;          => "/usr/share/emacs/23.1.90/lisp/subr.el.gz"
;;;
;;; :TEST-ME (locate-library-rmv-sfx "subr"
'("/usr/share/emacs/23.1.90/lisp" "/home/MON/loc-libr")
;;;                    '((".el.gz" ".bubba"  ".el")))
;;;          => "/usr/share/emacs/23.1.90/lisp/subr"
;;;
;;; :TEST-ME
;;; :NOTE :SEE `ffap-locate-file' for more on  why this is a relevant use-case.
;;; (let ((find-vaguely
;;;        (locate-library-rmv-sfx
;;;         "subr"
;;;         '( "/home/MON/loc-libr" "/usr/share/emacs/23.1.90/lisp")
;;;         '(( ".bubba" ".el.gz" ".el") .t))))
;;;   (if (file-exists-p find-vaguely)
;;;       (find-file find-vaguely)
;;;       (completing-read "Which file :"
;;;                        (file-expand-wildcards (concat find-vaguely "*")))))
;;;
;;; ==============================

[-- Attachment #2: locate-library-redux --]
[-- Type: application/octet-stream, Size: 10618 bytes --]

;;; ==============================
;;; :UNMODIFIED `locate-library'. Evaluate me later to get back to Kansas.
(defun locate-library (library &optional nosuffix path interactive-call)
  (interactive (list (completing-read "Locate library: "
				      (apply-partially
                                       'locate-file-completion-table
                                       load-path (get-load-suffixes)))
		     nil nil
		     t))
  (let ((file (locate-file library
			   (or path load-path)
			   (append (unless nosuffix (get-load-suffixes))
				   load-file-rep-suffixes))))
    (if interactive-call
	(if file
	    (message "Library is file %s" (abbreviate-file-name file))
	  (message "No library %s in search path" library)))
    file))

;;; ==============================
;;; :MODIFIED `locate-library'. 
;;; NOSUFFIX with alternative semanitcs and SHOW-COMPRESSED.
;;; Revised version of previous patch(s).
;;; <Timestamp: #{2010-01-28T21:45:20-05:00Z}#{10044} - by MON>
(defun locate-library (library &optional nosuffix path interactive-call show-compressed) 
  (interactive (list (completing-read "Locate library: "
				      (apply-partially
                                       'locate-file-completion-table
                                       load-path (get-load-suffixes)))
		     nil nil
		     t (if current-prefix-arg t)))
  (let* ((lfrs (remove "" load-file-rep-suffixes))
         (gls (sort (get-load-suffixes) #'(lambda (l1 l2) (< (length l1) (length l2)))))
         (sfx  (cond ((booleanp nosuffix)
                      (delete-dups (append gls lfrs)))
                     ((and nosuffix (stringp nosuffix))
                      `(,nosuffix 
                        ,@(mapcar #'(lambda (z)
                                      (concat nosuffix z))
                                  lfrs)))
                     ((consp nosuffix) (delete-dups (append nosuffix lfrs)))
                     (t (append gls lfrs))))
         (cln-lib (if (string= (file-name-sans-extension library) library)
                      library
                      (let ((lib-cln library))
                        (mapc #'(lambda (rgx) 
                                  (let ((ms (string-match-p rgx lib-cln)))
                                    (when ms (setq lib-cln (substring lib-cln 0 ms)))))
                              '("\\(\\(\\.elc\\|\\.el\\)\\.gz\\)" ; -> 1 .el[c].gz
                                "\\(\\.elc\\|\\.el\\)"            ; -> 1 .elc | .el 
                                "\\(\\.gz\\)"))                   ; -> 1 .gz
                        lib-cln)))
         (file (locate-file cln-lib (or path load-path) sfx)))
    (when (and file (or nosuffix (and show-compressed (not nosuffix))))
      (setq file (file-truename file))
      (let ((smp-gz ;;(string-match-p ".*.gz" file)))
             (string-match-p ".*\\.gz" file)))
        (setq file (concat (file-name-directory file)
                           (cond ((or (not show-compressed)
                                      (and show-compressed (not smp-gz)))
                                  (file-name-sans-extension
                                   (file-name-nondirectory 
                                    (file-name-sans-extension file))))
                                 ((or (and show-compressed smp-gz) t)
                                  (file-name-nondirectory file)))))))
    (if interactive-call
        (if file
            (message "Library is file %s" (abbreviate-file-name file))
            (message "No library %s in search path" library)))
    file))

;;; ==============================
;;; :MODIFIED `locate-library'. Semantics of NOSUFFIX unaltered.
;;; Additional arg STRIPSUFFIX when non-nil evaluates `locate-library-rmv-sfx'
;;; <Timestamp: #{2010-01-28T21:45:33-05:00Z}#{10044} - by MON>
(defun locate-library (library &optional nosuffix path interactive-call stripsuffix)
  (interactive (list (completing-read "Locate library: "
				      (apply-partially
                                       'locate-file-completion-table
                                       load-path (get-load-suffixes)))
		     nil nil
		     t))
  (let ((file 
         (if (and (not nosuffix) stripsuffix)
             (locate-library-rmv-sfx library path stripsuffix)
             (locate-file library
                          (or path load-path)
                          (append (unless nosuffix (get-load-suffixes))
                                  load-file-rep-suffixes)))))
    (if interactive-call
	(if file
	    (message "Library is file %s" (abbreviate-file-name file))
            (message "No library %s in search path" library)))
    file))
;;;
;;; Assume the following files are present in "/home/MON/loc-libr":
;;; "subr" "subr.bubba" "subr.bubba.gz" "subr.el" "subr.el.gz" "subr.elc.gz" "subr.el~"
;;;
;;; :TEST-ME (locate-library "subr.el" nil '("/home/MON/loc-libr") nil  '((".bubba" ".el" ".el.gz") . t))
;;;          => "/home/MON/loc-libr/subr.el.gz"
;;;
;;; :TEST-ME (locate-library "subr.el" nil '("/home/MON/loc-libr") nil  '((".bubba" ".el" ".el.gz") . nil))
;;;           => "/home/MON/loc-libr/subr"
;;;
;;; :TEST-ME (locate-library "subr.el" t)
;;;          => "/home/MON/loc-libr/subr"
;;;

;;; ==============================
;;; :NOTE For backwards compat we strip the extension in the `cln-lib' var.
;;;       Not using `file-name-extension'/`file-name-extension' b/c:
;;;       (file-name-extension "subr.elc.gz") => "gz"
;;;       (file-name-sans-extension "subr.elc.gz") => "subr.elc"
;;;
;;; <Timestamp: #{2010-01-28T19:31:03-05:00Z}#{10044} - by MON>
(defun locate-library-rmv-sfx (library locpath rmvsfx-shw-gz)
  "LIBRARY is a string naming the library to locate.
LOCPATH is a list of paths in which to locate LIBRARY
RMVSFX-SHW-GZ is a dotted list with the form:\n
 '\(\(\".el\" \".el.gz\" \".bubba\"\) . t\)\"
The first element is a list of suffix names which LIBRARY might have.
When present the second element is a boolean, t or nil. If t when LIBRARY is
found in PATH with a suffix matching the first element of RMVSFX-SHW-GZ and that
element represents a compressed file extension show the file name with the
extension."
  (let* ((gls (sort (get-load-suffixes) #'(lambda (l1 l2) (< (length l1) (length l2)))))
         (lfrs   (remove "" load-file-rep-suffixes))         
         (cln-lib (if (string= (file-name-sans-extension library) library)
                      library
                      (let ((lib-cln library))
                        (mapc #'(lambda (rgx) 
                                  (let ((ms (string-match-p rgx lib-cln)))
                                    (when ms (setq lib-cln (substring lib-cln 0 ms)))))
                              '("\\(\\(\\.elc\\|\\.el\\)\\.gz\\)" ; -> 1 .el[c].gz
                                "\\(\\.elc\\|\\.el\\)" ; -> 1 .elc | .el 
                                "\\(\\.gz\\)"))        ; -> 1 .gz
                        lib-cln)))
         ;; :NOTE arg 
         (shw-gz  (cdr rmvsfx-shw-gz))  ; => t
         (rmvsfx (car rmvsfx-shw-gz))   ; => (".el" ".el.gz" ".bubba")
         (sfx  (cond ((booleanp rmvsfx) (delete-dups (append gls lfrs)))
                     ((and rmvsfx (stringp rmvsfx))
                      `(,rmvsfx ,@(mapcar #'(lambda (z) (concat rmvsfx z)) lfrs)))
                     ((consp rmvsfx) (delete-dups (append rmvsfx lfrs)))
                     ;; (t (append  gls lfrs)))) ;; <-should not happen.
                     ))
         (file (locate-file cln-lib locpath sfx 'exists)))
    (when file 
      (setq file (file-truename file))
      (let ((smp-gz (string-match-p ".*\\.gz" file)))
        (setq file (concat (file-name-directory file)
                           (cond ((or (not shw-gz) (and shw-gz (not smp-gz)))
                                  ;; Call it twice to knock the .gz off the .el.gz
                                  (file-name-sans-extension
                                   (file-name-nondirectory 
                                    (file-name-sans-extension file))))
                                 ((or (and shw-gz smp-gz) t) 
                                  (file-name-nondirectory file)))))))
    file))
;;
;;;
;;; :TEST-ME (locate-library-rmv-sfx "subr.el" '("/home/MON/loc-libr") '((".bubba" ".el" ".el.gz") . t))
;;;          => "/home/MON/loc-libr/subr"
;;; :TEST-ME (locate-library-rmv-sfx "subr.el" '("/home/MON/loc-libr") '((".bubba" ".el" ".el.gz")))
;;;          => "/home/MON/loc-libr/subr"
;;; :TEST-ME (locate-library-rmv-sfx "subr" '("/home/MON/loc-libr") '((".el.gz" ".bubba"  ".el") . t))
;;;          =>"/home/MON/loc-libr/subr.el.gz"
;;; :TEST-ME (locate-library-rmv-sfx "subr.el" '("/home/MON/loc-libr") '((".el.gz" ".bubba"  ".el") . nil))
;;;          => "/home/MON/loc-libr/subr"
;;; :TEST-ME (locate-library-rmv-sfx "subr.el.gz" '("/home/MON/loc-libr") '((".el.gz" ".bubba"  ".el") . nil))
;;;          => "/home/MON/loc-libr/subr"
;;; :TEST-ME (locate-library-rmv-sfx "subr.el.gz" '("/home/MON/loc-libr") '((".el.gz" ".bubba"  ".el") . t))
;;;           => "/home/MON/loc-libr/subr.el.gz"
;;; :TEST-ME (locate-library-rmv-sfx "subr.el.gz" '("/home/MON/loc-libr") '((".el.gz" ".bubba"  ".el") . t))
;;;
;;; :TEST-ME (locate-library-rmv-sfx "subr.el.gz" '("/home/MON/loc-libr" "/usr/share/emacs/23.1.90/lisp") 
;;;                        '((".el.gz" ".bubba"  ".el") . t))
;;;            => "/home/MON/loc-libr/subr.el.gz"
;;;
;;; :TEST-ME (locate-library-rmv-sfx "subr.el.gz" '("/usr/share/emacs/23.1.90/lisp" "/home/MON/loc-libr" )
;;;                    '((".el.gz" ".bubba"  ".el") . t))
;;;           => "/usr/share/emacs/23.1.90/lisp/subr.el.gz"
;;;
;;; :TEST-ME (locate-library-rmv-sfx "subr" '("/usr/share/emacs/23.1.90/lisp""/home/MON/loc-libr") 
;;;                    '((".el.gz" ".bubba"  ".el") . t))
;;;          => "/usr/share/emacs/23.1.90/lisp/subr.el.gz"
;;;
;;; :TEST-ME (locate-library-rmv-sfx "subr" '("/usr/share/emacs/23.1.90/lisp" "/home/MON/loc-libr") 
;;;                    '((".el.gz" ".bubba"  ".el")))
;;;          => "/usr/share/emacs/23.1.90/lisp/subr"
;;; 
;;; :TEST-ME
;;; :NOTE :SEE `ffap-locate-file' for more on  why this is a relevant use-case.
;;; (let ((find-vaguely 
;;;        (locate-library-rmv-sfx 
;;;         "subr" 
;;;         '( "/home/MON/loc-libr" "/usr/share/emacs/23.1.90/lisp") 
;;;         '(( ".bubba" ".el.gz" ".el") .t))))
;;;   (if (file-exists-p find-vaguely)
;;;       (find-file find-vaguely)
;;;       (completing-read "Which file :"
;;;                        (file-expand-wildcards (concat find-vaguely "*")))))
;;;

;;; ==============================
;;; EOF

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

end of thread, other threads:[~2010-01-29  2:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-19 22:28 locate-library, the NOSUFFIX arg and a [PATCH] MON KEY
2010-01-21 14:08 ` Stefan Monnier
2010-01-21 23:58   ` MON KEY
2010-01-22 15:18     ` Stefan Monnier
2010-01-23  2:10       ` MON KEY
2010-01-23 11:23         ` Stefan Monnier
2010-01-24  1:39           ` MON KEY
2010-01-25  3:23             ` Stefan Monnier
2010-01-27  4:25               ` MON KEY
2010-01-27 14:55                 ` Stefan Monnier
2010-01-28  1:09                   ` MON KEY
2010-01-28  2:46                     ` Stefan Monnier
2010-01-29  2:55                       ` MON KEY

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