unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Daniel Mendler <mail@daniel-mendler.de>
Cc: 68214@debbugs.gnu.org
Subject: bug#68214: Completion sorting customization by category
Date: Tue, 09 Jan 2024 19:59:13 +0200	[thread overview]
Message-ID: <86o7dul766.fsf@mail.linkov.net> (raw)
In-Reply-To: <87h6jpdm63.fsf@daniel-mendler.de> (Daniel Mendler's message of "Sun, 07 Jan 2024 19:37:56 +0100")

>> What do you think about doing the same for
>> `completion-extra-properties'?
>
> Yes, makes sense. The documentation of `completion-extra-properties'
> would have to be extended accordingly, mentioning all the newly
> supported properties. It bothers me a little bit that the
> `completion-metadata-get' lookup wouldn't be allocation-free anymore
> (because of keywords versus plain symbols), but one could cache the
> keyword symbol.
>
> (defun completion-metadata-get (metadata prop)
>   "Get property PROP from completion METADATA.
> If the metadata specifies a completion category, the variables
> `completion-category-overrides' and
> `completion-category-defaults' take precedence for
> category-specific overrides.  If the completion metadata does not
> specify the property, the `completion-extra-properties' plist is
> consulted.  Note that the keys of the
> `completion-extra-properties' plist are keyword symbols, not
> plain symbols."
>   (if-let (((not (eq prop 'category)))
>            (cat (alist-get 'category metadata))
>            (over (completion--category-override cat prop)))
>       (cdr over)
>     (or (alist-get prop metadata)
>         (plist-get completion-extra-properties
>                    ;; Cache the keyword
>                    (or (get prop 'completion-extra-properties--keyword)
>                        (put prop 'completion-extra-properties--keyword
>                             (intern (concat ":" (symbol-name prop)))))))))

Thanks, this is now pushed as well in the commit aff1d53cd46.

Now I tried to use a more user-friendly let-binding of
'completion-extra-properties' like below, but then discovered
that it doesn't work for the category.

Maybe 'completion-metadata-get' could try to get a category
from 'completion-extra-properties' as well?

diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index e01d5d792a6..2c3e7d28301 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -2337,14 +2337,12 @@ calendar-read-date
          (defmon (aref month-array (1- (calendar-extract-month default-date))))
          (completion-ignore-case t)
          (month (cdr (assoc-string
-                      (completing-read
-                       (format-prompt "Month name" defmon)
-                       (lambda (string pred action)
-	                 (if (eq action 'metadata)
-		             '(metadata (category . calendar-month))
-	                   (complete-with-action
-                            action (append month-array nil) string pred)))
-                       nil t nil nil defmon)
+                      (let ((completion-extra-properties
+                             '(:category calendar-month)))
+                        (completing-read
+                         (format-prompt "Month name" defmon)
+                         (append month-array nil)
+                         nil t nil nil defmon))
                       (calendar-make-alist month-array 1) t)))
          (defday (calendar-extract-day default-date))
          (last (calendar-last-day-of-month month year)))





  reply	other threads:[~2024-01-09 17:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02 17:07 bug#68214: Completion sorting customization by category Juri Linkov
2024-01-03  7:20 ` Daniel Mendler
2024-01-03 16:07   ` Juri Linkov
2024-01-03 17:12     ` Daniel Mendler
2024-01-04 17:21       ` Juri Linkov
2024-01-05  7:59         ` Juri Linkov
2024-01-05  8:33           ` Daniel Mendler
2024-01-06 17:33             ` Juri Linkov
2024-01-06 17:59               ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-07 18:05                 ` Juri Linkov
2024-01-07 18:37                   ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-09 17:59                     ` Juri Linkov [this message]
2024-01-09 18:14                       ` Juri Linkov
2024-01-09 18:31                         ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-10  7:35                           ` Juri Linkov
2024-01-10  8:53                             ` Daniel Mendler 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

  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=86o7dul766.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=68214@debbugs.gnu.org \
    --cc=mail@daniel-mendler.de \
    /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).