Fix numerical `comment-padding' value

* lisp/newcomment.el (comment-padright): Allow using a number for
`comment-padding', like the doc string says (bug#40056).
This commit is contained in:
Lars Ingebrigtsen 2021-01-28 09:57:48 +01:00
parent 8992f8abf3
commit 64d4648869

View file

@ -832,12 +832,17 @@ Ensure that `comment-normalize-vars' has been called before you use this."
(when (and (stringp str) (string-match "\\S-" str))
;; Separate the actual string from any leading/trailing padding
(string-match "\\`\\s-*\\(.*?\\)\\s-*\\'" str)
(let ((s (match-string 1 str)) ;actual string
(let ((s (match-string 1 str)) ;actual string
(lpad (substring str 0 (match-beginning 1))) ;left padding
(rpad (concat (substring str (match-end 1)) ;original right padding
(substring comment-padding ;additional right padding
(min (- (match-end 0) (match-end 1))
(length comment-padding)))))
(rpad (concat
(substring str (match-end 1)) ;original right padding
(if (numberp comment-padding)
(make-string (min comment-padding
(- (match-end 0) (match-end 1)))
?\s)
(substring comment-padding ;additional right padding
(min (- (match-end 0) (match-end 1))
(length comment-padding))))))
;; We can only duplicate C if the comment-end has multiple chars
;; or if comments can be nested, else the comment-end `}' would
;; be turned into `}}}' where only the first ends the comment
@ -852,7 +857,7 @@ Ensure that `comment-normalize-vars' has been called before you use this."
(concat (mapconcat (lambda (c) (concat (regexp-quote (string c)) "?"))
lpad "") ;padding is not required
(regexp-quote s)
(when multi "+") ;the last char of S might be repeated
(when multi "+") ;the last char of S might be repeated
(mapconcat (lambda (c) (concat (regexp-quote (string c)) "?"))
rpad "")))))) ;padding is not required