Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tweak commenting/uncommenting to accept a line

Known as TextMate-style commenting[1], this methodology of tweaking
comment-or-uncomment-region to accept a line was taken from Chris
Wanstrath's textmate.el.

[1]: http://bclennox.com/textmate-style-commenting-in-bbedit
  • Loading branch information...
commit 6c3bb5ec0704a3805b05409af281ea033ceea76a 1 parent 104418d
@andrewsardone authored
View
25 modules/aps-core.el
@@ -63,4 +63,29 @@
(interactive)
(insert (aps-uuid-create)))
+(defmacro allow-line-as-region-for-function (orig-function)
+ "Adds an *-or-line version of the given function that
+normally requires region arguments.
+
+This code comes from Aquamac's osxkeys.el and is licensed under
+the GPL."
+`(defun ,(intern (concat (symbol-name orig-function) "-or-line"))
+ ()
+ ,(format "Like `%s', but acts on the current line if mark is not active."
+ orig-function)
+ (interactive)
+ (if mark-active
+ (call-interactively (function ,orig-function))
+ (save-excursion
+ ;; define a region (temporarily) -- so any C-u prefixes etc. are preserved.
+ (beginning-of-line)
+ (set-mark (point))
+ (end-of-line)
+ (call-interactively (function ,orig-function))))))
+
+;; taken from Chris Wanstrath's textmate.el
+(defun aps-define-comment-or-uncomment-line ()
+ (unless (fboundp 'comment-or-uncomment-region-or-line)
+ (allow-line-as-region-for-function comment-or-uncomment-region)))
+
(provide 'aps-core)
View
3  modules/aps-editor.el
@@ -72,4 +72,7 @@
;; narrow-to-defun C-x n d
(put 'narrow-to-region 'disabled nil)
+;; enable sensible commenting/uncommenting
+(aps-define-comment-or-uncomment-line)
+
(provide 'aps-editor)
View
8 modules/aps-global-keybindings.el
@@ -33,6 +33,14 @@
(global-unset-key (kbd "C-\-"))
(global-set-key (kbd "C-\-") 'undo)
+;; comment or uncomment
+;; removes the default C-/ keybinding for `undo', but I already
+;; use the default C-x u or my custom C--
+(global-unset-key (kbd "C-/"))
+(global-set-key (kbd "C-/") 'comment-or-uncomment-region-or-line)
+(if (eq system-type 'darwin)
+ (global-set-key (kbd "s-/") 'comment-or-uncomment-region-or-line))
+
;; use hippie-expand instead of dabbrev
(global-set-key (kbd "M-/") 'hippie-expand)
Please sign in to comment.
Something went wrong with that request. Please try again.