unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#49321: 28.0.50; [PATCH] Add option icomplete-matches-format
@ 2021-07-01 19:39 Gabriel
  2021-07-04 14:05 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Gabriel @ 2021-07-01 19:39 UTC (permalink / raw)
  To: 49321

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

This patch adds a new user option to lisp/icomplete.el called
'icomplete-matches-format', similar to 'lazy-count-prefix-format'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-option-icomplete-matches-format.patch --]
[-- Type: text/x-patch, Size: 1881 bytes --]

From 47fbdb57abb38972f2b0929760e4043583ba16a8 Mon Sep 17 00:00:00 2001
From: Gabriel do Nascimento Ribeiro <gabriel376@hotmail.com>
Date: Thu, 1 Jul 2021 16:29:24 -0300
Subject: [PATCH 1/1] Add option icomplete-matches-format

* lisp/icomplete.el (icomplete-matches-format): New user option.
---
 lisp/icomplete.el | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 26698c43cf..67bae49b9e 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -97,6 +97,12 @@ icomplete-with-completion-tables
   :type '(choice (const :tag "All" t)
 		 (repeat function)))
 
+(defcustom icomplete-matches-format "%s/%s "
+  "Format of the current/total number of matches for the prompt prefix."
+  :version "28.1"
+  :type '(choice (const :tag "No prefix" nil)
+                 (string :tag "Prefix format string" "%s/%s ")))
+
 (defface icomplete-first-match '((t :weight bold))
   "Face used by Icomplete for highlighting first match."
   :version "24.4")
@@ -696,12 +702,10 @@ icomplete-exhibit
               (overlay-put
                icomplete-overlay 'before-string
                (and icomplete-scroll
-                    (let ((past (length icomplete--scrolled-past)))
-                      (format
-                       "%s/%s "
-                       (1+ past)
-                       (+ past
-                          (safe-length completion-all-sorted-completions))))))
+                    (let* ((past (length icomplete--scrolled-past))
+                           (current (1+ past))
+                           (total (+ past (safe-length completion-all-sorted-completions))))
+                      (format (or icomplete-matches-format "") current total))))
               (overlay-put icomplete-overlay 'after-string text))))))))
 
 (defun icomplete--affixate (md prospects)
-- 
2.32.0


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

* bug#49321: 28.0.50; [PATCH] Add option icomplete-matches-format
  2021-07-01 19:39 bug#49321: 28.0.50; [PATCH] Add option icomplete-matches-format Gabriel
@ 2021-07-04 14:05 ` Lars Ingebrigtsen
  2021-07-04 15:00   ` João Távora
  0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-04 14:05 UTC (permalink / raw)
  To: Gabriel; +Cc: 49321, João Távora, Dmitry Gutov

Gabriel <gabriel376@hotmail.com> writes:

> This patch adds a new user option to lisp/icomplete.el called
> 'icomplete-matches-format', similar to 'lazy-count-prefix-format'.

I guess that sounds reasonable, but I really have no opinion here.  So
I've added Dmitry and João to the CCs -- perhaps they have?

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





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

* bug#49321: 28.0.50; [PATCH] Add option icomplete-matches-format
  2021-07-04 14:05 ` Lars Ingebrigtsen
@ 2021-07-04 15:00   ` João Távora
  2021-07-04 15:33     ` Gabriel
  0 siblings, 1 reply; 6+ messages in thread
From: João Távora @ 2021-07-04 15:00 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Gabriel, 49321, Dmitry Gutov

Thanks Lars,

I think it'd be great to skip the `safe-length` and similar potentially
costly calls if the user decides he doesn't want this info (which
I suppose is icomplete-matches-format = nil)

João

On Sun, Jul 4, 2021 at 3:05 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> Gabriel <gabriel376@hotmail.com> writes:
>
> > This patch adds a new user option to lisp/icomplete.el called
> > 'icomplete-matches-format', similar to 'lazy-count-prefix-format'.
>
> I guess that sounds reasonable, but I really have no opinion here.  So
> I've added Dmitry and João to the CCs -- perhaps they have?
>
> --
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no



-- 
João Távora





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

* bug#49321: 28.0.50; [PATCH] Add option icomplete-matches-format
  2021-07-04 15:00   ` João Távora
@ 2021-07-04 15:33     ` Gabriel
  2021-07-04 15:49       ` Gabriel
  2021-07-19 16:04       ` Lars Ingebrigtsen
  0 siblings, 2 replies; 6+ messages in thread
From: Gabriel @ 2021-07-04 15:33 UTC (permalink / raw)
  To: 49321

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

João Távora <joaotavora@gmail.com> writes:

> Thanks Lars,
>
> I think it'd be great to skip the `safe-length` and similar potentially
> costly calls if the user decides he doesn't want this info (which
> I suppose is icomplete-matches-format = nil)
>
> João
>

Hi Joao,

Thanks for your inputs, makes a lot of sense to shortcut this piece of
code in case the user option is nil. Here is an updated version of the
patch:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-option-icomplete-matches-format.patch --]
[-- Type: text/x-patch, Size: 1920 bytes --]

From d1e81cf0a31a2f5ac714c3cf6dc2cada527cb7a4 Mon Sep 17 00:00:00 2001
From: Gabriel do Nascimento Ribeiro <gabriel376@hotmail.com>
Date: Sun, 4 Jul 2021 12:31:26 -0300
Subject: [PATCH 1/1] Add option icomplete-matches-format

* lisp/icomplete.el (icomplete-matches-format): New user option.
---
 lisp/icomplete.el | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 576fced015..ce914c2f24 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -97,6 +97,12 @@ icomplete-with-completion-tables
   :type '(choice (const :tag "All" t)
 		 (repeat function)))
 
+(defcustom icomplete-matches-format "%s/%s "
+  "Format of the current/total number of matches for the prompt prefix."
+  :version "28.1"
+  :type '(choice (const :tag "No prefix" nil)
+                 (string :tag "Prefix format string" "%s/%s ")))
+
 (defface icomplete-first-match '((t :weight bold))
   "Face used by Icomplete for highlighting first match."
   :version "24.4")
@@ -696,12 +702,11 @@ icomplete-exhibit
               (overlay-put
                icomplete-overlay 'before-string
                (and icomplete-scroll
-                    (let ((past (length icomplete--scrolled-past)))
-                      (format
-                       "%s/%s "
-                       (1+ past)
-                       (+ past
-                          (safe-length completion-all-sorted-completions))))))
+                    icomplete-matches-format
+                    (let* ((past (length icomplete--scrolled-past))
+                           (current (1+ past))
+                           (total (+ past (safe-length completion-all-sorted-completions))))
+                      (format icomplete-matches-format current total))))
               (overlay-put icomplete-overlay 'after-string text))))))))
 
 (defun icomplete--affixate (md prospects)
-- 
2.32.0


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

* bug#49321: 28.0.50; [PATCH] Add option icomplete-matches-format
  2021-07-04 15:33     ` Gabriel
@ 2021-07-04 15:49       ` Gabriel
  2021-07-19 16:04       ` Lars Ingebrigtsen
  1 sibling, 0 replies; 6+ messages in thread
From: Gabriel @ 2021-07-04 15:49 UTC (permalink / raw)
  To: 49321

By the way, there is an open thread in #emacs-devel [1] about making
'icomplete-scroll' into a defcustom, which makes sense to me. In this
case, I am not sure if/how the matches prefix should work. The 'current
value' may not make sense, since it's a rotating list, but the 'total
value' continues to be an important info for the user. I will be glad to
send new patches, if necessary.

[1] https://lists.gnu.org/archive/html/emacs-devel/2021-06/msg00827.html

Regards,
Gabriel





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

* bug#49321: 28.0.50; [PATCH] Add option icomplete-matches-format
  2021-07-04 15:33     ` Gabriel
  2021-07-04 15:49       ` Gabriel
@ 2021-07-19 16:04       ` Lars Ingebrigtsen
  1 sibling, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-19 16:04 UTC (permalink / raw)
  To: Gabriel; +Cc: 49321

Gabriel <gabriel376@hotmail.com> writes:

> Thanks for your inputs, makes a lot of sense to shortcut this piece of
> code in case the user option is nil. Here is an updated version of the
> patch:

Thanks; applied to Emacs 28.

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





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

end of thread, other threads:[~2021-07-19 16:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 19:39 bug#49321: 28.0.50; [PATCH] Add option icomplete-matches-format Gabriel
2021-07-04 14:05 ` Lars Ingebrigtsen
2021-07-04 15:00   ` João Távora
2021-07-04 15:33     ` Gabriel
2021-07-04 15:49       ` Gabriel
2021-07-19 16:04       ` Lars Ingebrigtsen

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).