emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/paredit e121b92 024/224: Clarify `paredit-insert-comment'


From: ELPA Syncer
Subject: [nongnu] elpa/paredit e121b92 024/224: Clarify `paredit-insert-comment' and change its criteria for code comments.
Date: Sat, 7 Aug 2021 09:22:10 -0400 (EDT)

branch: elpa/paredit
commit e121b9258746d4d947269cab840197c3bbf2391a
Author: Taylor R Campbell <campbell@mumble.net>
Commit: Taylor R Campbell <campbell@mumble.net>

    Clarify `paredit-insert-comment' and change its criteria for code comments.
    
    Formerly, this would choose code comments only when code follow the
    point on the line.  Now it will insert code comments also when no
    code precede the point on the line.  For example, the command will
    choose a code comment rather than a margin comment in the following
    fragment:
    
       (foo bar
            |baz
            quux)
    =>
       (foo bar
            ;; |
            baz
            quux)
    
    darcs-hash:20081025201840-00fcc-0435e69b7e5e42c43a763dad345c0f8a25925b89
---
 paredit.el | 49 +++++++++++++++++++++----------------------------
 1 file changed, 21 insertions(+), 28 deletions(-)

diff --git a/paredit.el b/paredit.el
index 6c705a0..73a9d51 100644
--- a/paredit.el
+++ b/paredit.el
@@ -1065,35 +1065,28 @@ This is expected to be called only in 
`paredit-comment-dwim'; do not
         (code-before-p
          (save-excursion (paredit-skip-whitespace nil (point-at-bol))
                          (not (bolp)))))
-    (if (and (bolp)
-             ;; We have to use EQ 0 here and not ZEROP because ZEROP
-             ;; signals an error if its argument is non-numeric, but
-             ;; CALCULATE-LISP-INDENT may return nil.
-             (eq (let ((indent (calculate-lisp-indent)))
-                   (if (consp indent)
-                       (car indent)
-                     indent))
-                 0))
-        ;; Top-level comment
-        (progn (if code-after-p (save-excursion (newline)))
-               (insert ";;; "))
-      (if code-after-p
-          ;; Code comment
-          (progn (if code-before-p
-                     ;++ Why NEWLINE-AND-INDENT here and not just
-                     ;++ NEWLINE, or PAREDIT-NEWLINE?
-                     (newline-and-indent))
+    (cond ((and (bolp)
+                (let ((indent
+                       (let ((indent (calculate-lisp-indent)))
+                         (if (consp indent) (car indent) indent))))
+                  (and indent (zerop indent))))
+           ;; Top-level comment
+           (if code-after-p (save-excursion (newline)))
+           (insert ";;; "))
+          ((or code-after-p (not code-before-p))
+           ;; Code comment
+           (if code-before-p (newline))
+           (lisp-indent-line)
+           (insert ";; ")
+           (if code-after-p
+               (save-excursion
+                 (newline)
                  (lisp-indent-line)
-                 (insert ";; ")
-                 ;; Move the following code.  (NEWLINE-AND-INDENT will
-                 ;; delete whitespace after the comment, though, so use
-                 ;; NEWLINE & LISP-INDENT-LINE manually here.)
-                 (save-excursion (newline)
-                                 (lisp-indent-line)))
-          ;; Margin comment
-          (progn (indent-to comment-column
-                            1)          ; 1 -> force one leading space
-                 (insert ?\; ))))))
+                 (indent-sexp))))
+          (t
+           ;; Margin comment
+           (indent-to comment-column 1) ; 1 -> force one leading space
+           (insert ?\; )))))
 
 ;;;; Character Deletion
 



reply via email to

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