]> git.eshelyaron.com Git - emacs.git/commitdiff
newcomment.el (comment-line): New command on C-x C-;.
authorArtur Malabarba <bruce.connor.am@gmail.com>
Sun, 8 Feb 2015 21:03:17 +0000 (19:03 -0200)
committerArtur Malabarba <bruce.connor.am@gmail.com>
Sun, 8 Feb 2015 21:03:17 +0000 (19:03 -0200)
lisp/ChangeLog
lisp/bindings.el
lisp/newcomment.el

index b862d42b9613bab4b2e7fe7c724e2120e2f36dd3..64424b74c9507f19b8fbc6cad78ef251f2790138 100644 (file)
@@ -1,3 +1,9 @@
+2015-02-08  Artur Malabarba  <bruce.connor.am@gmail.com>
+
+       * newcomment.el (comment-line): New command.
+
+       * bindings.el (ctl-x-map): Bind to `C-x C-;'.
+
 2015-02-08  Oleh Krehel  <ohwoeowho@gmail.com>
 
        * outline.el (outline-show-entry): Fix one invisible char for the
index 883914ecdc2bb1d8452694b4344f3db151493339..4cc9f6ad3689443f83013e13cc190aec5a9ebbb4 100644 (file)
@@ -1130,6 +1130,7 @@ if `inhibit-field-text-motion' is non-nil."
 (define-key esc-map "j" 'indent-new-comment-line)
 (define-key esc-map "\C-j" 'indent-new-comment-line)
 (define-key ctl-x-map ";" 'comment-set-column)
+(define-key ctl-x-map "C-;" 'comment-line)
 (define-key ctl-x-map "f" 'set-fill-column)
 (define-key ctl-x-map "$" 'set-selective-display)
 
index e307eac94ebced026668bf109ee14edb19410ce4..aabafc76b9a77fd4940481faf48ac2d572566efd 100644 (file)
@@ -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