unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: "Omar Antolín Camarena" <omar@matem.unam.mx>
Cc: 41424@debbugs.gnu.org, 41412@debbugs.gnu.org,
	Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#41424: bug#41412: 27.0.90; Value of default directory in completions buffer
Date: Fri, 22 Jan 2021 21:28:14 +0100	[thread overview]
Message-ID: <87k0s4wwbl.fsf@gnus.org> (raw)
In-Reply-To: <87pnay7azg.fsf@penguin> ("Omar Antolín Camarena"'s message of "Wed, 20 May 2020 12:49:23 -0500")

Omar Antolín Camarena <omar@matem.unam.mx> writes:

> There is a bit of logic in `complete-setup-function' (from simple.el)
> to set the default directory in the *Completions* buffer:
>
> ;; FIXME: This is a bad hack.  We try to set the default-directory
> ;; in the *Completions* buffer so that the relative file names
> ;; displayed there can be treated as valid file names, independently
> ;; from the completion context.  But this suffers from many problems:
> ;; - It's not clear when the completions are file names.  With some
> ;;   completion tables (e.g. bzr revision specs), the listed
> ;;   completions can mix file names and other things.
> ;; - It doesn't pay attention to possible quoting.
> ;; - With fancy completion styles, the code below will not always
> ;;   find the right base directory.
> (if minibuffer-completing-file-name
>     (file-name-as-directory
>      (expand-file-name
>       (buffer-substring (minibuffer-prompt-end)
>                         (- (point) (or completion-base-size 0))))))
>
> As the comment says, this is brittle, but better than nothing. I
> believe, however, that the `file-name-as-directory' is a typo and
> probably `file-name-directory' was intended instead.

I think that sounds likely.  The patch that introduced this code is
below, and it indeed changes the `file-name-directory' to
`file-name-as-directory' (among other things).

I've added Stafan M to the CCs -- was this done on purpose, or should we
go back to `file-name-directory' here?

diff --git a/lisp/simple.el b/lisp/simple.el
index 082605f659..13c75c4d7b 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5851,20 +5851,22 @@ completion-root-regexp
 ;; after the text of the completion list buffer is written.
 (defun completion-setup-function ()
   (let* ((mainbuf (current-buffer))
-         (mbuf-contents (minibuffer-completion-contents))
-         common-string-length)
-    ;; When reading a file name in the minibuffer,
-    ;; set default-directory in the minibuffer
-    ;; so it will get copied into the completion list buffer.
-    (if minibuffer-completing-file-name
-	(with-current-buffer mainbuf
-	  (setq default-directory
-                (file-name-directory (expand-file-name mbuf-contents)))))
+         (base-dir
+          ;; When reading a file name in the minibuffer,
+          ;; try and find the right default-directory to set in the
+          ;; completion list buffer.
+          ;; FIXME: Why do we do that, actually?  --Stef
+          (if minibuffer-completing-file-name
+              (file-name-as-directory
+               (expand-file-name
+                (substring (minibuffer-completion-contents)
+                           0 (or completion-base-size 0)))))))
     (with-current-buffer standard-output
       (let ((base-size completion-base-size)) ;Read before killing localvars.
         (completion-list-mode)
         (set (make-local-variable 'completion-base-size) base-size))
       (set (make-local-variable 'completion-reference-buffer) mainbuf)
+      (if base-dir (setq default-directory base-dir))
       (unless completion-base-size
         ;; This shouldn't be needed any more, but further analysis is needed
         ;; to make sure it's the case.


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





  reply	other threads:[~2021-01-22 20:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-20 17:49 bug#41424: 26.1; default-directory in *Completions* buffer Omar Antolín Camarena
2021-01-22 20:28 ` Lars Ingebrigtsen [this message]
2021-01-22 22:50   ` bug#41412: 27.0.90; Value of default directory in completions buffer Stefan Monnier
2021-01-23 18:47     ` bug#41424: " Lars Ingebrigtsen
2021-01-23 22:00       ` Stefan Monnier
2022-05-09 11:00         ` bug#41412: bug#41424: 26.1; default-directory in *Completions* buffer Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k0s4wwbl.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=41412@debbugs.gnu.org \
    --cc=41424@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=omar@matem.unam.mx \
    /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 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).