diff options
| author | Michal Nazarewicz | 2016-06-21 16:52:52 +0200 |
|---|---|---|
| committer | Michal Nazarewicz | 2016-07-04 23:44:06 +0200 |
| commit | dc294483af221066724f1007a595016b47fb5814 (patch) | |
| tree | e81eb0d46998ec2d634de6d6df64c346ca63fb0b | |
| parent | e3ae3c44882085bf52f6bb8b02e98eb7d0b1f81b (diff) | |
| download | emacs-dc294483af221066724f1007a595016b47fb5814.tar.gz emacs-dc294483af221066724f1007a595016b47fb5814.zip | |
Make ‘delete-trailing-whitespace’ delete spaces after form feed
* lisp/simple.el (delete-trailing-whitespace): Treat form fead as
a non-whitespace character (regradless of whether it’s character syntax
is whitespace) and delete any whitespace following it instead of leaving
lines with form feeds completely unchanged. I.e. a line like "\f " will
now became "\f".
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/simple.el | 15 | ||||
| -rw-r--r-- | test/lisp/simple-tests.el | 17 |
3 files changed, 28 insertions, 10 deletions
| @@ -187,6 +187,12 @@ questions, with a handy way to display help texts. | |||
| 187 | 'undo', undo the last replacement; bound to 'u'. | 187 | 'undo', undo the last replacement; bound to 'u'. |
| 188 | 'undo-all', undo all replacements; bound to 'U'. | 188 | 'undo-all', undo all replacements; bound to 'U'. |
| 189 | 189 | ||
| 190 | ** 'delete-trailing-whitespace' deletes whitespace after form feed. | ||
| 191 | In modes where form feed was treated as a whitespace character, | ||
| 192 | 'delete-trailing-whitespace' would keep lines containing it unchanged. | ||
| 193 | It now deletes whitespace after the last form feed thus behaving the | ||
| 194 | same as in modes where the character is not whitespace. | ||
| 195 | |||
| 190 | 196 | ||
| 191 | * Changes in Specialized Modes and Packages in Emacs 25.2 | 197 | * Changes in Specialized Modes and Packages in Emacs 25.2 |
| 192 | 198 | ||
diff --git a/lisp/simple.el b/lisp/simple.el index 0da70976ed5..3fa23ff9477 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -602,15 +602,14 @@ buffer if the variable `delete-trailing-lines' is non-nil." | |||
| 602 | (list nil nil)))) | 602 | (list nil nil)))) |
| 603 | (save-match-data | 603 | (save-match-data |
| 604 | (save-excursion | 604 | (save-excursion |
| 605 | (let ((end-marker (copy-marker (or end (point-max)))) | 605 | (let ((end-marker (copy-marker (or end (point-max))))) |
| 606 | (start (or start (point-min)))) | 606 | (goto-char (or start (point-min))) |
| 607 | (goto-char start) | 607 | (with-syntax-table (make-syntax-table (syntax-table)) |
| 608 | (while (re-search-forward "\\s-$" end-marker t) | ||
| 609 | (skip-syntax-backward "-" (line-beginning-position)) | ||
| 610 | ;; Don't delete formfeeds, even if they are considered whitespace. | 608 | ;; Don't delete formfeeds, even if they are considered whitespace. |
| 611 | (if (looking-at-p ".*\f") | 609 | (modify-syntax-entry ?\f "_") |
| 612 | (goto-char (match-end 0))) | 610 | (while (re-search-forward "\\s-$" end-marker t) |
| 613 | (delete-region (point) (match-end 0))) | 611 | (skip-syntax-backward "-" (line-beginning-position)) |
| 612 | (delete-region (point) (match-end 0)))) | ||
| 614 | ;; Delete trailing empty lines. | 613 | ;; Delete trailing empty lines. |
| 615 | (goto-char end-marker) | 614 | (goto-char end-marker) |
| 616 | (when (and (not end) | 615 | (when (and (not end) |
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el index 40cd1d29498..2722544446d 100644 --- a/test/lisp/simple-tests.el +++ b/test/lisp/simple-tests.el | |||
| @@ -204,7 +204,7 @@ | |||
| 204 | 204 | ||
| 205 | 205 | ||
| 206 | ;;; `delete-trailing-whitespace' | 206 | ;;; `delete-trailing-whitespace' |
| 207 | (ert-deftest simple-delete-trailing-whitespace () | 207 | (ert-deftest simple-delete-trailing-whitespace--bug-21766 () |
| 208 | "Test bug#21766: delete-whitespace sometimes deletes non-whitespace." | 208 | "Test bug#21766: delete-whitespace sometimes deletes non-whitespace." |
| 209 | (defvar python-indent-guess-indent-offset) ; to avoid a warning | 209 | (defvar python-indent-guess-indent-offset) ; to avoid a warning |
| 210 | (let ((python (featurep 'python)) | 210 | (let ((python (featurep 'python)) |
| @@ -219,11 +219,24 @@ | |||
| 219 | "\n" | 219 | "\n" |
| 220 | "\n")) | 220 | "\n")) |
| 221 | (delete-trailing-whitespace) | 221 | (delete-trailing-whitespace) |
| 222 | (should (equal (count-lines (point-min) (point-max)) 3))) | 222 | (should (string-equal (buffer-string) |
| 223 | (concat "query = \"\"\"WITH filtered AS\n" | ||
| 224 | "WHERE\n" | ||
| 225 | "\"\"\".format(fv_)\n")))) | ||
| 223 | ;; Let's clean up if running interactive | 226 | ;; Let's clean up if running interactive |
| 224 | (unless (or noninteractive python) | 227 | (unless (or noninteractive python) |
| 225 | (unload-feature 'python))))) | 228 | (unload-feature 'python))))) |
| 226 | 229 | ||
| 230 | (ert-deftest simple-delete-trailing-whitespace--formfeeds () | ||
| 231 | "Test formfeeds are not deleted but whitespace past them is." | ||
| 232 | (with-temp-buffer | ||
| 233 | (with-syntax-table (make-syntax-table) | ||
| 234 | (modify-syntax-entry ?\f " ") ; Make sure \f is whitespace | ||
| 235 | (insert " \f \n \f \f \n\nlast\n") | ||
| 236 | (delete-trailing-whitespace) | ||
| 237 | (should (string-equal (buffer-string) " \f\n \f \f\n\nlast\n")) | ||
| 238 | (should (equal ?\s (char-syntax ?\f)))))) | ||
| 239 | |||
| 227 | 240 | ||
| 228 | ;;; auto-boundary tests | 241 | ;;; auto-boundary tests |
| 229 | (ert-deftest undo-auto-boundary-timer () | 242 | (ert-deftest undo-auto-boundary-timer () |