From 35d58020b6e173b137429786d174ffdb8894a812 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Sun, 20 Mar 2016 12:52:28 +0100 Subject: [PATCH] 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. --- lisp/net/shr.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 (set-window-hscroll nil 0) (shr-descend dom) (shr-fill-lines start (point)) + (shr--remove-blank-lines-at-the-end start (point)) (shr-remove-trailing-whitespace start (point)) (when shr-warning (message "%s" shr-warning)))) +(defun shr--remove-blank-lines-at-the-end (start end) + (save-restriction + (save-excursion + (current-buffer) + (narrow-to-region start end) + (goto-char end) + (when (and (re-search-backward "[^ \n]" nil t) + (not (eobp))) + (forward-char 1) + (delete-region (point) (point-max)) + (unless (bolp) + (insert "\n")))))) + (defun shr-remove-trailing-whitespace (start end) (let ((width (window-width))) (save-restriction -- 2.39.2