* [PATCH v2 0/1] notmuch-show-header-line: allow format strings and functions @ 2022-05-16 2:20 jao 2022-05-16 2:20 ` [PATCH v2 1/1] emacs: " jao 0 siblings, 1 reply; 8+ messages in thread From: jao @ 2022-05-16 2:20 UTC (permalink / raw) To: notmuch; +Cc: jao This one extends the previous version that accepted a format string by also accepting an arbitrary function. jao (1): emacs: notmuch-show-header-line: allow format strings and functions emacs/notmuch-show.el | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) -- 2.36.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/1] emacs: notmuch-show-header-line: allow format strings and functions 2022-05-16 2:20 [PATCH v2 0/1] notmuch-show-header-line: allow format strings and functions jao @ 2022-05-16 2:20 ` jao 2022-05-17 20:30 ` Tomi Ollila 0 siblings, 1 reply; 8+ messages in thread From: jao @ 2022-05-16 2:20 UTC (permalink / raw) To: notmuch; +Cc: jao If a string value is assigned to notmuch-show-header-line, it's used as a format string to be passed passed to format-spec with `%s` substituted by the message's subject. If a function is given, it's called with the subject as argument, and its return value used as header line. As before, t means displaying the subject and nil not using any header line. Signed-off-by: jao <jao@gnu.org> --- emacs/notmuch-show.el | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 7c1f02c9..79599480 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -85,8 +85,26 @@ visible for any given message." :group 'notmuch-show) (defcustom notmuch-show-header-line t - "Show a header line with the current message's subject." - :type 'boolean + "Show a header line in notmuch show buffers. + +If t (the default), the header line will contain the current +message's subject. + +If a string, this value is interpreted as a format string to be +passed to `format-spec` with `%s` as the substitution variable +for the message's subject. E.g., to display the subject trimmed +to a maximum of 80 columns, you could use \"%>-80s\" as format. + +If you assign to this variable a function, the function will be +called with the subject as argument and its return value used as +the header line. + +Finally, if this variabale is set to nil, no header is +displayed." + :type '(choice (const :tag "No header" ni) + (const :tag "Subject" t) + (string :tag "Format") + (function :tag "Function")) :group 'notmuch-show) (defcustom notmuch-show-relative-dates t @@ -1351,11 +1369,16 @@ If no messages match the query return NIL." (lambda () (notmuch-show-set-prop :orig-tags (notmuch-show-get-tags)))) ;; Set the header line to the subject of the first message. (when notmuch-show-header-line - (setq header-line-format - (replace-regexp-in-string "%" "%%" - (notmuch-sanitize - (notmuch-show-strip-re - (notmuch-show-get-subject)))))) + (let* ((s (replace-regexp-in-string "%" "%%" + (notmuch-sanitize + (notmuch-show-strip-re + (notmuch-show-get-subject))))) + (h (cond ((stringp notmuch-show-header-line) + (format-spec notmuch-show-header-line `((?s . ,s)))) + ((functionp notmuch-show-header-line) + (funcall notmuch-show-header-line s)) + (notmuch-show-header-line s)))) + (setq header-line-format h))) (run-hooks 'notmuch-show-hook) (if state (notmuch-show-apply-state state) -- 2.36.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] emacs: notmuch-show-header-line: allow format strings and functions 2022-05-16 2:20 ` [PATCH v2 1/1] emacs: " jao @ 2022-05-17 20:30 ` Tomi Ollila 2022-05-17 21:41 ` Jose A Ortega Ruiz 2022-05-17 21:49 ` Jose A Ortega Ruiz 0 siblings, 2 replies; 8+ messages in thread From: Tomi Ollila @ 2022-05-17 20:30 UTC (permalink / raw) To: jao, notmuch On Mon, May 16 2022, jao@gnu.org wrote: > If a string value is assigned to notmuch-show-header-line, it's used > as a format string to be passed passed to format-spec with `%s` > substituted by the message's subject. If a function is given, it's > called with the subject as argument, and its return value used as > header line. > > As before, t means displaying the subject and nil not using any header > line. > > Signed-off-by: jao <jao@gnu.org> > --- > emacs/notmuch-show.el | 37 ++++++++++++++++++++++++++++++------- > 1 file changed, 30 insertions(+), 7 deletions(-) > > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el > index 7c1f02c9..79599480 100644 > --- a/emacs/notmuch-show.el > +++ b/emacs/notmuch-show.el > @@ -85,8 +85,26 @@ visible for any given message." > :group 'notmuch-show) > > (defcustom notmuch-show-header-line t > - "Show a header line with the current message's subject." > - :type 'boolean > + "Show a header line in notmuch show buffers. > + > +If t (the default), the header line will contain the current > +message's subject. > + > +If a string, this value is interpreted as a format string to be > +passed to `format-spec` with `%s` as the substitution variable > +for the message's subject. E.g., to display the subject trimmed > +to a maximum of 80 columns, you could use \"%>-80s\" as format. > + > +If you assign to this variable a function, the function will be > +called with the subject as argument and its return value used as > +the header line. > + > +Finally, if this variabale is set to nil, no header is > +displayed." > + :type '(choice (const :tag "No header" ni) > + (const :tag "Subject" t) > + (string :tag "Format") > + (function :tag "Function")) > :group 'notmuch-show) > > (defcustom notmuch-show-relative-dates t > @@ -1351,11 +1369,16 @@ If no messages match the query return NIL." > (lambda () (notmuch-show-set-prop :orig-tags (notmuch-show-get-tags)))) > ;; Set the header line to the subject of the first message. > (when notmuch-show-header-line > - (setq header-line-format > - (replace-regexp-in-string "%" "%%" > - (notmuch-sanitize > - (notmuch-show-strip-re > - (notmuch-show-get-subject)))))) > + (let* ((s (replace-regexp-in-string "%" "%%" > + (notmuch-sanitize > + (notmuch-show-strip-re > + (notmuch-show-get-subject))))) > + (h (cond ((stringp notmuch-show-header-line) > + (format-spec notmuch-show-header-line `((?s . ,s)))) > + ((functionp notmuch-show-header-line) > + (funcall notmuch-show-header-line s)) > + (notmuch-show-header-line s)))) > + (setq header-line-format h))) To me it looks like some lines are indented with tabs and some spaces (noticed as indentation looked weird to me and then started moving cursor at the beginning of line -- there is probably a way to highlight tabs in notmuch show buffer but...) Otherwise it looks good to me (took a bit to match cond CLAUSES...) Tomi > (run-hooks 'notmuch-show-hook) > (if state > (notmuch-show-apply-state state) > -- > 2.36.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] emacs: notmuch-show-header-line: allow format strings and functions 2022-05-17 20:30 ` Tomi Ollila @ 2022-05-17 21:41 ` Jose A Ortega Ruiz 2022-05-18 9:58 ` David Bremner 2022-05-17 21:49 ` Jose A Ortega Ruiz 1 sibling, 1 reply; 8+ messages in thread From: Jose A Ortega Ruiz @ 2022-05-17 21:41 UTC (permalink / raw) To: Tomi Ollila, notmuch On Tue, May 17 2022, Tomi Ollila wrote: [...] > To me it looks like some lines are indented with tabs and some spaces > (noticed as indentation looked weird to me and then started moving cursor > at the beginning of line -- there is probably a way to highlight tabs in > notmuch show buffer but...) oh, i've got that highlight on, and i see spaces and tabs mixed all over the place, so i didn't pay attention: i have emacs configured to indent using spaces, am i supposed to use tabs for notmuch elisp? or just not mix the two in the same block? thanks for checking, jao -- They are ill discoverers that think there is no land, when they can see nothing but sea. -Francis Bacon, philosopher (1561-1626) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] emacs: notmuch-show-header-line: allow format strings and functions 2022-05-17 21:41 ` Jose A Ortega Ruiz @ 2022-05-18 9:58 ` David Bremner 2022-05-18 19:31 ` Jose A Ortega Ruiz 0 siblings, 1 reply; 8+ messages in thread From: David Bremner @ 2022-05-18 9:58 UTC (permalink / raw) To: Jose A Ortega Ruiz, Tomi Ollila, notmuch Jose A Ortega Ruiz <jao@gnu.org> writes: > On Tue, May 17 2022, Tomi Ollila wrote: > > > [...] > >> To me it looks like some lines are indented with tabs and some spaces >> (noticed as indentation looked weird to me and then started moving cursor >> at the beginning of line -- there is probably a way to highlight tabs in >> notmuch show buffer but...) > > oh, i've got that highlight on, and i see spaces and tabs mixed all over > the place, so i didn't pay attention: i have emacs configured to indent > using spaces, am i supposed to use tabs for notmuch elisp? or just not > mix the two in the same block? > If you run "devel/check-notmuch-commit" (or the embedded emacs command) it will "do the right thing" for indenting elisp. Basically however emacs -Q does it. The only catch is that potentially some files might predate this and/or have indentation overriding emacs, so you have to pick and choose any diffs. d ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] emacs: notmuch-show-header-line: allow format strings and functions 2022-05-18 9:58 ` David Bremner @ 2022-05-18 19:31 ` Jose A Ortega Ruiz 0 siblings, 0 replies; 8+ messages in thread From: Jose A Ortega Ruiz @ 2022-05-18 19:31 UTC (permalink / raw) To: David Bremner, Tomi Ollila, notmuch On Wed, May 18 2022, David Bremner wrote: > Jose A Ortega Ruiz <jao@gnu.org> writes: > >> On Tue, May 17 2022, Tomi Ollila wrote: >> >> >> [...] >> >>> To me it looks like some lines are indented with tabs and some spaces >>> (noticed as indentation looked weird to me and then started moving cursor >>> at the beginning of line -- there is probably a way to highlight tabs in >>> notmuch show buffer but...) >> >> oh, i've got that highlight on, and i see spaces and tabs mixed all over >> the place, so i didn't pay attention: i have emacs configured to indent >> using spaces, am i supposed to use tabs for notmuch elisp? or just not >> mix the two in the same block? >> > > If you run "devel/check-notmuch-commit" (or the embedded emacs command) > it will "do the right thing" for indenting elisp. Basically however > emacs -Q does it. Ah, thanks. I did that now in a new version of the patch. Hopefully i got it right this time. I also refactored out a separate function, as discussed with Tomi. Cheers, jao -- He is a hard man who is only just, and a sad one who is only wise. -Voltaire, philosopher (1694-1778) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] emacs: notmuch-show-header-line: allow format strings and functions 2022-05-17 20:30 ` Tomi Ollila 2022-05-17 21:41 ` Jose A Ortega Ruiz @ 2022-05-17 21:49 ` Jose A Ortega Ruiz 2022-05-18 13:36 ` Tomi Ollila 1 sibling, 1 reply; 8+ messages in thread From: Jose A Ortega Ruiz @ 2022-05-17 21:49 UTC (permalink / raw) To: Tomi Ollila, notmuch On Tue, May 17 2022, Tomi Ollila wrote: [...] > Otherwise it looks good to me (took a bit to match cond CLAUSES...) perhaps it'd be bit clearer if i factor it out in a separate function that just does the bit of setting the header line format? cheers, jao -- Not far from the invention of fire must rank the invention of doubt. -Thomas Henry Huxley, biologist (1825-1895) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] emacs: notmuch-show-header-line: allow format strings and functions 2022-05-17 21:49 ` Jose A Ortega Ruiz @ 2022-05-18 13:36 ` Tomi Ollila 0 siblings, 0 replies; 8+ messages in thread From: Tomi Ollila @ 2022-05-18 13:36 UTC (permalink / raw) To: Jose A Ortega Ruiz, notmuch On Tue, May 17 2022, Jose A. Ortega Ruiz wrote: > On Tue, May 17 2022, Tomi Ollila wrote: > > [...] > >> Otherwise it looks good to me (took a bit to match cond CLAUSES...) > > perhaps it'd be bit clearer if i factor it out in a separate function > that just does the bit of setting the header line format? I thought something similar last night.... > > cheers, > jao > -- > Not far from the invention of fire must rank the invention of doubt. > -Thomas Henry Huxley, biologist (1825-1895) ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-05-18 19:31 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-05-16 2:20 [PATCH v2 0/1] notmuch-show-header-line: allow format strings and functions jao 2022-05-16 2:20 ` [PATCH v2 1/1] emacs: " jao 2022-05-17 20:30 ` Tomi Ollila 2022-05-17 21:41 ` Jose A Ortega Ruiz 2022-05-18 9:58 ` David Bremner 2022-05-18 19:31 ` Jose A Ortega Ruiz 2022-05-17 21:49 ` Jose A Ortega Ruiz 2022-05-18 13:36 ` Tomi Ollila
Code repositories for project(s) associated with this public inbox https://yhetil.org/notmuch.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).