Last active
October 31, 2015 05:48
-
-
Save alphapapa/fd7edf8104215028f3da 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
(defun change-inner (prefix character) | |
"Kill region inside delimiters, using either beginning or | |
ending delimiter. With prefix arg, kill including delimiters." | |
(interactive "p\nc") | |
(let ((initial-point (point)) | |
(start) | |
(end) | |
(move-point-by (if (> prefix 1) 0 1))) | |
(condition-case nil | |
(progn | |
;; Search forward for given char | |
(search-forward (char-to-string character)) | |
(setq end (- (point) move-point-by)) | |
(condition-case nil | |
(backward-sexp) | |
(error (backward-list))) | |
(setq start (+ (point) move-point-by)) | |
(kill-region start end) | |
(or prefix (forward-char))) | |
(error (progn | |
;; Reset and search backward for given char | |
(goto-char initial-point) | |
(search-backward (char-to-string character)) | |
(setq start (+ (point) move-point-by)) | |
(condition-case nil | |
(forward-list) | |
(error (forward-sexp)))) | |
(setq end (- (point) move-point-by)) | |
(kill-region start end) | |
(or prefix (backward-char)))))) | |
(defun change-outer () | |
(interactive) | |
(let ((current-prefix-arg '(4))) | |
(call-interactively 'change-inner))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment