From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: MON KEY Newsgroups: gmane.emacs.devel Subject: locate-library, the NOSUFFIX arg and a [PATCH] Date: Tue, 19 Jan 2010 17:28:37 -0500 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=000e0cd5f67eb4ccfa047d8bfdc2 X-Trace: ger.gmane.org 1263940349 24046 80.91.229.12 (19 Jan 2010 22:32:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Jan 2010 22:32:29 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 19 23:32:22 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NXMcX-0001DW-FZ for ged-emacs-devel@m.gmane.org; Tue, 19 Jan 2010 23:32:22 +0100 Original-Received: from localhost ([127.0.0.1]:46740 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXMcY-0007dc-7C for ged-emacs-devel@m.gmane.org; Tue, 19 Jan 2010 17:32:22 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXMZ1-0005tv-QJ for emacs-devel@gnu.org; Tue, 19 Jan 2010 17:28:43 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXMYw-0005sV-GI for emacs-devel@gnu.org; Tue, 19 Jan 2010 17:28:43 -0500 Original-Received: from [199.232.76.173] (port=40279 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXMYw-0005sK-9q for emacs-devel@gnu.org; Tue, 19 Jan 2010 17:28:38 -0500 Original-Received: from mail-yx0-f191.google.com ([209.85.210.191]:63159) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXMYw-0003x5-1y for emacs-devel@gnu.org; Tue, 19 Jan 2010 17:28:38 -0500 Original-Received: by yxe29 with SMTP id 29so9853305yxe.14 for ; Tue, 19 Jan 2010 14:28:37 -0800 (PST) Original-Received: by 10.150.107.28 with SMTP id f28mr8461220ybc.57.1263940117252; Tue, 19 Jan 2010 14:28:37 -0800 (PST) X-Google-Sender-Auth: 5a00f4d726179e5f X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:120247 Archived-At: --000e0cd5f67eb4ccfa047d8bfdc2 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable `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-suffi= xes' | 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 nam= e 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 lrea= d.c's `Fcons'ing of `empty_unibyte_string'. Which among other things may be causi= ng problems like this: (locate-file-completion-table load-path '("") "subr" #'(lambda (y) (string-match-p ".*z" y)) 'nil) =3D> "subr.el.gz" Which, as it relates to locate-library, causes wonkiness with the local var= iable `file'. Following shows this with NOSUFFIX both t and nil: (let (nosuffix) (append (unless nosuffix (get-load-suffixes)) load-file-rep-suffixes)) =3D> (".elc" ".elc.gz" ".el" ".el.gz" "" ".gz") (let ((nosuffix t)) (append (unless nosuffix (get-load-suffixes)) load-file-rep-suffixes)) =3D> ("" ".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") =3D> "/usr/share/emacs/23.1.90/lisp/subr.elc" (locate-library "subr" ".elc") =3D> "/usr/share/emacs/23.1.90/lisp/subr" (locate-library "subr" ".el") =3D> "/usr/share/emacs/23.1.90/lisp/subr" (locate-library "subr.el" ".gz") =3D> "/usr/share/emacs/23.1.90/lisp/subr" (locate-library "subr" ".el.gz") =3D> "/usr/share/emacs/23.1.90/lisp/subr" (locate-library "subr" ".gz") =3D> nil (locate-library "subr" t) =3D> "/usr/share/emacs/23.1.90/lisp/subr" (apply 'locate-library "subr" '(nil nil t)) =3D> "/usr/share/emacs/23.1.90/lisp/subr.elc" (apply 'locate-library "subr" '(".el.gz" nil t)) =3D> "/usr/share/emacs/23.1.90/lisp/subr" (apply 'locate-library "subr" '(".elc" nil t)) =3D> "/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"))) =3D> ("/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) ;;; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D --- 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)) - =0C ;;;; Specifying things to do later. ;;; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D --000e0cd5f67eb4ccfa047d8bfdc2 Content-Type: application/octet-stream; name="subr.el.diff" Content-Disposition: attachment; filename="subr.el.diff" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g4n98vwu0 LS0tIHN1YnIuZWx+OTkzMDR+CTIwMTAtMDEtMTkgMTU6MzQ6MDAuMDAwMDAwMDAwIC0wNTAwCisr KyBzdWJyLmVsCTIwMTAtMDEtMTkgMTc6MDU6MjQuMDAwMDAwMDAwIC0wNTAwCkBAIC0xNTg2LDE2 ICsxNTg2LDM0IEBACiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsb2Fk LXBhdGggKGdldC1sb2FkLXN1ZmZpeGVzKSkpCiAJCSAgICAgbmlsIG5pbAogCQkgICAgIHQpKQot ICAobGV0ICgoZmlsZSAobG9jYXRlLWZpbGUgbGlicmFyeQotCQkJICAgKG9yIHBhdGggbG9hZC1w YXRoKQotCQkJICAgKGFwcGVuZCAodW5sZXNzIG5vc3VmZml4IChnZXQtbG9hZC1zdWZmaXhlcykp Ci0JCQkJICAgbG9hZC1maWxlLXJlcC1zdWZmaXhlcykpKSkKKyAgKGxldCogKChsZnJzIChyZW1v dmUgIiIgbG9hZC1maWxlLXJlcC1zdWZmaXhlcykpCisgICAgICAgICAoc2Z4ICAoY29uZCAoKGJv b2xlYW5wIG5vc3VmZml4KQorICAgICAgICAgICAgICAgICAgICAgIChkZWxldGUtZHVwcyAoYXBw ZW5kIGxmcnMgKGdldC1sb2FkLXN1ZmZpeGVzKSkpKQorICAgICAgICAgICAgICAgICAgICAgKChh bmQgbm9zdWZmaXggKHN0cmluZ3Agbm9zdWZmaXgpKQorICAgICAgICAgICAgICAgICAgICAgIGAo LG5vc3VmZml4IAorICAgICAgICAgICAgICAgICAgICAgICAgLEAobWFwY2FyICMnKGxhbWJkYSAo eikKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGNvbmNhdCBub3N1ZmZp eCB6KSkKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZnJzKSkpCisgICAgICAg ICAgICAgICAgICAgICAoKGNvbnNwIG5vc3VmZml4KQorICAgICAgICAgICAgICAgICAgICAgIChk ZWxldGUtZHVwcyAoYXBwZW5kIG5vc3VmZml4IGxmcnMpKSkKKyAgICAgICAgICAgICAgICAgICAg ICh0IChhcHBlbmQgbGZycyhnZXQtbG9hZC1zdWZmaXhlcykpKSkpCisgICAgICAgICAoZmlsZSAo bG9jYXRlLWZpbGUgbGlicmFyeQorICAgICAgICAgICAgICAgICAgICAgICAgICAgIChvciBwYXRo IGxvYWQtcGF0aCkKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZngpKSkKKyAgICAod2hl biAoYW5kIGZpbGUgbm9zdWZmaXgpCisgICAgICAoc2V0cSBmaWxlIChmaWxlLXRydWVuYW1lIGZp bGUpKQorICAgICAgKHNldHEgZmlsZSAoY29uY2F0IChmaWxlLW5hbWUtZGlyZWN0b3J5IGZpbGUp CisgICAgICAgICAgICAgICAgICAgICAgICAgKGlmIChzdHJpbmctbWF0Y2gtcCAiLiouZ3oiIGZp bGUpCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChmaWxlLW5hbWUtc2Fucy1leHRlbnNp b24KKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChmaWxlLW5hbWUtbm9uZGlyZWN0b3J5 IAorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChmaWxlLW5hbWUtc2Fucy1leHRlbnNp b24gZmlsZSkpKQorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoZmlsZS1uYW1lLXNhbnMt ZXh0ZW5zaW9uCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoZmlsZS1uYW1lLW5vbmRp cmVjdG9yeSBmaWxlKSkpKSkpCiAgICAgKGlmIGludGVyYWN0aXZlLWNhbGwKLQkoaWYgZmlsZQot CSAgICAobWVzc2FnZSAiTGlicmFyeSBpcyBmaWxlICVzIiAoYWJicmV2aWF0ZS1maWxlLW5hbWUg ZmlsZSkpCi0JICAobWVzc2FnZSAiTm8gbGlicmFyeSAlcyBpbiBzZWFyY2ggcGF0aCIgbGlicmFy eSkpKQorICAgICAgICAoaWYgZmlsZQorICAgICAgICAgICAgKG1lc3NhZ2UgIkxpYnJhcnkgaXMg ZmlsZSAlcyIgKGFiYnJldmlhdGUtZmlsZS1uYW1lIGZpbGUpKQorICAgICAgICAgICAgKG1lc3Nh Z2UgIk5vIGxpYnJhcnkgJXMgaW4gc2VhcmNoIHBhdGgiIGxpYnJhcnkpKSkKICAgICBmaWxlKSkK LQogDAogOzs7OyBTcGVjaWZ5aW5nIHRoaW5ncyB0byBkbyBsYXRlci4KIAo= --000e0cd5f67eb4ccfa047d8bfdc2--