GNU bug report logs - #22586
[PATCH 1/2] Optimise ‘point in message header’ check

Previous Next

Packages: emacs, gnus;

Reported by: Michal Nazarewicz <mina86 <at> mina86.com>

Date: Sun, 7 Feb 2016 17:42:02 UTC

Severity: minor

Tags: fixed, patch

Fixed in version 26.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 22586 in the body.
You can then email your comments to 22586 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#22586; Package emacs. (Sun, 07 Feb 2016 17:42:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michal Nazarewicz <mina86 <at> mina86.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 07 Feb 2016 17:42:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Michal Nazarewicz <mina86 <at> mina86.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH 1/2] Optimise ‘point in message header’ check
Date: Sun,  7 Feb 2016 18:40:46 +0100
* lisp/gnus/message.el (message-point-in-header-p): Replace two unbound
regular expression matches with a single bound string match thus
reducing amount of work the function is doing.
---
 lisp/gnus/message.el | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 77e471f..88f198f 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -3516,12 +3516,12 @@ message-fill-paragraph
 (defun message-point-in-header-p ()
   "Return t if point is in the header."
   (save-excursion
-    (and
-     (not
-      (re-search-backward
-       (concat "^" (regexp-quote mail-header-separator) "\n") nil t))
-     (re-search-forward
-      (concat "^" (regexp-quote mail-header-separator) "\n") nil t))))
+    (save-restriction
+      (widen)
+      (let ((bound (+ (point-at-eol) 1)) case-fold-search)
+        (goto-char (point-min))
+        (not (search-forward (concat "\n" mail-header-separator "\n")
+                             bound t))))))
 
 (defun message-do-auto-fill ()
   "Like `do-auto-fill', but don't fill in message header."
-- 
2.7.0.rc3.207.g0ac5344





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#22586; Package emacs. (Sun, 07 Feb 2016 17:44:02 GMT) Full text and rfc822 format available.

Message #8 received at 22586 <at> debbugs.gnu.org (full text, mbox):

From: Michal Nazarewicz <mina86 <at> mina86.com>
To: 22586 <at> debbugs.gnu.org
Subject: [PATCH 2/2] Make `message-beginning-of-line' aware of folded headers
Date: Sun,  7 Feb 2016 18:42:52 +0100
* lisp/gnus/message.pl (message-beginning-of-header): New function which
moves point to the beginning of a mail header.  The function is aware of
folded headers and with non-nil argument looks for the true beginning of
a header while with nil argument moves to the indented text of header’s
value.
(message-beginning-of-line): Function is now aware of folded headers and
either moves point to the indention of a header or, in visual-line-mode,
searches for the beginning of the header.
---
 etc/NEWS             |  5 ++++
 lisp/gnus/message.el | 82 +++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 67 insertions(+), 20 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 95ade41..7ce652c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -762,6 +762,11 @@ invalid certificates are marked in red.
 *** text/html messages that contain inline image parts will be
 transformed into multipart/related messages before sending.
 
+*** `message-beginning-of-line' (bound to C-a) understands folded headers.
+In `visual-line-mode' it will look for the true beginning of a header
+while in non-`visual-line-mode' it will move the point to the indented
+header’s value.
+
 +++
 ** In Show Paren Mode, a parenthesis can be highlighted when point
 stands inside it, and certain parens can be highlighted when point is
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 88f198f..57c6b62 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -6341,35 +6341,77 @@ message-beginning-of-line
 (defvar visual-line-mode)
 (declare-function beginning-of-visual-line "simple" (&optional n))
 
+(defun message-beginning-of-header (handle-folded)
+  "Move point to beginning of header’s value.
+
+When point is at the first header line, moves it after the colon
+and spaces separating header name and header value.
+
+When point is in a continuation line of a folded header (i.e. the
+line starts with a space), the behaviour depends on HANDLE-FOLDED
+argument.  If it’s nil, function moves the point to the start of
+the header continuation; otherwise, function locates the
+beginning of the header and moves point past the colon as is the
+case of single-line headers.
+
+No check whether point is inside of a header or body of the
+message is performed.
+
+Returns point or nil if beginning of header’s value could not be
+found.  In the latter case, the point is still moved to the
+beginning of line (possibly after attempting to move it to the
+beginning of a folded header)."
+  ;; https://www.rfc-editor.org/rfc/rfc2822.txt, section 2.2.3. says that when
+  ;; unfolding a single WSP should be consumed.  WSP is defined as a space
+  ;; character or a horizontal tab.
+  (beginning-of-line)
+  (when handle-folded
+    (while (and (> (point) (point-min))
+                (or (eq (char-after) ?\s) (eq (char-after) ?\t)))
+      (beginning-of-line 0)))
+  (when (or (eq (char-after) ?\s) (eq (char-after) ?\t)
+            (search-forward ":" (point-at-eol) t))
+    ;; We are a bit more lacks than the RFC and allow any positive number of WSP
+    ;; characters.
+    (skip-chars-forward " \t" (point-at-eol))
+    (point)))
+
 (defun message-beginning-of-line (&optional n)
   "Move point to beginning of header value or to beginning of line.
 The prefix argument N is passed directly to `beginning-of-line'.
 
 This command is identical to `beginning-of-line' if point is
-outside the message header or if the option `message-beginning-of-line'
-is nil.
-
-If point is in the message header and on a (non-continued) header
-line, move point to the beginning of the header value or the beginning of line,
-whichever is closer.  If point is already at beginning of line, move point to
-beginning of header value.  Therefore, repeated calls will toggle point
-between beginning of field and beginning of line."
+outside the message header or if the option
+`message-beginning-of-line' is nil.
+
+If point is in the message header and on a header line, move
+point to the beginning of the header value or the beginning of
+line, whichever is closer.  If point is already at beginning of
+line, move point to beginning of header value.  Therefore,
+repeated calls will toggle point between beginning of field and
+beginning of line.
+
+When called without a prefix argument, header value spanning
+multiple lines is treated as a single line.  Otherwise, even if
+N is 1, when point is on a continuation header line, it will be
+moved to the beginning "
   (interactive "p")
   (let ((zrs 'zmacs-region-stays))
     (when (and (featurep 'xemacs) (interactive-p) (boundp zrs))
       (set zrs t)))
-  (if (and message-beginning-of-line
-	   (message-point-in-header-p))
-      (let* ((here (point))
-	     (bol (progn (beginning-of-line n) (point)))
-	     (eol (point-at-eol))
-	     (eoh (re-search-forward ": *" eol t)))
-	(goto-char
-	 (if (and eoh (or (< eoh here) (= bol here)))
-	     eoh bol)))
-    (if (and (boundp 'visual-line-mode) visual-line-mode)
-	(beginning-of-visual-line n)
-      (beginning-of-line n))))
+  (cond
+   ;; Go to beginning of header or beginning of line.
+   ((and message-beginning-of-line (message-point-in-header-p))
+    (let* ((point (point))
+           (bol (progn (beginning-of-line n) (point)))
+           (boh (message-beginning-of-header (and (boundp 'visual-line-mode)
+                                                  visual-line-mode))))
+      (goto-char (if (and boh (or (< boh point) (= bol point))) boh bol))))
+   ;; Go to beginning of visual line
+   ((and (boundp 'visual-line-mode) visual-line-mode)
+    (beginning-of-visual-line n))
+   ;; Go to beginning of line.
+   ((beginning-of-line n))))
 
 (defun message-buffer-name (type &optional to group)
   "Return a new (unique) buffer name based on TYPE and TO."
-- 
2.7.0.rc3.207.g0ac5344





Information forwarded to bug-gnu-emacs <at> gnu.org, bugs <at> gnus.org:
bug#22586; Package emacs,gnus. (Tue, 09 Feb 2016 03:09:02 GMT) Full text and rfc822 format available.

Message #11 received at 22586 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Michal Nazarewicz <mina86 <at> mina86.com>
Cc: 22586 <at> debbugs.gnu.org
Subject: Re: bug#22586: [PATCH 1/2] Optimise ‘point in
 message header’ check
Date: Tue, 09 Feb 2016 14:07:31 +1100
Thanks; I've applied both patches to the Gnus trunk

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 09 Feb 2016 03:11:01 GMT) Full text and rfc822 format available.

bug marked as fixed in version 25.2, send any further explanations to 22586 <at> debbugs.gnu.org and Michal Nazarewicz <mina86 <at> mina86.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 09 Feb 2016 03:11:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 08 Mar 2016 12:24:05 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 04 Dec 2016 02:50:09 GMT) Full text and rfc822 format available.

bug Marked as fixed in versions 26.1. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 04 Dec 2016 02:50:09 GMT) Full text and rfc822 format available.

bug No longer marked as fixed in versions 25.2. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 04 Dec 2016 02:50:09 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 01 Jan 2017 12:24:25 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 176 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.