discussion and development of piem
 help / color / mirror / code / Atom feed
* [PATCH] notmuch: Configure mailing list archive links
@ 2021-02-05 17:10 Xinglu Chen
  2021-02-06  4:54 ` Kyle Meyer
  2021-02-06  8:44 ` [PATCH v2] " Xinglu Chen
  0 siblings, 2 replies; 6+ messages in thread
From: Xinglu Chen @ 2021-02-05 17:10 UTC (permalink / raw)
  To: piem

This adds an entry to `notmuch-show-stash-ml-archive-link-alist` that
reads the `piem-inboxes` variable and returns the public-inbox archive
url.  This means that users don't have to manually add public-inbox
archive urls to `notmuch-show-stash-ml-archive-link-alist`.
---
You can run `notmuch-show-stash-mlarchive-link` on this message, and
paste the link in the browser to see it in action (assuming you have
configured `piem-inboxes`).

 piem-notmuch.el | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/piem-notmuch.el b/piem-notmuch.el
index 5c0cd62..52d9198 100644
--- a/piem-notmuch.el
+++ b/piem-notmuch.el
@@ -106,6 +106,13 @@ (defun piem-notmuch-am-ready-mbox ()
                     (insert patch)))
                 "mbox"))))))
 
+(defun piem-notmuch-show-get-public-inbox-link (mid)
+  "Given the message-id MID, return the public-inbox url.
+This will lookup the url in the `piem-inboxes' variable."
+  (let* ((inbox (piem-inbox-by-header-match))
+        (link (piem-inbox-get :url inbox)))
+    (concat link mid)))
+
 ;;;###autoload
 (define-minor-mode piem-notmuch-mode
   "Toggle Notmuch support for piem.
@@ -119,11 +126,18 @@ (define-minor-mode piem-notmuch-mode
         (add-hook 'piem-am-ready-mbox-functions #'piem-notmuch-am-ready-mbox)
         (add-hook 'piem-get-inbox-functions #'piem-notmuch-get-inbox)
         (add-hook 'piem-get-mid-functions #'piem-notmuch-get-mid)
-        (add-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread))
+        (add-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread)
+        (add-to-list 'notmuch-show-stash-mlarchive-link-alist
+                     '("piem" . piem-notmuch-show-get-public-inbox-link))
+        (setq notmuch-show-stash-mlarchive-link-default "piem"))
     (remove-hook 'piem-am-ready-mbox-functions #'piem-notmuch-am-ready-mbox)
     (remove-hook 'piem-get-inbox-functions #'piem-notmuch-get-inbox)
     (remove-hook 'piem-get-mid-functions #'piem-notmuch-get-mid)
-    (remove-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread)))
+    (remove-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread)
+    (setq notmuch-show-stash-mlarchive-link-alist
+          (delete '("piem" . piem-notmuch-show-get-public-inbox-link)
+                  notmuch-show-stash-mlarchive-link-alist))
+    (setq notmuch-show-stash-mlarchive-link-default "Gmane")))
 
 ;;; piem-notmuch.el ends here
 (provide 'piem-notmuch)
-- 
2.29.2


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

* Re: [PATCH] notmuch: Configure mailing list archive links
  2021-02-05 17:10 [PATCH] notmuch: Configure mailing list archive links Xinglu Chen
@ 2021-02-06  4:54 ` Kyle Meyer
  2021-02-06  8:07   ` Xinglu Chen
  2021-02-06  8:44 ` [PATCH v2] " Xinglu Chen
  1 sibling, 1 reply; 6+ messages in thread
From: Kyle Meyer @ 2021-02-06  4:54 UTC (permalink / raw)
  To: Xinglu Chen; +Cc: piem

Xinglu Chen writes:

> This adds an entry to `notmuch-show-stash-ml-archive-link-alist` that
> reads the `piem-inboxes` variable and returns the public-inbox archive
> url.  This means that users don't have to manually add public-inbox
> archive urls to `notmuch-show-stash-ml-archive-link-alist`.

Nice idea.  I regularly use notmuch-show-stash-mlarchive-link with
public-inbox targets and will happily drop my manual entries :)

I've considered something related in the past: adding a command in the
piem-dispatch transient that essentially does

  (when-let ((inbox (piem-inbox)))
    (kill-new
     (message
      "%s"
      (concat (piem--ensure-trailing-slash (piem-inbox-get :url inbox))
              (piem-escape-mid
               (or (piem-mid)
                   (user-error
                    "No message ID found for the current buffer")))))))

In notmuch, I'm already too accustomed to using
notmuch-show-stash-mlarchive-link (and more generally
notmuch-show-stash-map), but I think I'd occasionally find the above
useful in Gnus.  Hmm, perhaps I'll add such a command this weekend,
along with a section in the manual where we can mention it as well as
the notmuch-show-stash-mlarchive-link support added by this patch.

> diff --git a/piem-notmuch.el b/piem-notmuch.el
> index 5c0cd62..52d9198 100644
> --- a/piem-notmuch.el
> +++ b/piem-notmuch.el
> @@ -106,6 +106,13 @@ (defun piem-notmuch-am-ready-mbox ()
>                      (insert patch)))
>                  "mbox"))))))
>  
> +(defun piem-notmuch-show-get-public-inbox-link (mid)
> +  "Given the message-id MID, return the public-inbox url.
> +This will lookup the url in the `piem-inboxes' variable."
> +  (let* ((inbox (piem-inbox-by-header-match))
> +        (link (piem-inbox-get :url inbox)))
> +    (concat link mid)))

This will usually work, but

  * mid should be escaped with piem-escape-mid.

  * piem-inbox-by-header-match should be executed within
    piem-notmuch--with-current-message so that it can match against the
    full set of headers (which is important for matching the list ID).

    Better yet, just use piem-notmuch-get-inbox, which already does
    that.

  * What about in cases where there is no inbox/url?  Right now it would
    just return the plain message ID.  Should it signal a user-error
    instead?

> +
>  ;;;###autoload
>  (define-minor-mode piem-notmuch-mode
>    "Toggle Notmuch support for piem.
> @@ -119,11 +126,18 @@ (define-minor-mode piem-notmuch-mode
>          (add-hook 'piem-am-ready-mbox-functions #'piem-notmuch-am-ready-mbox)
>          (add-hook 'piem-get-inbox-functions #'piem-notmuch-get-inbox)
>          (add-hook 'piem-get-mid-functions #'piem-notmuch-get-mid)
> -        (add-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread))
> +        (add-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread)
> +        (add-to-list 'notmuch-show-stash-mlarchive-link-alist
> +                     '("piem" . piem-notmuch-show-get-public-inbox-link))
> +        (setq notmuch-show-stash-mlarchive-link-default "piem"))

I'd rather not override the user's
notmuch-show-stash-mlarchive-link-default setting (even if we were to
only do so for the default value of "Gmane", which we know is
nonfunctional and not likely coming back at this point).  Instead, how
about just mentioning notmuch-show-stash-mlarchive-link support in
piem-notmuch-mode's docstring along with a suggestion to set
notmuch-show-stash-mlarchive-link-default to "piem"?

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

* Re: [PATCH] notmuch: Configure mailing list archive links
  2021-02-06  4:54 ` Kyle Meyer
@ 2021-02-06  8:07   ` Xinglu Chen
  0 siblings, 0 replies; 6+ messages in thread
From: Xinglu Chen @ 2021-02-06  8:07 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: piem

On Fri, Feb 05 2021, Kyle Meyer wrote:

>   * What about in cases where there is no inbox/url?  Right now it would
>     just return the plain message ID.  Should it signal a user-error
>     instead?

It should probably give an error and maybe tell the user to add a url.

>> +
>>  ;;;###autoload
>>  (define-minor-mode piem-notmuch-mode
>>    "Toggle Notmuch support for piem.
>> @@ -119,11 +126,18 @@ (define-minor-mode piem-notmuch-mode
>>          (add-hook 'piem-am-ready-mbox-functions #'piem-notmuch-am-ready-mbox)
>>          (add-hook 'piem-get-inbox-functions #'piem-notmuch-get-inbox)
>>          (add-hook 'piem-get-mid-functions #'piem-notmuch-get-mid)
>> -        (add-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread))
>> +        (add-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread)
>> +        (add-to-list 'notmuch-show-stash-mlarchive-link-alist
>> +                     '("piem" . piem-notmuch-show-get-public-inbox-link))
>> +        (setq notmuch-show-stash-mlarchive-link-default "piem"))
>
> I'd rather not override the user's
> notmuch-show-stash-mlarchive-link-default setting (even if we were to
> only do so for the default value of "Gmane", which we know is
> nonfunctional and not likely coming back at this point).  Instead, how
> about just mentioning notmuch-show-stash-mlarchive-link support in
> piem-notmuch-mode's docstring along with a suggestion to set
> notmuch-show-stash-mlarchive-link-default to "piem"?

That sounds like a better idea than what I am currently doing.

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

* [PATCH v2] notmuch: Configure mailing list archive links
  2021-02-05 17:10 [PATCH] notmuch: Configure mailing list archive links Xinglu Chen
  2021-02-06  4:54 ` Kyle Meyer
@ 2021-02-06  8:44 ` Xinglu Chen
  2021-02-06 15:58   ` Kyle Meyer
  1 sibling, 1 reply; 6+ messages in thread
From: Xinglu Chen @ 2021-02-06  8:44 UTC (permalink / raw)
  To: piem

This adds an entry to `notmuch-show-stash-ml-archive-link-alist` that
reads the `piem-inboxes` variable and returns the public-inbox archive
url.  This means that users don't have to manually add public-inbox
archive urls to `notmuch-show-stash-ml-archive-link-alist`.
---
Changes from v1:

- Use `piem-notmuch-get-inbox` instead of writing my own thing.

- Give a user error if there is not url for the inbox.

- Do not set `notmuch-show-stash-mlarchive-link-default`, instead add
  info in `piem-notmuch-mode` docstring that suggests the user to set
  the variable on their own.

 piem-notmuch.el | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/piem-notmuch.el b/piem-notmuch.el
index 5c0cd62..2d6c5a3 100644
--- a/piem-notmuch.el
+++ b/piem-notmuch.el
@@ -106,12 +106,29 @@ (defun piem-notmuch-am-ready-mbox ()
                     (insert patch)))
                 "mbox"))))))
 
+(defun piem-notmuch-show-get-public-inbox-link (mid)
+  "Given the message-id MID, return the public-inbox url.
+This will lookup the url in the `piem-inboxes' variable."
+  (let* ((inbox (piem-notmuch-get-inbox))
+         (link (or (piem-inbox-get :url inbox)
+                   (user-error "No url was found for %s" inbox))))
+    (concat
+     (piem--ensure-trailing-slash link)
+     (piem-escape-mid mid))))
+
 ;;;###autoload
 (define-minor-mode piem-notmuch-mode
   "Toggle Notmuch support for piem.
 With a prefix argument ARG, enable piem-notmuch mode if ARG is
 positive, and disable it otherwise.  If called from Lisp, enable
-the mode if ARG is omitted or nil."
+the mode if ARG is omitted or nil.
+
+This will add a new entry to
+`notmuch-show-stash-mlarchive-link-alist' which till determine
+the archive url by reading the `piem-inboxes’ variable.  You can
+also set `notmuch-show-shas-mlarchive-link-default' to \"piem\"
+to make this the default behavior when calling
+`notmuch-show-stash-mlarchive-link'."
   :global t
   :init-value nil
   (if piem-notmuch-mode
@@ -119,11 +136,16 @@ (define-minor-mode piem-notmuch-mode
         (add-hook 'piem-am-ready-mbox-functions #'piem-notmuch-am-ready-mbox)
         (add-hook 'piem-get-inbox-functions #'piem-notmuch-get-inbox)
         (add-hook 'piem-get-mid-functions #'piem-notmuch-get-mid)
-        (add-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread))
+        (add-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread)
+        (add-to-list 'notmuch-show-stash-mlarchive-link-alist
+                     '("piem" . piem-notmuch-show-get-public-inbox-link)))
     (remove-hook 'piem-am-ready-mbox-functions #'piem-notmuch-am-ready-mbox)
     (remove-hook 'piem-get-inbox-functions #'piem-notmuch-get-inbox)
     (remove-hook 'piem-get-mid-functions #'piem-notmuch-get-mid)
-    (remove-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread)))
+    (remove-hook 'piem-mid-to-thread-functions #'piem-notmuch-mid-to-thread)
+    (setq notmuch-show-stash-mlarchive-link-alist
+          (delete '("piem" . piem-notmuch-show-get-public-inbox-link)
+                  notmuch-show-stash-mlarchive-link-alist))))
 
 ;;; piem-notmuch.el ends here
 (provide 'piem-notmuch)
-- 
2.29.2


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

* Re: [PATCH v2] notmuch: Configure mailing list archive links
  2021-02-06  8:44 ` [PATCH v2] " Xinglu Chen
@ 2021-02-06 15:58   ` Kyle Meyer
  2021-02-06 16:17     ` Xinglu Chen
  0 siblings, 1 reply; 6+ messages in thread
From: Kyle Meyer @ 2021-02-06 15:58 UTC (permalink / raw)
  To: Xinglu Chen; +Cc: piem

Xinglu Chen writes:

> This adds an entry to `notmuch-show-stash-ml-archive-link-alist` that
> reads the `piem-inboxes` variable and returns the public-inbox archive
> url.  This means that users don't have to manually add public-inbox
> archive urls to `notmuch-show-stash-ml-archive-link-alist`.

s/notmuch-show-stash-ml-archive/notmuch-show-stash-mlarchive/

(fixed when applying)

> +(defun piem-notmuch-show-get-public-inbox-link (mid)
> +  "Given the message-id MID, return the public-inbox url.
> +This will lookup the url in the `piem-inboxes' variable."
> +  (let* ((inbox (piem-notmuch-get-inbox))
> +         (link (or (piem-inbox-get :url inbox)
> +                   (user-error "No url was found for %s" inbox))))
> +    (concat
> +     (piem--ensure-trailing-slash link)
> +     (piem-escape-mid mid))))

Looks good.  I've also added a user-error when piem-notmuch-get-inbox
returns nil to give an error that's slightly more informative than "No
url was found for nil".

> +
>  ;;;###autoload
>  (define-minor-mode piem-notmuch-mode
>    "Toggle Notmuch support for piem.
>  With a prefix argument ARG, enable piem-notmuch mode if ARG is
>  positive, and disable it otherwise.  If called from Lisp, enable
> -the mode if ARG is omitted or nil."
> +the mode if ARG is omitted or nil.
> +
> +This will add a new entry to
> +`notmuch-show-stash-mlarchive-link-alist' which till determine
> +the archive url by reading the `piem-inboxes’ variable.  You can
> +also set `notmuch-show-shas-mlarchive-link-default' to \"piem\"

Made a few typo fixes:
s/will/till/
s/’/'/
s/notmuch-show-shas-/notmuch-show-stash-/

> +to make this the default behavior when calling
> +`notmuch-show-stash-mlarchive-link'."

Pushed (fad8d59).  Thanks.

diff --git a/piem-notmuch.el b/piem-notmuch.el
index 2d6c5a3..27edfae 100644
--- a/piem-notmuch.el
+++ b/piem-notmuch.el
@@ -109,7 +109,8 @@ (defun piem-notmuch-am-ready-mbox ()
 (defun piem-notmuch-show-get-public-inbox-link (mid)
   "Given the message-id MID, return the public-inbox url.
 This will lookup the url in the `piem-inboxes' variable."
-  (let* ((inbox (piem-notmuch-get-inbox))
+  (let* ((inbox (or (piem-notmuch-get-inbox)
+                    (user-error "No inbox associated with current buffer")))
          (link (or (piem-inbox-get :url inbox)
                    (user-error "No url was found for %s" inbox))))
     (concat
@@ -119,14 +120,15 @@ (defun piem-notmuch-show-get-public-inbox-link (mid)
 ;;;###autoload
 (define-minor-mode piem-notmuch-mode
   "Toggle Notmuch support for piem.
+
 With a prefix argument ARG, enable piem-notmuch mode if ARG is
 positive, and disable it otherwise.  If called from Lisp, enable
 the mode if ARG is omitted or nil.
 
 This will add a new entry to
-`notmuch-show-stash-mlarchive-link-alist' which till determine
-the archive url by reading the `piem-inboxes’ variable.  You can
-also set `notmuch-show-shas-mlarchive-link-default' to \"piem\"
+`notmuch-show-stash-mlarchive-link-alist' which will determine
+the archive url by reading the `piem-inboxes' variable.  You can
+also set `notmuch-show-stash-mlarchive-link-default' to \"piem\"
 to make this the default behavior when calling
 `notmuch-show-stash-mlarchive-link'."
   :global t

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

* Re: [PATCH v2] notmuch: Configure mailing list archive links
  2021-02-06 15:58   ` Kyle Meyer
@ 2021-02-06 16:17     ` Xinglu Chen
  0 siblings, 0 replies; 6+ messages in thread
From: Xinglu Chen @ 2021-02-06 16:17 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: piem

On Sat, Feb 06 2021, Kyle Meyer wrote:

>>  ;;;###autoload
>>  (define-minor-mode piem-notmuch-mode
>>    "Toggle Notmuch support for piem.
>>  With a prefix argument ARG, enable piem-notmuch mode if ARG is
>>  positive, and disable it otherwise.  If called from Lisp, enable
>> -the mode if ARG is omitted or nil."
>> +the mode if ARG is omitted or nil.
>> +
>> +This will add a new entry to
>> +`notmuch-show-stash-mlarchive-link-alist' which till determine
>> +the archive url by reading the `piem-inboxes’ variable.  You can
>> +also set `notmuch-show-shas-mlarchive-link-default' to \"piem\"
>
> Made a few typo fixes:
> s/will/till/
> s/’/'/
> s/notmuch-show-shas-/notmuch-show-stash-/

Oops, I am good at making typos..

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

end of thread, other threads:[~2021-02-06 16:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-05 17:10 [PATCH] notmuch: Configure mailing list archive links Xinglu Chen
2021-02-06  4:54 ` Kyle Meyer
2021-02-06  8:07   ` Xinglu Chen
2021-02-06  8:44 ` [PATCH v2] " Xinglu Chen
2021-02-06 15:58   ` Kyle Meyer
2021-02-06 16:17     ` Xinglu Chen

discussion and development of piem

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.kyleam.com/piem/0 piem/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 piem piem/ https://inbox.kyleam.com/piem \
		piem@inbox.kyleam.com
	public-inbox-index piem

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.piem


code repositories for project(s) associated with this inbox:

	https://git.kyleam.com/piem/

AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git