unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Antero Mejr via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eshel Yaron <me@eshelyaron.com>
Cc: 62800@debbugs.gnu.org, Juri Linkov <juri@linkov.net>
Subject: bug#62800: [PATCH] eww: Use completion in URL/keyword prompt.
Date: Thu, 13 Apr 2023 01:31:43 +0000	[thread overview]
Message-ID: <871qkoy3cw.fsf@mailbox.org> (raw)
In-Reply-To: <m1a5zcydwx.fsf@eshelyaron.com> (Eshel Yaron's message of "Thu, 13 Apr 2023 00:43:42 +0300")

[-- Attachment #1: Type: text/plain, Size: 1369 bytes --]

Eshel Yaron <me@eshelyaron.com> writes:

>> -     (list (read-string (format-prompt "Enter URL or keywords"
>> -                                       (and uris (car uris)))
>> -                        nil 'eww-prompt-history uris)
>> +     (list (completing-read (format-prompt "Enter URL or keywords"
>> +                                           (and uris (car uris)))
>> +                            eww-prompt-history nil nil nil
>> +                            'eww-prompt-history uris)
>
> Note that this change doesn't work so well for the use case of inserting
> space-separated keywords, since it causes SPC to be bound to
> `minibuffer-complete-word' instead of `self-insert-command'.

Good point. The attached v2 patch creates a new keymap called
"eww-minibuffer-url-keymap" with "SPC" and "?" bound to
self-insert-command, and uses that map for the URL/keyword prompt.

Rebinding minibuffer-local-completion-map is done in a few places in the
code. It is also suggested in the manual (49.3.4 Minibuffer Keymaps),
and was already in my init file, which is why I didn't notice the
problem.

It would be nice if there was a single keymap along the lines of
"minibuffer-local-text-completion-map" that can be used for all those
existing cases, and for completion in commands like "M-x rgrep".  But
that is a bigger change and beyond the scope of this patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v2-0001-eww-Enable-completion-in-URL-keyword-prompt.patch --]
[-- Type: text/x-patch, Size: 2452 bytes --]

From 4be47c886d2e1aeeeaa40a53dea5a8f5f209b652 Mon Sep 17 00:00:00 2001
From: Antero Mejr <antero@mailbox.org>
Date: Wed, 12 Apr 2023 17:56:01 +0000
Subject: [PATCH v2] eww: Enable completion in URL/keyword prompt.

* lisp/net/eww.el (eww): Use 'completing-read' when prompting for a URL
or keywords.
(eww-minibuffer-url-keymap): New keymap for use in the URL/keyword
prompt.
* etc/NEWS (EWW): Add NEWS entry for the change.
---
 etc/NEWS        |  5 +++++
 lisp/net/eww.el | 16 ++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 5e1fd76e99e..9f9317d5ea9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -219,6 +219,11 @@ the new argument NEW-BUFFER non-nil, it will use a new buffer instead.
 Interactively, invoke 'eww-open-file' with a prefix argument to
 activate this behavior.
 
++++
+*** 'eww' now has completion when prompting for a URL or keywords.
+The interactive minibuffer prompt when invoking 'eww' now has support
+for completion.
+
 ** go-ts-mode
 
 +++
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 11be20b68db..7f0c9167c6a 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -329,6 +329,12 @@ parameter, and should return the (possibly) transformed URL."
   :parent shr-map
   "RET" #'eww-follow-link)
 
+(defvar-keymap eww-minibuffer-url-keymap
+  :doc "Keymap used in the minibuffer prompt for URLs or keywords."
+  :parent minibuffer-local-completion-map
+  "SPC" #'self-insert-command
+  "?" #'self-insert-command)
+
 (defun eww-suggested-uris nil
   "Return the list of URIs to suggest at the `eww' prompt.
 This list can be customized via `eww-suggest-uris'."
@@ -377,10 +383,12 @@ killed after rendering.
 
 For more information, see Info node `(eww) Top'."
   (interactive
-   (let ((uris (eww-suggested-uris)))
-     (list (read-string (format-prompt "Enter URL or keywords"
-                                       (and uris (car uris)))
-                        nil 'eww-prompt-history uris)
+   (let ((uris (eww-suggested-uris))
+         (minibuffer-local-completion-map eww-minibuffer-url-keymap))
+     (list (completing-read (format-prompt "Enter URL or keywords"
+                                           (and uris (car uris)))
+                            eww-prompt-history nil nil nil
+                            'eww-prompt-history uris)
            current-prefix-arg)))
   (setq url (eww--dwim-expand-url url))
   (pop-to-buffer-same-window
-- 
2.39.2


  reply	other threads:[~2023-04-13  1:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-12 18:10 bug#62800: [PATCH] eww: Use completion in URL/keyword prompt Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-12 18:32 ` Juri Linkov
2023-04-12 19:44   ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-12 21:43     ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-13  1:31       ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-04-13  6:41         ` Juri Linkov
2023-04-13  6:40     ` Juri Linkov
2023-04-13 17:16       ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-22  9:03         ` Eli Zaretskii
2023-04-23 18:03           ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-23 18:31             ` Eli Zaretskii
2023-04-24 11:56             ` Eli Zaretskii
2023-04-25 14:33             ` Eli Zaretskii

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=871qkoy3cw.fsf@mailbox.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=62800@debbugs.gnu.org \
    --cc=antero@mailbox.org \
    --cc=juri@linkov.net \
    --cc=me@eshelyaron.com \
    /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).