emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r116965: * lisp/newcomment.el (comment-indent-new-li


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r116965: * lisp/newcomment.el (comment-indent-new-line): Sink code where it's used.
Date: Fri, 11 Apr 2014 01:05:09 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 116965
revision-id: address@hidden
parent: address@hidden
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Thu 2014-04-10 21:05:03 -0400
message:
  * 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.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/newcomment.el             
newcomment.el-20091113204419-o5vbwnq5f7feedwu-1719
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-04-09 16:58:08 +0000
+++ b/lisp/ChangeLog    2014-04-11 01:05:03 +0000
@@ -1,3 +1,9 @@
+2014-04-11  Stefan Monnier  <address@hidden>
+
+       * 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.
+
 2014-04-09  Daniel Colascione  <address@hidden>
 
        * emacs-lisp/lisp.el (backward-up-list): Add `escape-strings',

=== modified file 'lisp/newcomment.el'
--- a/lisp/newcomment.el        2014-03-18 06:06:33 +0000
+++ b/lisp/newcomment.el        2014-04-11 01:05:03 +0000
@@ -1390,22 +1390,12 @@
         ;; 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 @@
                         (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)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]