unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* notmuch-mode snippet: auto-select "inbox" widget when launching
@ 2020-11-08  9:14 Christian Tietze
  2021-08-02 10:08 ` David Bremner
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Tietze @ 2020-11-08  9:14 UTC (permalink / raw)
  To: notmuch

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

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

* Re: notmuch-mode snippet: auto-select "inbox" widget when launching
  2020-11-08  9:14 notmuch-mode snippet: auto-select "inbox" widget when launching Christian Tietze
@ 2021-08-02 10:08 ` David Bremner
  0 siblings, 0 replies; 2+ messages in thread
From: David Bremner @ 2021-08-02 10:08 UTC (permalink / raw)
  To: Christian Tietze, notmuch

Christian Tietze <me@christiantietze.de> writes:

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

Did you try notmuch-hello-refresh-hook? Maybe set a varible in
notmuch-hello-mode-hook to say "new invocation" and do the jump in
notmuch-refresh-hook?

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

Some "not really solution" ideas:

- you can remove notmuch-hello-insert-header from
  notmuch-hello-sections, which means less tabbing

- by default there are key-sequences starting with j that jump to each
  configured saved-search

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

end of thread, other threads:[~2021-08-02 10:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-08  9:14 notmuch-mode snippet: auto-select "inbox" widget when launching Christian Tietze
2021-08-02 10:08 ` David Bremner

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