Subject: bug#26049: 25.2; Extra lines not added to comment

From: Antonin Houska <[email-masked]>
Date: Mon, 06 Nov 2017 11:14:22 +0100

Noam Postavsky <[email-masked]> wrote:

> tags 26049 + patch
> quit
> 
> Antonin Houska <[email-masked]> writes:
> 
> > The next version of the patch (with string-trim replaced with
> > string-trim-right) is below. Is there anything else I should do?
> 
> Could you please add a commit message (see CONTRIBUTE under "Commit
> messages" for conventions) and post a version produced via 'git
> format-patch' (that way I can grab the patch + commit message
> automagically).

See below.

-- 
Antonin Houska
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt
Web: http://www.postgresql-support.de, http://www.cybertec.at

>From e782404ce76c05076b794e9506049d7ed4c55663 Mon Sep 17 00:00:00 2001
From: Antonin Houska <[email-masked]>
Date: Mon, 6 Nov 2017 09:59:07 +0100
Subject: [PATCH] Handle single-line comments correctly (Bug#26049)

* lisp/newcomment.el: the comment text had to contain at least one
line break for the ending extra line to be added. The behavior seems
more consistent if the end of the comment text is also considered a
line break.

While fixing this, also removed trailing white space from the comment
initial line (/*).

Copyright-paperwork-exempt: yes
---
 lisp/newcomment.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 2e644c3a99..950f3c85b4 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -69,6 +69,9 @@
 
 ;;; Code:
 
+(eval-when-compile
+  (require 'subr-x))
+
 ;;;###autoload
 (defalias 'indent-for-comment 'comment-indent)
 ;;;###autoload
@@ -1141,6 +1144,9 @@ comment-region-internal
 
 	  ;; make the leading and trailing lines if requested
 	  (when lines
+	    ;; Trim trailing whitespace from cs if there's some.
+            (setq cs (string-trim-right cs))
+
 	    (let ((csce
 		   (comment-make-extra-lines
 		    cs ce ccs cce min-indent max-indent block)))
@@ -1211,7 +1217,7 @@ comment-region-default
 	   (progn (goto-char end) (end-of-line) (skip-syntax-backward " ")
 		  (<= (point) end))
 	   (or block (not (string= "" comment-end)))
-	   (or block (progn (goto-char beg) (search-forward "\n" end t)))))
+	   (or block (progn (goto-char beg) (re-search-forward "$" end t)))))
 
     ;; don't add end-markers just because the user asked for `block'
     (unless (or lines (string= "" comment-end)) (setq block nil))
-- 
2.12.3