diff options
| author | Lars Ingebrigtsen | 2019-08-15 18:00:08 -0700 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-08-15 18:00:16 -0700 |
| commit | ab8a96977f6fc91d9a6ba4fe8a2a959c0525e339 (patch) | |
| tree | 1459a869b914210bba0b4e5800c3fc8a5b9ee109 | |
| parent | 1ee0192b792124663a0a40a729dd83c047d21535 (diff) | |
| download | emacs-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.
| -rw-r--r-- | lisp/mail/flow-fill.el | 92 | ||||
| -rw-r--r-- | test/lisp/mail/flow-fill-tests.el | 16 |
2 files changed, 58 insertions, 50 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. | |||
| 120 | If DELETE-SPACE, delete RFC2646 spaces padding at the end of | 120 | If DELETE-SPACE, delete RFC2646 spaces padding at the end of |
| 121 | lines." | 121 | lines." |
| 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) |
diff --git a/test/lisp/mail/flow-fill-tests.el b/test/lisp/mail/flow-fill-tests.el index a05950bb70a..2dd516b91d1 100644 --- a/test/lisp/mail/flow-fill-tests.el +++ b/test/lisp/mail/flow-fill-tests.el | |||
| @@ -24,7 +24,7 @@ | |||
| 24 | (require 'ert) | 24 | (require 'ert) |
| 25 | (require 'flow-fill) | 25 | (require 'flow-fill) |
| 26 | 26 | ||
| 27 | (ert-deftest fill-flow-tests-fill-flowed-encode () | 27 | (ert-deftest fill-flow-tests-fill-flowed-decode () |
| 28 | (let ((input | 28 | (let ((input |
| 29 | (concat | 29 | (concat |
| 30 | "> Thou villainous ill-breeding spongy dizzy-eyed \n" | 30 | "> Thou villainous ill-breeding spongy dizzy-eyed \n" |
| @@ -53,6 +53,7 @@ | |||
| 53 | (with-temp-buffer | 53 | (with-temp-buffer |
| 54 | (insert input) | 54 | (insert input) |
| 55 | (fill-flowed) | 55 | (fill-flowed) |
| 56 | (message "foo") | ||
| 56 | (should (equal (buffer-string) output))))) | 57 | (should (equal (buffer-string) output))))) |
| 57 | 58 | ||
| 58 | (ert-deftest fill-flow-tests-fill-flowed-encode () | 59 | (ert-deftest fill-flow-tests-fill-flowed-encode () |
| @@ -88,5 +89,18 @@ | |||
| 88 | (fill-flowed-encode) | 89 | (fill-flowed-encode) |
| 89 | (should (equal (buffer-string) output))))) | 90 | (should (equal (buffer-string) output))))) |
| 90 | 91 | ||
| 92 | (ert-deftest fill-flow-tests-fill-flowed-stuffed () | ||
| 93 | (let ((input | ||
| 94 | (concat | ||
| 95 | " > From space-stuffed with a \n" | ||
| 96 | "continuation.\n")) | ||
| 97 | (output | ||
| 98 | "> From space-stuffed with a continuation.\n") | ||
| 99 | (fill-flowed-display-column 69)) | ||
| 100 | (with-temp-buffer | ||
| 101 | (insert input) | ||
| 102 | (fill-flowed) | ||
| 103 | (should (equal (buffer-string) output))))) | ||
| 104 | |||
| 91 | (provide 'flow-fill-tests) | 105 | (provide 'flow-fill-tests) |
| 92 | ;;; flow-fill-tests.el ends here | 106 | ;;; flow-fill-tests.el ends here |