* bug#22586: [PATCH 1/2] Optimise ‘point in message header’ check
@ 2016-02-07 17:40 Michal Nazarewicz
2016-02-07 17:42 ` bug#22586: [PATCH 2/2] Make `message-beginning-of-line' aware of folded headers Michal Nazarewicz
2016-02-09 3:07 ` bug#22586: [PATCH 1/2] Optimise ‘point in message header’ check Lars Ingebrigtsen
0 siblings, 2 replies; 3+ messages in thread
From: Michal Nazarewicz @ 2016-02-07 17:40 UTC (permalink / raw)
To: 22586
* 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#22586: [PATCH 2/2] Make `message-beginning-of-line' aware of folded headers
2016-02-07 17:40 bug#22586: [PATCH 1/2] Optimise ‘point in message header’ check Michal Nazarewicz
@ 2016-02-07 17:42 ` Michal Nazarewicz
2016-02-09 3:07 ` bug#22586: [PATCH 1/2] Optimise ‘point in message header’ check Lars Ingebrigtsen
1 sibling, 0 replies; 3+ messages in thread
From: Michal Nazarewicz @ 2016-02-07 17:42 UTC (permalink / raw)
To: 22586
* 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#22586: [PATCH 1/2] Optimise ‘point in message header’ check
2016-02-07 17:40 bug#22586: [PATCH 1/2] Optimise ‘point in message header’ check Michal Nazarewicz
2016-02-07 17:42 ` bug#22586: [PATCH 2/2] Make `message-beginning-of-line' aware of folded headers Michal Nazarewicz
@ 2016-02-09 3:07 ` Lars Ingebrigtsen
1 sibling, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-09 3:07 UTC (permalink / raw)
To: Michal Nazarewicz; +Cc: 22586
Thanks; I've applied both patches to the Gnus trunk
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-09 3:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-07 17:40 bug#22586: [PATCH 1/2] Optimise ‘point in message header’ check Michal Nazarewicz
2016-02-07 17:42 ` bug#22586: [PATCH 2/2] Make `message-beginning-of-line' aware of folded headers Michal Nazarewicz
2016-02-09 3:07 ` bug#22586: [PATCH 1/2] Optimise ‘point in message header’ check Lars Ingebrigtsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.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).