summaryrefslogtreecommitdiff
path: root/lisp/newcomment.el
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-02-08 19:03:17 -0200
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-02-08 19:03:17 -0200
commit97cb255360172980e7b79ed6a8cb35abbc58f897 (patch)
treeb3067683f9ab3ff500584c2d40c4ccb40f740aa0 /lisp/newcomment.el
parent61320cc95ca14ec282bb73307e9006fb1d6e7e80 (diff)
downloademacs-97cb255360172980e7b79ed6a8cb35abbc58f897.tar.gz
newcomment.el (comment-line): New command on C-x C-;.
Diffstat (limited to 'lisp/newcomment.el')
-rw-r--r--lisp/newcomment.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index e307eac94eb..aabafc76b9a 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -1451,6 +1451,38 @@ unless optional argument SOFT is non-nil."
(end-of-line 0)
(insert comend))))))))))))
+;;;###autoload
+(defun comment-line (n)
+ "Comment or uncomment current line and leave point after it.
+With positive prefix, apply to N lines including current one.
+With negative prefix, apply to -N lines above. Also, further
+consecutive invocations of this command will inherit the negative
+argument.
+
+If region is active, comment lines in active region instead.
+Unlike `comment-dwim', this always comments whole lines."
+ (interactive "p")
+ (if (use-region-p)
+ (comment-or-uncomment-region
+ (save-excursion
+ (goto-char (region-beginning))
+ (line-beginning-position))
+ (save-excursion
+ (goto-char (region-end))
+ (line-end-position)))
+ (when (and (eq last-command 'comment-line-backward)
+ (natnump n))
+ (setq n (- n)))
+ (let ((range
+ (list (line-beginning-position)
+ (goto-char (line-end-position n)))))
+ (comment-or-uncomment-region
+ (apply #'min range)
+ (apply #'max range)))
+ (forward-line 1)
+ (back-to-indentation)
+ (unless (natnump n) (setq this-command 'comment-line-backward)))
+
(provide 'newcomment)
;;; newcomment.el ends here