Created
October 24, 2010 05:04
-
-
Save kiwanami/643125 to your computer and use it in GitHub Desktop.
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
;; kill-region or backward-kill-word | |
(defun kill-region-or-backward-kill-word () | |
(interactive) | |
(if (region-active-p) | |
(kill-region (point) (mark)) | |
(backward-kill-word 1))) | |
;; swap quotes | |
(defvar swap-quotes-list | |
'((?\" ?\') (?\' ?\`) (?\` ?\"))) | |
(defun transpose-chars-or-swap-quotes (arg) | |
(interactive "p") | |
(or (swap-quotes) (transpose-chars arg))) | |
(defun swap-quotes () | |
(interactive) | |
(catch 'break | |
(dolist (i swap-quotes-list) | |
(let ((target-char (car i)) | |
(replaced-char (cadr i)) | |
(prev-pos (point))) | |
(if (= (char-after (point)) target-char) | |
(save-excursion | |
(forward-char 1) | |
(let ((next-pos (re-search-forward (char-to-string target-char)))) | |
(if next-pos | |
(subst-char-in-region prev-pos next-pos target-char replaced-char) | |
(message "The corresponding quote is not found."))) | |
(throw 'break t))))) | |
nil)) | |
(defun kill-word-or-delete-horizontal-space (arg) | |
(interactive "p") | |
(let ((pos (point))) | |
(if (and (not (eobp)) | |
(= (char-syntax (char-after pos)) 32) | |
(= (char-syntax (char-after (1+ pos))) 32)) | |
(prog1 (delete-horizontal-space) | |
(unless (memq (char-after pos) '(?( ?) ?{ ?} ?[ ?])) | |
(insert " "))) | |
(kill-word arg)))) | |
(defun eval-last-sexp-or-region (&optional args) | |
(interactive "P") | |
(let (output-buffer) | |
(if (region-active-p) | |
(eval-region | |
(region-beginning) (region-end) t) | |
(eval-last-sexp args)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment