all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: enometh@meer.net, 74208@debbugs.gnu.org
Subject: bug#74208: 31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly
Date: Sat, 23 Nov 2024 14:25:42 +0200	[thread overview]
Message-ID: <864j3ym915.fsf@gnu.org> (raw)
In-Reply-To: <jwvr07iv413.fsf-monnier+emacs@gnu.org> (message from Stefan Monnier on Sun, 10 Nov 2024 22:40:27 -0500)

Ping! How should we make progress with this issue?

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: eliz@gnu.org,  74208@debbugs.gnu.org
> Date: Sun, 10 Nov 2024 22:40:27 -0500
> 
> >>> The problem is that the parameter DIR == "http://example.com" was
> >>> getting bound to default-directory with undesirable results.
> >
> >> It can also have desirable results sometimes (depends on the URL at point
> >> and what kind of support for URLs you have in your Emacs, admittedly).
> >> Do you happen to have a more realistic scenario than your "echo foo"
> >> that lets us better judge the severity of the problem, and maybe other
> >> ways to solve the actual problem?
> >
> > Are you saying it is ok for emacs to make all calls to `call-prcoess'
> > to unconditionally fail --- when emacs is waiting for input at the
> > minibuffer?  the calls to call-process can come from anywhere, from
> > timers, or from outside via emacsclient, etc.
> 
> `default-directory` can point to random places, including non-existing
> directories, HTTP places (e.g. if you enable `url-handler-mode`), so
> code like timers need to take this possibility into account, yes.
> The ffap minibuffer discussed here is just one of many other ways to get
> into this situation.
> 
> > I already posted that any hypothetical completion facilites are
> > singularly useless for the task of ffap (url) -- to get the url at
> > point into the minibuffer and maybe manually edit it.  If these
> > facilities exist and you are using them, I'd like to see an example.
> 
> diff --git a/lisp/url/url-handlers.el b/lisp/url/url-handlers.el
> index 9edc7865a74..17013345c25 100644
> --- a/lisp/url/url-handlers.el
> +++ b/lisp/url/url-handlers.el
> @@ -375,18 +375,48 @@ url-insert-file-contents-literally
>      (kill-buffer buffer)
>      nil))
>  
> -(defun url-file-name-completion (url _directory &optional _predicate)
> -  ;; Even if it's not implemented, it's not an error to ask for completion,
> -  ;; in case it's available (bug#14806).
> -  ;; (error "Unimplemented")
> -  url)
> +(defun url-file-name-completion (url directory &optional predicate)
> +  (let ((all (url-file-name-all-completions url directory)))
> +    (if (null all)
> +        ;; If `url' is the empty string, don't return nil, so as to prevent
> +        ;; partial-completion from recursing into the parent directory.
> +        (if (equal url "") url)
> +      (try-completion url all predicate))))
>  (put 'file-name-completion 'url-file-handlers #'url-file-name-completion)
>  
> -(defun url-file-name-all-completions (_file _directory)
> -  ;; Even if it's not implemented, it's not an error to ask for completion,
> -  ;; in case it's available (bug#14806).
> -  ;; (error "Unimplemented")
> -  nil)
> +(defvar url-handler-temp-buf)
> +
> +(defun url-file-name-all-completions (file directory)
> +  ;; FIXME: Cache the "directory" buffers between completion requests.
> +  (let ((buf (get-file-buffer directory)))
> +    (unless buf
> +      (setq buf (ignore-errors (find-file-noselect directory)))
> +      (when buf
> +        (with-current-buffer buf
> +          (set (make-local-variable 'url-handler-temp-buf) t))))
> +    (when buf
> +      (unwind-protect
> +          (with-current-buffer buf
> +            (save-excursion
> +              (let ((all ())
> +                    (case-fold-search t)
> +                    ;; FIXME: Handle URL-quoting.
> +                    (regexp (format "<a href=\"\\(%s[^\"]+\\)\"" file)))
> +                (goto-char (point-min))
> +                (while (re-search-forward regexp nil t)
> +                  (let ((url (match-string 1)))
> +                    (unless (string-match
> +                             "\\`\\(?:\\.\\.\\|[#?/]\\|[-a-z]+:/\\)\\|" url)
> +                      ;; It's a relative URL.
> +                      (when (string-match "[#?]\\|/\\(.\\)" url)
> +                        (setq url (substring url (or (match-beginning 1)
> +                                                     (match-beginning 0)))))
> +                      ;; FIXME: Handle URL-unquoting.
> +                      (push url all))))
> +                all)))
> +        (and (buffer-live-p buf)
> +             (buffer-local-value 'url-handler-temp-buf buf)
> +             (kill-buffer buf))))))
>  (put 'file-name-all-completions
>       'url-file-handlers #'url-file-name-all-completions)
>  
> 
> 





  reply	other threads:[~2024-11-23 12:25 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05  2:09 bug#74208: 31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly Madhu
2024-11-09 11:11 ` Eli Zaretskii
2024-11-09 16:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-10  0:57   ` Madhu
2024-11-10  6:00     ` Eli Zaretskii
2024-11-10  7:00       ` Madhu
2024-11-10 10:00         ` Eli Zaretskii
2024-11-10 10:41           ` Madhu
2024-11-10 10:45             ` Eli Zaretskii
2024-11-10 11:17               ` Madhu
2024-11-10 11:26                 ` Eli Zaretskii
2024-11-10 16:54         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-11  2:17           ` Madhu
2024-11-11  3:40             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-23 12:25               ` Eli Zaretskii [this message]
2024-11-23 14:56                 ` Madhu
2024-11-24  3:00                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-24  7:19                   ` Eli Zaretskii
2024-12-07 12:20                     ` Eli Zaretskii
2024-12-07 17:23                       ` Madhu
2024-12-07 18:27                         ` Eli Zaretskii
2024-12-08  8:46                         ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 10:49                           ` Madhu
2024-12-08 11:33                             ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 11:59                               ` Madhu
2024-12-08 15:13                                 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 16:26                                   ` Madhu
2024-12-08 17:28                                     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 23:42                                       ` Madhu
2024-12-09  8:17                                         ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors

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

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

  git send-email \
    --in-reply-to=864j3ym915.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=74208@debbugs.gnu.org \
    --cc=enometh@meer.net \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.