all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: Problem mit symlinks, locate-library and load-history [Was: <Something else>]
Date: Wed, 22 Mar 2006 14:04:30 +0000 (GMT)	[thread overview]
Message-ID: <Pine.LNX.3.96.1060322121024.283B-100000@acm.acm> (raw)
In-Reply-To: <E1FLVGN-00029a-AT@fencepost.gnu.org>

Hi, Richard!

On Mon, 20 Mar 2006, Richard Stallman wrote:

[ This was in the context of eval-after-load not finding an already
loaded file, because of confusion between suffixes ".el" and ".elc" and
confusion between symbolic links and true names. ] 

>It could be useful to define a subroutine to do
> 	      (assoc (file-truename (locate-library file)) load-history)))
>except do it correctly.

>Would someone like to do that, and ack?

Thinking about this a little more, there is confusion in the above,
certainly when used in eval-after-load:  There is NO REASON why a loaded
file should have to be in load-path, and it seems that (locate-library
file) was used mainly to give a convenient search key for `alloc'.

I therefore propose the following function loaded-filename which does
nothing but search load-history for a file.  It can be called like
this:

(loaded-filename "font-lock.el") => "/home/acm/emacs/emacs/lisp/font-lock.elc"
  (any suffix in `load-suffixes' will do in place of the .el).

(loaded-filename "font-lock") => "/home/acm/emacs/emacs/lisp/font-lock.elc"
  (There needn't be a suffix on the name).

(loaded-filename "font-lock.el" t) => nil
  ("font-lock.el", as such, has not been loaded)

(loaded-filename "~/emacs/emacs/lisp/font-lock") =>
"/home/acm/emacs/emacs/lisp/font-lock.elc"

The functions work fine in GNU.  I'm not sure about MS-Windows (case
folding?) or VMS (version numbers?).

#########################################################################
(defun load-history-filename-element (filename &optional exact-suffix)
  "Get the load-history element which matches the loaded Elisp file FILENAME.
Return nil if the file isn't found.  The parameters have the same meaning as
those of the function `loaded-filename'."
  (let* (supplied-basename-sans-ext
	 supplied-extension		; e.g. ".el" or "", NOT "el".
	 regexp
	 (loads load-history)
	 (load-elt (and loads (car loads))))

    (if (file-name-absolute-p filename)
	(progn
	  (setq filename (file-truename filename))
	  (setq supplied-basename-sans-ext
		(file-name-sans-extension (file-name-nondirectory filename))))
      (if (file-name-directory filename)
	  (error "loaded-filename: Relative file name has directory parts: %s" filename))
      (setq supplied-basename-sans-ext (file-name-sans-extension filename)))
    (setq supplied-extension
	  (if (file-name-extension filename)
	      (concat "." (file-name-extension filename))
	    ""))
    (setq regexp
	  (concat (if (file-name-absolute-p filename) "^" "")
		  (if exact-suffix
		      (regexp-quote filename)
		    (concat supplied-basename-sans-ext
			    (regexp-opt (cons supplied-extension load-suffixes))))
		  "$"))

    (while (and loads
		(or (null (car load-elt))
		    (not (string-match regexp (car load-elt)))
		    (not (string= supplied-basename-sans-ext
				  (file-name-sans-extension
				   (file-name-nondirectory (car load-elt)))))))
      (setq loads (cdr loads)
	    load-elt (and loads (car loads))))
    load-elt))

(defun loaded-filename (filename &optional exact-suffix)
  "Get the absolute file name from which Elisp file FILENAME was loaded.
Return nil if the file isn't found.  The returned file name will be a true
name \(i.e. with all its symbolic links having been chased out).

FILENAME is a string.  It may be an absolute file name like
\"/usr/local/bin/emacs/lisp/foobar\", or a bare file name like \"foobar\" or
\"foobar.el\".  It may not be a relative name containing a \"/\".

If EXACT-SUFFIX is non-nil, the function searches only for FILENAME.
Otherwise it also searches for the file names formed by replacing FILENAME's
suffix, if any, by each of the suffixes in `load-suffixes'."
  (let ((elt (load-history-filename-element filename exact-suffix)))
    (and elt (car elt))))
#########################################################################

-- 
Alan Mackenzie (Munich, Germany)

  parent reply	other threads:[~2006-03-22 14:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-14 11:30 CC Mode: File mode specification error: (void-variable c-font-lock-keywords-3) Alan Mackenzie
2006-03-19 22:19 ` Problem mit symlinks, locate-library and load-history [Was: <Something else>] Alan Mackenzie
2006-03-21  1:02   ` Richard Stallman
2006-03-21 14:26     ` Problem mit symlinks, locate-library and load-history Alan Mackenzie
2006-03-21 14:56       ` Stefan Monnier
2006-03-22 14:04     ` Alan Mackenzie [this message]
2006-03-27  8:36       ` Problem mit symlinks, locate-library and load-history [Was: <Something else>] Richard Stallman
2006-05-10 11:18         ` Problem mit symlinks, locate-library and load-history [PATCH] Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.3.96.1060322121024.283B-100000@acm.acm \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.