summaryrefslogtreecommitdiff
path: root/lisp/newcomment.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2014-04-10 21:05:03 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2014-04-10 21:05:03 -0400
commit0d6a1375afcf2204f465d12ba5dc903cd0a9eb2e (patch)
treebdb8bd9d3c28f3f7d2020eed72776fc4b8b9eb1e /lisp/newcomment.el
parentfb2dcc3567ca762f05b452bb9edd27da33322f70 (diff)
downloademacs-0d6a1375afcf2204f465d12ba5dc903cd0a9eb2e.tar.gz
* lisp/newcomment.el (comment-indent-new-line): Sink code where it's used.
Reuse the previous comment's indentation unconditionally if it's on its own line.
Diffstat (limited to 'lisp/newcomment.el')
-rw-r--r--lisp/newcomment.el57
1 files changed, 35 insertions, 22 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 2d798494b8b..b607eb95df2 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -1390,22 +1390,12 @@ unless optional argument SOFT is non-nil."
;; If we're not inside a comment, just try to indent.
((not compos) (indent-according-to-mode))
(t
- (let* ((comment-column
- ;; The continuation indentation should be somewhere between
- ;; the current line's indentation (plus 2 for good measure)
- ;; and the current comment's indentation, with a preference
- ;; for comment-column.
- (save-excursion
- ;; FIXME: use prev line's info rather than first line's.
- (goto-char compos)
- (min (current-column) (max comment-column
- (+ 2 (current-indentation))))))
- (comstart (buffer-substring compos comin))
+ (let* ((comstart (buffer-substring compos comin))
(normalp
(string-match (regexp-quote (comment-string-strip
comment-start t t))
comstart))
- (comment-end
+ (comend
(if normalp comment-end
;; The comment starter is not the normal comment-start
;; so we can't just use comment-end.
@@ -1416,19 +1406,42 @@ unless optional argument SOFT is non-nil."
(buffer-substring
(save-excursion (comment-enter-backward) (point))
(point))
- nil t)))))
- (comment-start comstart)
- (continuep (or comment-multi-line
- (cadr (assoc comment-style comment-styles))))
- ;; Force comment-continue to be recreated from comment-start.
- ;; FIXME: wrong if comment-continue was set explicitly!
- ;; FIXME: use prev line's continuation if available.
- (comment-continue nil))
- (if (and comment-multi-line (> (length comment-end) 0))
+ nil t))))))
+ (if (and comment-multi-line (> (length comend) 0))
(indent-according-to-mode)
(insert-and-inherit ?\n)
(forward-char -1)
- (comment-indent continuep)
+ (let* ((comment-column
+ ;; The continuation indentation should be somewhere
+ ;; between the current line's indentation (plus 2 for
+ ;; good measure) and the current comment's indentation,
+ ;; with a preference for comment-column.
+ (save-excursion
+ ;; FIXME: use prev line's info rather than first
+ ;; line's.
+ (goto-char compos)
+ (min (current-column)
+ (max comment-column
+ (+ 2 (current-indentation))))))
+ (comment-indent-function
+ ;; If the previous comment is on its own line, then
+ ;; reuse its indentation unconditionally.
+ ;; Important for modes like Python/Haskell where
+ ;; auto-indentation is unreliable.
+ (if (save-excursion (goto-char compos)
+ (skip-chars-backward " \t")
+ (bolp))
+ (lambda () comment-column) comment-indent-function))
+ (comment-start comstart)
+ (comment-end comend)
+ (continuep (or comment-multi-line
+ (cadr (assoc comment-style
+ comment-styles))))
+ ;; Recreate comment-continue from comment-start.
+ ;; FIXME: wrong if comment-continue was set explicitly!
+ ;; FIXME: use prev line's continuation if available.
+ (comment-continue nil))
+ (comment-indent continuep))
(save-excursion
(let ((pt (point)))
(end-of-line)