all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "David J. Biesack" <David.Biesack@sas.com>
Cc: 4902@emacsbugs.donarmstrong.com
Subject: bug#4902: 23.1; directory-abbrev-alist is not handled early enough
Date: Wed, 11 Nov 2009 09:52:19 -0500	[thread overview]
Message-ID: <jwvws1xm96i.fsf-monnier+emacsbugreports@gnu.org> (raw)
In-Reply-To: <ytb1vk63w73.fsf@sas.com> (David J. Biesack's message of "Tue, 10 Nov 2009 16:29:36 -0500")

> Obviously, there are too many different names for the same file,
> and I want Emacs to normalize all files to a canonical
> form; i.e. all the variations of my network home should
> be normalized to u:/ and so forth.

> directory-abbrev-alist:

> '(("^//dntsrc/u/sasdjb" . "u:")
>   ("^/u/sasdjb" . "u:")
>   ("^//sashq/root/u/sasdjb" . "u:")
>   ("^/nfs/sanyo/vol/vol2/u22/sasdjb" . "u:/")
>   ("^//sashq/root/u/sasdjb" . "u:")
>   ("^/sas/" . "//dntsrc/sas/")
>   ("^/sasgen" . "//dntsrc/sasgen/"))

The way I see it, the problem really is in the way you organize and use
your naming structure.  So "the right solution" would be a combination
of discipline, conventions, and symlinks to sort out this mess and make
sure that you see much fewer variations of filenames and that all the
ones you see work everywhere (via symlinks, for example).

Now, I understand this may not be practically feasible for you, but
I think that changing Emacs to accomodate this particular situation is
a bit hard to justify.

OTOH, Emacs does provide enough hooks already for you to be able to make
it work, I think.  The hook you want is file-name-handler-alist.
The only problem with it, is that it's very powerful and quite a bit
trickier to use than directory-abbrev-alist.

You could try the code below (guaranteed 100% untested).


        Stefan


(defvar djb-filemess-remappings
  '(("\\`/\\(/dntsrc/u\\|u\\|/sashq/root/u\\|nfs/sanyo/vol/vol2/u22\\)/sasdjb"
     . "u:")
    ("\\`/\\(sas\\(gen\\)?\\)/" . "//dntsrc/\\1/")))

(defun djb-filemess-run-real-handler (operation args)
  (let ((inhibit-file-name-handlers
         (cons 'djb-filemess-handler
               (and (eq inhibit-file-name-operation operation)
                    inhibit-file-name-handlers)))
        (inhibit-file-name-operation operation))
    (apply operation args))))

(defun djb-filemess-handler (operation &rest args)
  (let ((fn (get operation 'djb-filemess-handler)))
    (if fn (funcall fn operation args)
      (djb-filemess-run-real-handler operation args))))

(defun djb-filemess-remap-1 (operation args)
  (let ((file (car args))
        (remappings djb-filemess-remappings)
        newfile)
    (while (and (null newfile) remappings)
      (if (string-match (caar remappings) file)
          (setq newfile (replace-match (cdar remappings) t nil file))
        (setq remappings (cdr remappings))))
    (djb-filemess-run-real-handler operation
                                  (cons (or newfile file) (cdr args)))))

(put 'expand-file-name 'djb-filemess-handler 'djb-filemess-remap-1)
(put 'substitute-in-file-name 'djb-filemess-handler 'djb-filemess-remap-1)

(dolist (remapping djb-filemess-remappings)
  (push (cons (car remapping) 'djb-filemess-handler)
        file-name-handler-alist))





  parent reply	other threads:[~2009-11-11 14:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-10 17:54 bug#4902: 23.1; directory-abbrev-alist is not handled early enough David Biesack
2009-11-10 19:35 ` Stefan Monnier
2009-11-10 19:52   ` David J. Biesack
2009-11-10 21:02     ` Stefan Monnier
2009-11-10 21:29       ` David J. Biesack
2009-11-11  4:11         ` Eli Zaretskii
2009-11-11 12:47           ` David J. Biesack
2009-11-11 18:35             ` Eli Zaretskii
2009-11-11 20:57               ` David J. Biesack
2009-11-11 14:52         ` Stefan Monnier [this message]
2009-11-11 19:41           ` David J. Biesack
2019-11-02  5:21           ` Stefan Kangas

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=jwvws1xm96i.fsf-monnier+emacsbugreports@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=4902@emacsbugs.donarmstrong.com \
    --cc=David.Biesack@sas.com \
    /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.