emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

rmail-ordered-headers patch proposal


From: irek
Subject: rmail-ordered-headers patch proposal
Date: Wed, 23 Feb 2022 13:36:05 +0100

Hello, as suggested by Jean in thread "Fixed order of headers in Rmail
messages" from help-gnu-emacs@gnu.org mailing list I'm sending an patch
proposal for Rmail.

It adds new variable `rmail-ordered-headers' that gives control over
mail message headers order.  It's a list of string values being header
names.  When list is not nil then `rmail-copy-headers' function will
ignore `rmail-displayed-headers' and `rmail-ignored-headers' that are
regexp based.  Instead code will go over each `rmail-ordered-headers'
value searching for given header name and copy that header with
corresponding value if found, if not then it's skipped.

I have set default value for this custom variable because in my opinion
this should be a default behavior.

Motives behind all of this can be found in thread archive:
https://lists.gnu.org/archive/html/help-gnu-emacs/2022-02/msg00253.html
https://lists.gnu.org/archive/html/help-gnu-emacs/2022-02/msg00291.html

And in package commentary section that adds this behavior using advice:
https://github.com/ir33k/rmail-ordered-headers/blob/master/rmail-ordered-headers.el#L23

Basically patch does the same thing as mentioned package.

Happy to hear any comments on that, suggestions of changes etc.  I'm
aware that if this is going to be merged with Emacs code base then also
info page and NEWS file have to be updated.

BTW Tested on Emacs 25.2.2 and 29.0.50.

diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index 6b058d09f9..bac810fa25 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -377,6 +377,17 @@ rmail-nonignored-headers
   :type '(choice (const nil) (regexp))
   :group 'rmail-headers)
 
+;;;###autoload
+(defcustom rmail-ordered-headers '("Date" "From" "To" "Reply-To" "Cc" "Bcc" 
"Thread-Topic" "Subject")
+  "List of Header field names that Rmail should display in given order.
+Headers with empty values are omitted.  Note that controlling
+headers using this variable is least performent comparing to
+`rmail-displayed-headers' and `rmail-ignored-headers' which are
+ignored when this var is not nil."
+  :type '(repeat string)
+  :group 'rmail-headers
+  :version "29.1")
+
 ;;;###autoload
 (defcustom rmail-displayed-headers nil
   "Regexp to match Header fields that Rmail should display.
@@ -2898,6 +2909,19 @@ rmail-copy-headers
              (with-current-buffer rmail-view-buffer
                (goto-char (1+ len)))))
 
+           ;; Handle case where headers are copied in order.
+          ((and rmail-ordered-headers (null ignored-headers))
+            (seq-each
+             (lambda (header)
+               (when (re-search-forward (format "^%s:" header) nil t)
+                 (append-to-buffer rmail-view-buffer
+                                   (match-beginning 0)
+                                   (if (re-search-forward header-start-regexp 
nil t)
+                                       (1- (match-end 0))
+                                     (point-max))))
+               (goto-char (point-min)))
+             rmail-ordered-headers))
+
           ;; Handle the case where the headers matching the displayed
           ;; headers regexp should be copied.
           ((and rmail-displayed-headers (null ignored-headers))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]