aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/mail
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-08-15 18:00:08 -0700
committerLars Ingebrigtsen2019-08-15 18:00:16 -0700
commitab8a96977f6fc91d9a6ba4fe8a2a959c0525e339 (patch)
tree1459a869b914210bba0b4e5800c3fc8a5b9ee109 /lisp/mail
parent1ee0192b792124663a0a40a729dd83c047d21535 (diff)
downloademacs-ab8a96977f6fc91d9a6ba4fe8a2a959c0525e339.tar.gz
emacs-ab8a96977f6fc91d9a6ba4fe8a2a959c0525e339.zip
Reimplement the `fill-flowed' function to respect space stuffing
* lisp/mail/flow-fill.el (fill-flowed): Reimplement the function to respect space-stuffing (bug#17190). * test/lisp/mail/flow-fill-tests.el (fill-flow-tests-fill-flowed-stuffed): New test. (fill-flow-tests-fill-flowed-decode): Rename the test so that it actually runs.
Diffstat (limited to 'lisp/mail')
-rw-r--r--lisp/mail/flow-fill.el92
1 files changed, 43 insertions, 49 deletions
diff --git a/lisp/mail/flow-fill.el b/lisp/mail/flow-fill.el
index 948a7d799f5..7b50fcd96e0 100644
--- a/lisp/mail/flow-fill.el
+++ b/lisp/mail/flow-fill.el
@@ -120,55 +120,49 @@ If BUFFER is nil, default to the current buffer.
120If DELETE-SPACE, delete RFC2646 spaces padding at the end of 120If DELETE-SPACE, delete RFC2646 spaces padding at the end of
121lines." 121lines."
122 (with-current-buffer (or buffer (current-buffer)) 122 (with-current-buffer (or buffer (current-buffer))
123 (goto-char (point-min)) 123 (let ((fill-column (eval fill-flowed-display-column)))
124 ;; Remove space stuffing. 124 (goto-char (point-min))
125 (while (re-search-forward "^\\( \\|>+ $\\)" nil t) 125 (while (not (eobp))
126 (delete-char -1) 126 (cond
127 (forward-line 1)) 127 ((and (looking-at "^>+")
128 (goto-char (point-min)) 128 (eq (char-before (line-end-position)) ?\s))
129 (while (re-search-forward " $" nil t) 129 (let ((prefix (match-string 0)))
130 (when (save-excursion 130 ;; Insert a space character after the quote signs for more
131 (beginning-of-line) 131 ;; pleasant reading of quoted lines.
132 (looking-at "^\\(>*\\)\\( ?\\)")) 132 (goto-char (match-end 0))
133 (let ((quote (match-string 1)) 133 (unless (looking-at " ")
134 sig) 134 (insert " "))
135 (if (string= quote "") 135 (end-of-line)
136 (setq quote nil)) 136 (when (and (not (eobp))
137 (when (and quote (string= (match-string 2) "")) 137 (save-excursion
138 (save-excursion 138 (forward-line 1)
139 ;; insert SP after quote for pleasant reading of quoted lines 139 (looking-at (format "\\(%s ?\\)[^>]" prefix))))
140 (beginning-of-line) 140 ;; Delete the newline and the quote at the start of the
141 (when (> (skip-chars-forward ">") 0) 141 ;; next line.
142 (insert " ")))) 142 (delete-region (point) (match-end 1))
143 ;; XXX slightly buggy handling of "-- " 143 (ignore-errors
144 (while (and (save-excursion 144 (let ((fill-prefix (concat prefix " "))
145 (ignore-errors (backward-char 3)) 145 adaptive-fill-mode)
146 (setq sig (looking-at "-- ")) 146 (fill-region (line-beginning-position)
147 (looking-at "[^-][^-] ")) 147 (line-end-position)
148 (save-excursion 148 'left 'nosqueeze))))))
149 (unless (eobp) 149 (t
150 (forward-char 1) 150 ;; Delete the newline.
151 (looking-at (format "^\\(%s\\)\\([^>\n\r]\\)" 151 (when (eq (following-char) ?\s)
152 (or quote " ?")))))) 152 (delete-char 1))
153 (save-excursion 153 ;; Hack: Don't do the flowing on the signature line.
154 (replace-match (if (string= (match-string 2) " ") 154 (when (and (not (looking-at "-- $"))
155 "" "\\2"))) 155 (eq (char-before (line-end-position)) ?\s))
156 (backward-delete-char -1) 156 (end-of-line)
157 (when delete-space 157 (when delete-space
158 (delete-char -1)) 158 (delete-char -1))
159 (end-of-line)) 159 (delete-char 1)
160 (unless sig 160 (ignore-errors
161 (condition-case nil 161 (let ((fill-prefix ""))
162 (let ((fill-prefix (when quote (concat quote " "))) 162 (fill-region (line-beginning-position)
163 (fill-column (eval fill-flowed-display-column)) 163 (line-end-position)
164 adaptive-fill-mode) 164 'left 'nosqueeze))))))
165 (fill-region (point-at-bol) 165 (forward-line 1)))))
166 (min (1+ (point-at-eol))
167 (point-max))
168 'left 'nosqueeze))
169 (error
170 (forward-line 1)
171 nil))))))))
172 166
173(make-obsolete-variable 'fill-flowed-encode-tests nil "27.1") 167(make-obsolete-variable 'fill-flowed-encode-tests nil "27.1")
174(defvar fill-flowed-encode-tests) 168(defvar fill-flowed-encode-tests)