unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#65120: 29.1; directory-abbrev-alist breaks various things when inside an abbreviated directory
@ 2023-08-06 23:35 Sean Allred
  2023-08-07 15:45 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Allred @ 2023-08-06 23:35 UTC (permalink / raw)
  To: 65120

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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#65120: 29.1; directory-abbrev-alist breaks various things when inside an abbreviated directory
  2023-08-06 23:35 bug#65120: 29.1; directory-abbrev-alist breaks various things when inside an abbreviated directory Sean Allred
@ 2023-08-07 15:45 ` Eli Zaretskii
  2023-08-09 11:28   ` Sean Allred
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2023-08-07 15:45 UTC (permalink / raw)
  To: Sean Allred; +Cc: 65120

> From: Sean Allred <allred.sean@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?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#65120: 29.1; directory-abbrev-alist breaks various things when inside an abbreviated directory
  2023-08-07 15:45 ` Eli Zaretskii
@ 2023-08-09 11:28   ` Sean Allred
  2023-08-09 13:21     ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Allred @ 2023-08-09 11:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Sean Allred, 65120


Eli Zaretskii <eliz@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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#65120: 29.1; directory-abbrev-alist breaks various things when inside an abbreviated directory
  2023-08-09 11:28   ` Sean Allred
@ 2023-08-09 13:21     ` Eli Zaretskii
  2023-08-09 23:31       ` Sean Allred
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2023-08-09 13:21 UTC (permalink / raw)
  To: Sean Allred; +Cc: allred.sean, 65120

> From: Sean Allred <allred.sean@gmail.com>
> Cc: Sean Allred <allred.sean@gmail.com>, 65120@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...)





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#65120: 29.1; directory-abbrev-alist breaks various things when inside an abbreviated directory
  2023-08-09 13:21     ` Eli Zaretskii
@ 2023-08-09 23:31       ` Sean Allred
  2023-08-10  6:22         ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Allred @ 2023-08-09 23:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 65120


Eli Zaretskii <eliz@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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#65120: 29.1; directory-abbrev-alist breaks various things when inside an abbreviated directory
  2023-08-09 23:31       ` Sean Allred
@ 2023-08-10  6:22         ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2023-08-10  6:22 UTC (permalink / raw)
  To: Sean Allred; +Cc: 65120

> From: Sean Allred <allred.sean@gmail.com>
> Cc: 65120@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?





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-08-10  6:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-06 23:35 bug#65120: 29.1; directory-abbrev-alist breaks various things when inside an abbreviated directory Sean Allred
2023-08-07 15:45 ` Eli Zaretskii
2023-08-09 11:28   ` Sean Allred
2023-08-09 13:21     ` Eli Zaretskii
2023-08-09 23:31       ` Sean Allred
2023-08-10  6:22         ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).