diff options
| author | Lars Magne Ingebrigtsen | 2016-03-20 12:52:28 +0100 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2016-03-20 12:52:28 +0100 |
| commit | 35d58020b6e173b137429786d174ffdb8894a812 (patch) | |
| tree | 9afce62981d0c90e8fe3095b294a07e1892c66f6 | |
| parent | 0b7836dda668a64577778d05ce02d65301bb631b (diff) | |
| download | emacs-35d58020b6e173b137429786d174ffdb8894a812.tar.gz emacs-35d58020b6e173b137429786d174ffdb8894a812.zip | |
Remove trailing blank lines in shr
* lisp/net/shr.el (shr--remove-blank-lines-at-the-end): New function.
(shr-insert-document): Use it to remove trailing blank lines
at the end of documents, since these never seem to be very useful.
| -rw-r--r-- | lisp/net/shr.el | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el index 3877719d7a7..6bb6898188d 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el | |||
| @@ -274,10 +274,24 @@ DOM should be a parse tree as generated by | |||
| 274 | (set-window-hscroll nil 0) | 274 | (set-window-hscroll nil 0) |
| 275 | (shr-descend dom) | 275 | (shr-descend dom) |
| 276 | (shr-fill-lines start (point)) | 276 | (shr-fill-lines start (point)) |
| 277 | (shr--remove-blank-lines-at-the-end start (point)) | ||
| 277 | (shr-remove-trailing-whitespace start (point)) | 278 | (shr-remove-trailing-whitespace start (point)) |
| 278 | (when shr-warning | 279 | (when shr-warning |
| 279 | (message "%s" shr-warning)))) | 280 | (message "%s" shr-warning)))) |
| 280 | 281 | ||
| 282 | (defun shr--remove-blank-lines-at-the-end (start end) | ||
| 283 | (save-restriction | ||
| 284 | (save-excursion | ||
| 285 | (current-buffer) | ||
| 286 | (narrow-to-region start end) | ||
| 287 | (goto-char end) | ||
| 288 | (when (and (re-search-backward "[^ \n]" nil t) | ||
| 289 | (not (eobp))) | ||
| 290 | (forward-char 1) | ||
| 291 | (delete-region (point) (point-max)) | ||
| 292 | (unless (bolp) | ||
| 293 | (insert "\n")))))) | ||
| 294 | |||
| 281 | (defun shr-remove-trailing-whitespace (start end) | 295 | (defun shr-remove-trailing-whitespace (start end) |
| 282 | (let ((width (window-width))) | 296 | (let ((width (window-width))) |
| 283 | (save-restriction | 297 | (save-restriction |