[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#4902: 23.1; directory-abbrev-alist is not handled early enough

From: Stefan Monnier
Subject: bug#4902: 23.1; directory-abbrev-alist is not handled early enough
Date: Wed, 11 Nov 2009 09:52:19 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

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


(defvar djb-filemess-remappings
     . "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-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)
    (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)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]