all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Jumping to message by ID
@ 2023-09-09  9:00 Andrea Monaco
  2023-09-09  9:15 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Andrea Monaco @ 2023-09-09  9:00 UTC (permalink / raw)
  To: emacs-devel


I thought of a feature for rmail.  If point is on a message id, for
example those in the In-reply-to and References field, then pressing
ENTER or some key could show the message with that id, if such is found.

I would occasionally find this feature useful.  Let me know.



Andrea Monaco



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

* Re: Jumping to message by ID
  2023-09-09  9:00 Jumping to message by ID Andrea Monaco
@ 2023-09-09  9:15 ` Eli Zaretskii
  2023-10-20  8:09   ` [PATCH] " Andrea Monaco
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-09-09  9:15 UTC (permalink / raw)
  To: Andrea Monaco; +Cc: emacs-devel

> From: Andrea Monaco <andrea.monaco@autistici.org>
> Date: Sat, 09 Sep 2023 11:00:11 +0200
> 
> 
> I thought of a feature for rmail.  If point is on a message id, for
> example those in the In-reply-to and References field, then pressing
> ENTER or some key could show the message with that id, if such is found.
> 
> I would occasionally find this feature useful.  Let me know.

Sounds useful, please feel free to work on adding this.

Thanks.



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

* [PATCH] Jumping to message by ID
  2023-09-09  9:15 ` Eli Zaretskii
@ 2023-10-20  8:09   ` Andrea Monaco
  2023-10-20 10:26     ` Eli Zaretskii
  2023-10-23  2:08     ` Richard Stallman
  0 siblings, 2 replies; 7+ messages in thread
From: Andrea Monaco @ 2023-10-20  8:09 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel


diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index f76600000c9..aaccf8b9b24 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -2699,6 +2699,35 @@ rmail-show-message
     (if blurb
 	(message blurb))))
 
+(defun rmail-get-email-address-at-point ()
+  "Return the email address or message id around point, or nil if none is present."
+  (save-mark-and-excursion
+    (let ((p (point)))
+      (unless (= p (point-max))
+	(forward-char))
+      (if (and
+	   (search-backward "<" nil t)
+	   (let ((end (re-search-forward "<.*@.*>" nil t)))
+	     (and end (> end p))))
+	  (match-string 0)))))
+
+(defun rmail-show-message-by-id (&optional id)
+  "Show message with given Message ID, defaulting to the id around point."
+  (interactive
+   (list (rmail-get-email-address-at-point)))
+  (unless id
+    (error "No message ID around point"))
+  (let ((id (rmail-get-email-address-at-point)))
+    (when id
+      (unless (and rmail-summary-message-parents-vector
+		   (= (length rmail-summary-message-parents-vector)
+		      (1+ rmail-total-messages)))
+	(rmail-summary-fill-message-parents-and-descs-vectors))
+      (let ((entry (assoc id (gethash id rmail-summary-message-ids-hash-table))))
+	(if entry
+	    (rmail-show-message (cdr entry))
+	  (error (concat "No message with ID " id " found")))))))
+
 (defun rmail-is-text-p ()
   "Return t if the region contains a text message, nil otherwise."
   (save-excursion



New command to jump to a message with the ID around point

* lisp/mail/rmail.el (rmail-get-email-address-at-point)
    (rmail-show-message-by-id): New functions.



Andrea Monaco



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

* Re: [PATCH] Jumping to message by ID
  2023-10-20  8:09   ` [PATCH] " Andrea Monaco
@ 2023-10-20 10:26     ` Eli Zaretskii
  2023-10-20 17:26       ` Andrea Monaco
  2023-10-23  2:08     ` Richard Stallman
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-10-20 10:26 UTC (permalink / raw)
  To: Andrea Monaco; +Cc: emacs-devel

> From: Andrea Monaco <andrea.monaco@autistici.org>
> Cc: emacs-devel@gnu.org
> Date: Fri, 20 Oct 2023 10:09:55 +0200
> 
> 
> +(defun rmail-get-email-address-at-point ()
> +  "Return the email address or message id around point, or nil if none is present."

The name of the function doesn't seem to reflect what it does.  Can
you come up with a better name?

> +(defun rmail-show-message-by-id (&optional id)
> +  "Show message with given Message ID, defaulting to the id around point."
> +  (interactive
> +   (list (rmail-get-email-address-at-point)))
> +  (unless id
> +    (error "No message ID around point"))
> +  (let ((id (rmail-get-email-address-at-point)))
> +    (when id
> +      (unless (and rmail-summary-message-parents-vector
> +		   (= (length rmail-summary-message-parents-vector)
> +		      (1+ rmail-total-messages)))
> +	(rmail-summary-fill-message-parents-and-descs-vectors))
> +      (let ((entry (assoc id (gethash id rmail-summary-message-ids-hash-table))))
> +	(if entry
> +	    (rmail-show-message (cdr entry))
> +	  (error (concat "No message with ID " id " found")))))))
> +

If I have many hundreds of messages in my INBOX (e.g., I have almost
2100 now where I'm typing this, and this number is not an anomaly in
my Rmail use patterns), wouldn't
rmail-summary-fill-message-parents-and-descs-vectors take a
significant time?  If so, perhaps it would make sense to update the
data each time we update the summary, instead of punishing the first
call after getting new email?

Thanks.



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

* Re: [PATCH] Jumping to message by ID
  2023-10-20 10:26     ` Eli Zaretskii
@ 2023-10-20 17:26       ` Andrea Monaco
  2023-10-20 23:44         ` Adam Porter
  0 siblings, 1 reply; 7+ messages in thread
From: Andrea Monaco @ 2023-10-20 17:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel


  > The name of the function doesn't seem to reflect what it does.  Can
  > you come up with a better name?

What about rmail-match-email-address-around-point?  Of course I'm
looking for message ids, but those have the same syntax as email
addresses and the latter are surely known to whoever reads my function.


  > If so, perhaps it would make sense to update the data each time we
  > update the summary, instead of punishing the first call after
  > getting new email?

You're right, that's the same issue as rmail-summary-by-thread.

In this case I only need the message id hash table so I could just
update that, at the risk of making it out of sync with the vectors of
parents and descendants.

The only solution is updating all the data structures each time new mail
is got or mail is expunged, instead of recreating them from scratch; I
can look into that.



Andrea Monaco



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

* Re: [PATCH] Jumping to message by ID
  2023-10-20 17:26       ` Andrea Monaco
@ 2023-10-20 23:44         ` Adam Porter
  0 siblings, 0 replies; 7+ messages in thread
From: Adam Porter @ 2023-10-20 23:44 UTC (permalink / raw)
  To: andrea.monaco; +Cc: eliz, emacs-devel

> What about rmail-match-email-address-around-point?  Of course I'm
> looking for message ids, but those have the same syntax as email
> addresses and the latter are surely known to whoever reads my function.
Friendly FYI:

   goto-address-find-address-at-point is a native-compiled Lisp function
   in ‘goto-addr.el’.

   (goto-address-find-address-at-point)

   Find e-mail address around or before point.
   Then search backwards to beginning of line for the start of an e-mail
   address.  If no e-mail address found, return nil.



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

* Re: [PATCH] Jumping to message by ID
  2023-10-20  8:09   ` [PATCH] " Andrea Monaco
  2023-10-20 10:26     ` Eli Zaretskii
@ 2023-10-23  2:08     ` Richard Stallman
  1 sibling, 0 replies; 7+ messages in thread
From: Richard Stallman @ 2023-10-23  2:08 UTC (permalink / raw)
  To: Andrea Monaco; +Cc: eliz, emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

This is a useful change -- but it could be even more useful
if it had a user interface that did not require an additioal
command,  I don't see how to do that -- do you?

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)





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

end of thread, other threads:[~2023-10-23  2:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-09  9:00 Jumping to message by ID Andrea Monaco
2023-09-09  9:15 ` Eli Zaretskii
2023-10-20  8:09   ` [PATCH] " Andrea Monaco
2023-10-20 10:26     ` Eli Zaretskii
2023-10-20 17:26       ` Andrea Monaco
2023-10-20 23:44         ` Adam Porter
2023-10-23  2:08     ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.