* Re: [elpa] externals/notmuch-indicator f563869b6a 2/4: Tweak how the keymap is implemented [not found] ` <20220928175750.D5B2CC00615@vcs2.savannah.gnu.org> @ 2022-09-28 18:30 ` Stefan Monnier 2022-09-28 18:58 ` Protesilaos Stavrou 0 siblings, 1 reply; 5+ messages in thread From: Stefan Monnier @ 2022-09-28 18:30 UTC (permalink / raw) To: emacs-devel; +Cc: Protesilaos Stavrou > branch: externals/notmuch-indicator > commit f563869b6a5e5e12fd791bc109232ed45064f7a7 > Author: Protesilaos Stavrou <info@protesilaos.com> > Commit: Protesilaos Stavrou <info@protesilaos.com> > > Tweak how the keymap is implemented > > This continues the work done by Henrik Kjerringvåg in commit f5c9b2e. > Henrik does not require to assign copyright to the Free Software > Foundation for that commit, as it is within the ~15 line threshold. > --- > notmuch-indicator.el | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) > > diff --git a/notmuch-indicator.el b/notmuch-indicator.el > index 89e93054ee..9b598910e2 100644 > --- a/notmuch-indicator.el > +++ b/notmuch-indicator.el > @@ -166,17 +166,21 @@ option `notmuch-indicator-refresh-count'." > (shell-command-to-string > (format "notmuch count %s" terms)))) > > +(defvar notmuch-indicator-mode-map > + (let ((map (make-sparse-keymap))) > + map) > + "Keymap for the Notmuch indicator.") > + > (defun notmuch-indicator--format-label (label count face terms) > "Format LABEL, COUNT, FACE and TERMS of `notmuch-indicator-args'." > - (let ((map (make-sparse-keymap))) > - (define-key map [mode-line mouse-1] > - (lambda () (interactive) (notmuch-search terms))) > - (propertize > - (if (and face label) > - (format "%s%s " (propertize label 'face face) count) > - (format "%s%s " (or label "") count)) > - 'help-echo "mouse-1: Open notmuch search" > - 'local-map map))) > + (define-key notmuch-indicator-mode-map [mode-line mouse-1] > + (lambda () (interactive) (notmuch-search terms))) > + (propertize > + (if (and face label) > + (format "%s%s " (propertize label 'face face) count) > + (format "%s%s " (or label "") count)) > + 'help-echo (format "mouse-1: Open notmuch search for `%s'" terms) > + 'local-map notmuch-indicator-mode-map)) Hmm... really? The new `define-key` will overwrite the binding added in the previous call to `notmuch-indicator--format-label`, so if you have several elements in `notmuch-indicator-args`, they'll all use the last element's `terms` when you click `mouse-1` on them. While I'm here: > + (if (and face label) > + (format "%s%s " (propertize label 'face face) count) > + (format "%s%s " (or label "") count)) can be rewritten to (format "%s%s " (if (and face label) (propertize label 'face face) (or label "") count) Oh, and I see elsewhere that you call `mapconcat` with only 2 args, which is a new feature in Emacs-29 whereas the package claims to want to support Emacs-27. Stefan ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [elpa] externals/notmuch-indicator f563869b6a 2/4: Tweak how the keymap is implemented 2022-09-28 18:30 ` [elpa] externals/notmuch-indicator f563869b6a 2/4: Tweak how the keymap is implemented Stefan Monnier @ 2022-09-28 18:58 ` Protesilaos Stavrou 2022-09-28 19:15 ` Stefan Monnier 2022-09-28 20:38 ` Stefan Monnier 0 siblings, 2 replies; 5+ messages in thread From: Protesilaos Stavrou @ 2022-09-28 18:58 UTC (permalink / raw) To: Stefan Monnier, emacs-devel > From: Stefan Monnier <monnier@iro.umontreal.ca> > Date: Wed, 28 Sep 2022 14:30:01 -0400 > >> branch: externals/notmuch-indicator >> commit f563869b6a5e5e12fd791bc109232ed45064f7a7 >> Author: Protesilaos Stavrou <info@protesilaos.com> >> Commit: Protesilaos Stavrou <info@protesilaos.com> >> >> Tweak how the keymap is implemented >> >> This continues the work done by Henrik Kjerringvåg in commit f5c9b2e. >> Henrik does not require to assign copyright to the Free Software >> Foundation for that commit, as it is within the ~15 line threshold. > [... 37 lines elided] > Hmm... really? The new `define-key` will overwrite the binding added in > the previous call to `notmuch-indicator--format-label`, so if you have > several elements in `notmuch-indicator-args`, they'll all use the last > element's `terms` when you click `mouse-1` on them. Thanks for pointing it out! I reverted to the previous approach. > While I'm here: > >> + (if (and face label) >> + (format "%s%s " (propertize label 'face face) count) >> + (format "%s%s " (or label "") count)) > > can be rewritten to > > > (format "%s%s " > (if (and face label) (propertize label 'face face) > (or label "") > count) Done. Thank you! > Oh, and I see elsewhere that you call `mapconcat` with only 2 args, > which is a new feature in Emacs-29 whereas the package claims to want to > support Emacs-27. Thanks! On a more general note, how can we catch cases like this one? The compiler did not warn about it and the doc string of mapconcat does not explain as much. I know there is an entry in the NEWS, but having to check that manually is not easy. -- Protesilaos Stavrou https://protesilaos.com ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [elpa] externals/notmuch-indicator f563869b6a 2/4: Tweak how the keymap is implemented 2022-09-28 18:58 ` Protesilaos Stavrou @ 2022-09-28 19:15 ` Stefan Monnier 2022-09-28 20:38 ` Stefan Monnier 1 sibling, 0 replies; 5+ messages in thread From: Stefan Monnier @ 2022-09-28 19:15 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: emacs-devel >> Oh, and I see elsewhere that you call `mapconcat` with only 2 args, >> which is a new feature in Emacs-29 whereas the package claims to want to >> support Emacs-27. > > Thanks! On a more general note, how can we catch cases like this one? Byte-compile with the oldest Emacs you want to support and check its warnings? Stefan PS: We make efforts to provide warnings that help people adjust old code to work better in current and future Emacsen, but we don't provide any such thing in the other direction. The closest we have is that `C-h o` will sometimes give you a guess about the Emacs version in which this var/fun was introduced. And IIUC this functionality is not considered as very important. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [elpa] externals/notmuch-indicator f563869b6a 2/4: Tweak how the keymap is implemented 2022-09-28 18:58 ` Protesilaos Stavrou 2022-09-28 19:15 ` Stefan Monnier @ 2022-09-28 20:38 ` Stefan Monnier 2022-09-29 3:26 ` Protesilaos Stavrou 1 sibling, 1 reply; 5+ messages in thread From: Stefan Monnier @ 2022-09-28 20:38 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: emacs-devel Here's another trivial simplification (more specifically an η-reduction). Stefan diff --git a/notmuch-indicator.el b/notmuch-indicator.el index 07ada7aec8..7680ccdc3d 100644 --- a/notmuch-indicator.el +++ b/notmuch-indicator.el @@ -199,8 +199,7 @@ option `notmuch-indicator-refresh-count'." (defun notmuch-indicator--return-count () "Parse `notmuch-indicator-args' and format them as single string." (mapconcat - (lambda (props) - (notmuch-indicator--format-output props)) + #'notmuch-indicator--format-output notmuch-indicator-args "")) (defvar notmuch-indicator-string "" ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [elpa] externals/notmuch-indicator f563869b6a 2/4: Tweak how the keymap is implemented 2022-09-28 20:38 ` Stefan Monnier @ 2022-09-29 3:26 ` Protesilaos Stavrou 0 siblings, 0 replies; 5+ messages in thread From: Protesilaos Stavrou @ 2022-09-29 3:26 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel > From: Stefan Monnier <monnier@iro.umontreal.ca> > Date: Wed, 28 Sep 2022 16:38:38 -0400 > > Here's another trivial simplification (more specifically an η-reduction). > > > Stefan > > > diff --git a/notmuch-indicator.el b/notmuch-indicator.el > index 07ada7aec8..7680ccdc3d 100644 > --- a/notmuch-indicator.el > +++ b/notmuch-indicator.el > @@ -199,8 +199,7 @@ option `notmuch-indicator-refresh-count'." > (defun notmuch-indicator--return-count () > "Parse `notmuch-indicator-args' and format them as single string." > (mapconcat > - (lambda (props) > - (notmuch-indicator--format-output props)) > + #'notmuch-indicator--format-output > notmuch-indicator-args "")) > > (defvar notmuch-indicator-string "" > Installed it. Thank you! -- Protesilaos Stavrou https://protesilaos.com ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-09-29 3:26 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <166438787034.3914.5858408463434087870@vcs2.savannah.gnu.org> [not found] ` <20220928175750.D5B2CC00615@vcs2.savannah.gnu.org> 2022-09-28 18:30 ` [elpa] externals/notmuch-indicator f563869b6a 2/4: Tweak how the keymap is implemented Stefan Monnier 2022-09-28 18:58 ` Protesilaos Stavrou 2022-09-28 19:15 ` Stefan Monnier 2022-09-28 20:38 ` Stefan Monnier 2022-09-29 3:26 ` Protesilaos Stavrou
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).