summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor R Campbell <campbell@mumble.net>2008-10-25 20:18:40 +0000
committerTaylor R Campbell <campbell@mumble.net>2008-10-25 20:18:40 +0000
commite121b9258746d4d947269cab840197c3bbf2391a (patch)
tree7bc2c57879e9b5a9f93acbf08eee1e8037a0afd1
parent0ada66e5c5b62af4f25b97b21e69bfe587912a81 (diff)
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
-rw-r--r--paredit.el49
1 files 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