Subject: bug#78769: 31.0.50; improve ffap-file-name-with-spaces

From: Eli Zaretskii <[email-masked]>
Date: Thu, 12 Jun 2025 09:19:31 +0300

> Date: Thu, 12 Jun 2025 06:39:53 +0530 (IST)
> From:  Madhu via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> This is with regard to:
> 
> *  Eli Zaretskii <[email-masked]> <[email-masked]>
> Wrote on Sun, 08 Jun 2025 08:30:50 +0300
> >> Date: Sun, 08 Jun 2025 08:46:26 +0530
> >> From:  Madhu
> >> there is the "recently" (i.e. within living memory, or within 5 years)
> >> introduced ffap-file-name-with-spaces which helps but it breaks ffap on
> >> files with "~" patterns like "~/tmp/foo bar/var" patterns and generally
> >> breaks "~/tmp/".
> >
> > It's actually worse than that: Windows-style d:/foo/bar file names
> > (which AFAIU were the motivation for the change) are also broken when
> > this option is non-nil (and the test suite just codifies the incorrect
> > results!).
> >
> > Please submit a bug report about this semi-broken "feature".  It must
> > be improved.
> 
> The code paths were introduced in
> * commit f3afb23d26b948cfa095b221ca32090a2858e8f1
> |Author:     Jari Aalto <[email-masked]>
> |AuthorDate: Sat Aug 15 12:11:41 2020 +0200
> |Commit:     Lars Ingebrigtsen <[email-masked]>
> |CommitDate: Sat Aug 15 12:11:41 2020 +0200
> |
> |    Add support for ffap guessing at file names containing spaces
> |
> |    * lisp/ffap.el (ffap-file-name-with-spaces): New variable (bug#8439).
> |    (ffap-search-backward-file-end, ffap-search-forward-file-end)
> |    (ffap-dir-separator-near-point): New functions.
> |    (ffap-string-at-point): Use the variable and the new functions to
> |    guess at files containing strings.
> 
> After a bit of investigation, there are a couple of points.
> 
> First I think my use case of completing unix file names and spaces can
> be supported without touching the existing code paths which use
> ffap-file-name-with-spaces:
> 
> This simlply involves extending with the space character the car of
> the alist entry for `file' in ffap-string-at-point-mode-alist, when it
> is used in ffap-string-at-point
> 
> (setq args
>   (assq 'file ffap-string-at-point-mode-alist))
> 
> ;; => (file "--:\\\\${}+<>@-Z_[:alpha:]~*?#" "{<@" "@>;.,!:}")
> 
> ;; note the first three characters of (car args) is just obscure
> ;; notation which expands to "-./0123456789:"
> ;; (apply 'string (loop for i from ?\- to ?\: collect i))

Thanks.  I meanwhile installed on the master branch of the Emacs Git
repository, 4 days ago, a change which should fix the problem you
reported.  If you are using the master branch, updating from Git
should solve these problems for you.  Could you please try the latest
master branch and see if it solves this problem?