GNU bug report logs - #65120
29.1; directory-abbrev-alist breaks various things when inside an abbreviated directory

Previous Next

Package: emacs;

Reported by: Sean Allred <allred.sean <at> gmail.com>

Date: Sun, 6 Aug 2023 23:40:01 UTC

Severity: normal

Found in version 29.1

To reply to this bug, email your comments to 65120 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#65120; Package emacs. (Sun, 06 Aug 2023 23:40:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sean Allred <allred.sean <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 06 Aug 2023 23:40:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sean Allred <allred.sean <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.1; directory-abbrev-alist breaks various things when inside an
 abbreviated directory
Date: Sun, 06 Aug 2023 18:35:22 -0500
Emacs behaves oddly inside abbreviated directories when
`directory-abbrev-alist' is set.

    $ emacs -Q
    lisp> (setq directory-abbrev-alist `(("~/tmp" . "tmp")))
    keys> C-x d ~/tmp RET
    keys> C-x C-f

I see "tmp/" in the minibuffer and no completions are available.

I've also seen (dired "~/tmp") fail on Windows in this scenario --
complaining that the directory is inaccessible. On both systems, ~/tmp
does exist (and has content) and behaves as expected if
`directory-abbrev-alist' is nil.

Paring down to a minimal example on Windows is considerably more work
than it is on *nix, though, and I suspect the two symptoms have the same
root cause. Nevertheless, if it should help, I can do that leg-work
sometime this week.

---

In GNU Emacs 29.1 (build 1, aarch64-apple-darwin21.6.0, NS
 appkit-2113.60 Version 12.6.6 (Build 21G646)) of 2023-07-30 built on
 armbob.lan
Windowing system distributor 'Apple', version 10.3.2299
System Description:  macOS 13.5

Configured using:
 'configure --with-ns '--enable-locallisppath=/Library/Application
 Support/Emacs/${version}/site-lisp:/Library/Application
 Support/Emacs/site-lisp' --with-modules 'CFLAGS=-DFD_SETSIZE=10000
 -DDARWIN_UNLIMITED_SELECT' --with-x-toolkit=no'

Configured features:
ACL GLIB GMP GNUTLS JPEG JSON LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER
PNG RSVG THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

--
Sean Allred




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65120; Package emacs. (Mon, 07 Aug 2023 15:46:01 GMT) Full text and rfc822 format available.

Message #8 received at 65120 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Sean Allred <allred.sean <at> gmail.com>
Cc: 65120 <at> debbugs.gnu.org
Subject: Re: bug#65120: 29.1;
 directory-abbrev-alist breaks various things when inside an
 abbreviated directory
Date: Mon, 07 Aug 2023 18:45:55 +0300
> From: Sean Allred <allred.sean <at> gmail.com>
> Date: Sun, 06 Aug 2023 18:35:22 -0500
> 
> Emacs behaves oddly inside abbreviated directories when
> `directory-abbrev-alist' is set.
> 
>     $ emacs -Q
>     lisp> (setq directory-abbrev-alist `(("~/tmp" . "tmp")))
>     keys> C-x d ~/tmp RET
>     keys> C-x C-f
> 
> I see "tmp/" in the minibuffer and no completions are available.
> 
> I've also seen (dired "~/tmp") fail on Windows in this scenario --
> complaining that the directory is inaccessible. On both systems, ~/tmp
> does exist (and has content) and behaves as expected if
> `directory-abbrev-alist' is nil.

This is not how directory-abbrev-alist should be used, according to
documentation.  The cdr of each alist element ("tmp" in your case) is
supposed to be an absolute file name, and "tmp" isn't.  Also, the car
of each element is supposed to be an anchored regexp.

What did you want to accomplish with directory-abbrev-alist such as
the above, and why did you want that?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65120; Package emacs. (Wed, 09 Aug 2023 11:46:01 GMT) Full text and rfc822 format available.

Message #11 received at 65120 <at> debbugs.gnu.org (full text, mbox):

From: Sean Allred <allred.sean <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Sean Allred <allred.sean <at> gmail.com>, 65120 <at> debbugs.gnu.org
Subject: Re: bug#65120: 29.1; directory-abbrev-alist breaks various things
 when inside an abbreviated directory
Date: Wed, 09 Aug 2023 06:28:55 -0500
Eli Zaretskii <eliz <at> gnu.org> writes:
> This is not how directory-abbrev-alist should be used, according to
> documentation.  The cdr of each alist element ("tmp" in your case) is
> supposed to be an absolute file name, and "tmp" isn't.  Also, the car
> of each element is supposed to be an anchored regexp.
>
> What did you want to accomplish with directory-abbrev-alist such as
> the above, and why did you want that?

Ah, I missed this key part of the docstring of `directory-abbrev-alist';
my apologies for that:

    Use this feature when you have directories that you normally refer to
    via absolute symbolic links.  Make TO the name of the link, and FROM
    a regexp matching the name it is linked to.

I jumped the gun on that one a bit. These are definitely not actual
symlinks. In fact, symlinks are categorically a no-go in the target
environment -- Windows on a corporate network. Other solutions like
junctions are probably not something my target audience is going to be
comfortable maintaining.

What I'm trying to do:

I work on the internal tools team at a large-ish software company (~2500
devs). I'm creating a Magit 'distribution' of sorts for Windows to try
to promote its adoption -- since it's the only application in which I
can build first-class support for our workflows. Part of this support
(since I'm developing to lower the barrier to entry for non-Emacs users)
is the creation of a GUI menu that has all the different repositories
and worktrees I can find on their system.

The problem is that our standard folder structure for source code yields
very long paths that look pretty ugly in this menu system. I'm talking
things like 'C:/$MegaCorpSource/git/$host/project/path/here.git' and
'C:/$MegaCorpSource/$version/$SomeDevelopmentIdentifier'. For various
reasons (mostly a _huge_ corpus of other tooling that relies on this
structure), this path structure cannot change. I'm also not limited to
things in $MegaCorpSource; I'm trying to collect all repositories in
`magit-repository-directories'.

So, I'd like to shorten this $MegaCorpSource path using built-in
functionality where possible. My users aren't going to care about most
of the path components. I can roll my own, but is there something like
`abbreviate-file-name' that doesn't assume we're working with symlinks?
(Should/could there be? Thoughts on whether or not it is A Good
Idea(tm)?)

--
Sean Allred




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65120; Package emacs. (Wed, 09 Aug 2023 13:22:01 GMT) Full text and rfc822 format available.

Message #14 received at 65120 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Sean Allred <allred.sean <at> gmail.com>
Cc: allred.sean <at> gmail.com, 65120 <at> debbugs.gnu.org
Subject: Re: bug#65120: 29.1; directory-abbrev-alist breaks various things
 when inside an abbreviated directory
Date: Wed, 09 Aug 2023 16:21:46 +0300
> From: Sean Allred <allred.sean <at> gmail.com>
> Cc: Sean Allred <allred.sean <at> gmail.com>, 65120 <at> debbugs.gnu.org
> Date: Wed, 09 Aug 2023 06:28:55 -0500
> 
> So, I'd like to shorten this $MegaCorpSource path using built-in
> functionality where possible. My users aren't going to care about most
> of the path components. I can roll my own, but is there something like
> `abbreviate-file-name' that doesn't assume we're working with symlinks?
> (Should/could there be? Thoughts on whether or not it is A Good
> Idea(tm)?)

I don't think there's something in Emacs.  But you can use
directory-abbrev-alist if you define a drive (using 'subst') that
would remove the need for using the full file name.  Something like

  subst x: C:\$MegaCorpSource

Then you could use "x:/" in directory-abbrev-alist.  This actually
matches the "symlink" idea of this feature on Unix.

(Yes, I know: corporate IT doesn't like SUBST very much, either.  But
maybe you will be lucky...)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65120; Package emacs. (Wed, 09 Aug 2023 23:49:01 GMT) Full text and rfc822 format available.

Message #17 received at 65120 <at> debbugs.gnu.org (full text, mbox):

From: Sean Allred <allred.sean <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 65120 <at> debbugs.gnu.org
Subject: Re: bug#65120: 29.1; directory-abbrev-alist breaks various things
 when inside an abbreviated directory
Date: Wed, 09 Aug 2023 18:31:50 -0500
Eli Zaretskii <eliz <at> gnu.org> writes:
> I don't think there's something in Emacs.  But you can use
> directory-abbrev-alist if you define a drive (using 'subst') that
> would remove the need for using the full file name.  Something like
>
>   subst x: C:\$MegaCorpSource
>
> Then you could use "x:/" in directory-abbrev-alist.  This actually
> matches the "symlink" idea of this feature on Unix.

Oh, neat! This is definitely not something I would make work 'out of the
box' in my distribution, but I will absolutely add a note in my
documentation to call out this strategy. We already have ~10ish mapped
drives on the network -- as well as folks who use external drives. Would
hate to clobber someone's environment.

In the meantime, I think I'll create a new defcustom/defun pair:

    (defcustom directory-abbrev-display-alist
      nil
      "Like `directory-abbrev-alist', but for `abbreviate-file-name-for-display'.")

    (defun abbreviate-file-name-for-display (filename)
      "Like `abbreviate-file-name', but is not guaranteed to produce a functional path."
      (let ((directory-abbrev-alist (append directory-abbrev-display-alist
                                            directory-abbrev-alist)))
        (abbreviate-file-name filename)))

    ;; e.g.
    (let ((directory-abbrev-display-alist
           '(("C:/MegaCorpSource" . "@src"))))
      (abbreviate-file-name-for-display "C:/MegaCorpSource/foo"))
    => "@src/foo

(Symbol names prefixed with my package prefix, of course.)

If I get good mileage out of this, would this be the kind of thing I
could submit a patch for? It turned out prettier than I was expecting.
(I've already sorted out the FSF paperwork.)

> (Yes, I know: corporate IT doesn't like SUBST very much, either.  But
> maybe you will be lucky...)

Better to ask forgiveness... :-) [obligatory 'kidding' to any of my
corporate IT friends who may be reading this post!]

Thanks!

--
Sean Allred




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65120; Package emacs. (Thu, 10 Aug 2023 06:23:02 GMT) Full text and rfc822 format available.

Message #20 received at 65120 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Sean Allred <allred.sean <at> gmail.com>
Cc: 65120 <at> debbugs.gnu.org
Subject: Re: bug#65120: 29.1; directory-abbrev-alist breaks various things
 when inside an abbreviated directory
Date: Thu, 10 Aug 2023 09:22:38 +0300
> From: Sean Allred <allred.sean <at> gmail.com>
> Cc: 65120 <at> debbugs.gnu.org
> Date: Wed, 09 Aug 2023 18:31:50 -0500
> 
> In the meantime, I think I'll create a new defcustom/defun pair:
> 
>     (defcustom directory-abbrev-display-alist
>       nil
>       "Like `directory-abbrev-alist', but for `abbreviate-file-name-for-display'.")
> 
>     (defun abbreviate-file-name-for-display (filename)
>       "Like `abbreviate-file-name', but is not guaranteed to produce a functional path."
>       (let ((directory-abbrev-alist (append directory-abbrev-display-alist
>                                             directory-abbrev-alist)))
>         (abbreviate-file-name filename)))
> 
>     ;; e.g.
>     (let ((directory-abbrev-display-alist
>            '(("C:/MegaCorpSource" . "@src"))))
>       (abbreviate-file-name-for-display "C:/MegaCorpSource/foo"))
>     => "@src/foo
> 
> (Symbol names prefixed with my package prefix, of course.)
> 
> If I get good mileage out of this, would this be the kind of thing I
> could submit a patch for? It turned out prettier than I was expecting.
> (I've already sorted out the FSF paperwork.)

Where and how would this "abbreviated-for-display" file names used in
Emacs?




This bug report was last modified 268 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.