summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-03-24 01:02:59 -0400
committerKyle Meyer <kyle@kyleam.com>2015-03-24 01:02:59 -0400
commit4a5410cbfea937f585a07f0b01c328b44820716b (patch)
tree697892302cfd70d91b67f8293f5adb03c1f54a18
parent8eebc46e129d2f32597d9e58772af2aac4a86d26 (diff)
downloademacs.d-4a5410cbfea937f585a07f0b01c328b44820716b.tar.gz
Update toggle-line-or-region-comment
These modifications are based off of Drew Adam's comment function [1]. The main change in behavior from my old function is that whole lines of the region are commented even when the beginning or end of the region is not at the beginning or end of the line. [1] http://permalink.gmane.org/gmane.emacs.devel/181816
-rw-r--r--lisp/init-editing.el24
1 files changed, 15 insertions, 9 deletions
diff --git a/lisp/init-editing.el b/lisp/init-editing.el
index eb6adf3..c13df37 100644
--- a/lisp/init-editing.el
+++ b/lisp/init-editing.el
@@ -115,15 +115,21 @@ and '<<<' mark the bounds of the narrowed region.
(outline-mark-subtree)
(narrow-to-region (region-beginning) (region-end)))))
-(defun km/toggle-line-or-region-comment ()
- "Comment/uncomment the current line or region."
- (interactive)
- (let (beg end)
- (if (region-active-p)
- (setq beg (region-beginning) end (region-end))
- (setq beg (line-beginning-position) end (line-end-position)))
- (comment-or-uncomment-region beg end))
- (forward-line))
+(defun km/toggle-line-or-region-comment (beg end)
+ "Comment or uncomment the current line or region.
+If there is an active region, act on all lines that the region
+touches."
+ (interactive "*r")
+ (unless (use-region-p)
+ (setq beg (point)
+ end (point)))
+ (let ((bol (save-excursion (goto-char beg)
+ (line-beginning-position)))
+ (eol (save-excursion (goto-char end)
+ (line-end-position))))
+ (unless (eq bol eol)
+ (comment-or-uncomment-region bol eol)
+ (forward-line))))
;; Modified from http://oremacs.com/2015/01/26/occur-dwim/.
(defun km/occur ()