Created
February 18, 2012 14:40
-
-
Save benhsu/1859587 to your computer and use it in GitHub Desktop.
emacs code to operate on a region or line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; stab at generalizing this | |
(defun line-or-region-wrapper (func) | |
(interactive) | |
(if (region-active-p) | |
(funcall func (region-beginning) (region-end)) | |
(funcall func (line-beginning-position) (line-end-position)))) | |
(defun comment-or-uncomment-line-or-region () | |
(interactive) | |
(line-or-region-wrapper 'comment-or-uncomment-region)) | |
(defun indent-line-or-region () | |
(interactive) | |
(line-or-region-wrapper 'indent-region)) | |
(defun kill-line-or-region () | |
(interactive) | |
(if (region-active-p) | |
(kill-region) | |
(kill-line ))) | |
(global-set-key (kbd "C-;") 'comment-or-uncomment-line-or-region) | |
(global-set-key (kbd "C-w") 'kill-line-or-region) | |
;; from http://stackoverflow.com/questions/916797/emacs-global-set-key-to-c-tab | |
(global-set-key (kbd "<C-tab>") 'indent-line-or-region) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment