unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Christian Tietze <me@christiantietze.de>
To: notmuch@notmuchmail.org
Subject: notmuch-mode snippet: auto-select "inbox" widget when launching
Date: Sun, 08 Nov 2020 10:14:37 +0100	[thread overview]
Message-ID: <m1eel4cirm.fsf@christiantietze.de> (raw)

Hey folks!

I'm enjoying notmuch-mode for the better part of 2020 and really got going with emacs thanks to this.

In my day-to-day work, I noticed that when I leave the notmuch-hello buffer open, the point position remains like I left it, which is good. But sometimes I apparently hit `q` and on entering notmuch-hello the next time, I find that my point is in the upper-left corner where the logo is and I have to TAB to inbox.

My idea for a remedy: when `notmuch-hello` is executed and creates the buffer, move point to the inbox tag.

The existing hooks are kinda wonky for this, though. `notmuch-hello-mode-hook` is executed too early, before widgets are available to move the point to, for example. And adding an advice around notmuch-hello doesn't help because that's executed for every refresh, it seems.

My hacky solution is to flick a temp variable on in the mode hook and use this to distinguish the first advice execution from all the others. Code is at the end.

Maybe someone can make use of this, too.

I don't really like the way I do it :)

Do you have any suggestions? I don't want to propose a patch that changes when the hook is executed because I don't know why the hook runs before the widgets are available.

Thanks for any pointers, and enjoy!

Cheers,
Christian

-----
;; When enabling the mode for the first time in a buffer, set a temp variable to `t` ...
(defvar ct/notmuch-hello-mode-activated nil)

(defun ct/notmuch-hello-prepare-advice-hook ()
  (setq ct/notmuch-hello-mode-activated t))
(add-hook 'notmuch-hello-mode-hook #'ct/notmuch-hello-prepare-advice-hook)

(defun ct/notmuch-hello-post-launch-advice (&rest args)
  ;; ... search for the "inbox" widget in the buffer recursively.
  (defun go-to-inbox-widget ()
    (let ((widget (widget-at (point))))
      (if (and widget (string= "inbox" (widget-value widget)))
          nil
        (widget-forward 1)
        (go-to-inbox-widget))))
  ;; ... but only once (!) ...
  (unless (not ct/notmuch-hello-mode-activated)
    ;; ... so turn off the temp variable.
    (setq ct/notmuch-hello-mode-activated nil)
    (go-to-inbox-widget)))
(advice-add #'notmuch-hello :after #'ct/notmuch-hello-post-launch-advice)
-----

             reply	other threads:[~2021-07-30 12:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-08  9:14 Christian Tietze [this message]
2021-08-02 10:08 ` notmuch-mode snippet: auto-select "inbox" widget when launching David Bremner

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://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1eel4cirm.fsf@christiantietze.de \
    --to=me@christiantietze.de \
    --cc=notmuch@notmuchmail.org \
    /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://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).