Created
August 18, 2010 21:08
-
-
Save zzamboni/536198 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
; One of my recent favorite pieces of Emacs configuration. The % command was one of the things I missed the | |
; most in Emacs, until I found this little gem. I modified it from its original source by adding | |
; previous-line and next-line to the list of commands. | |
; From http://www.emacswiki.org/emacs/ParenthesisMatching#toc4 | |
(defun goto-match-paren (arg) | |
"Go to the matching parenthesis if on parenthesis AND last command is a movement command, otherwise insert %. | |
vi style of % jumping to matching brace." | |
(interactive "p") | |
(message "%s" last-command) | |
(if (not (memq last-command '( | |
set-mark | |
cua-set-mark | |
goto-match-paren | |
down-list | |
up-list | |
end-of-defun | |
beginning-of-defun | |
backward-sexp | |
forward-sexp | |
backward-up-list | |
forward-paragraph | |
backward-paragraph | |
end-of-buffer | |
beginning-of-buffer | |
backward-word | |
forward-word | |
mwheel-scroll | |
backward-word | |
forward-word | |
mouse-start-secondary | |
mouse-yank-secondary | |
mouse-secondary-save-then-kill | |
move-end-of-line | |
move-beginning-of-line | |
backward-char | |
forward-char | |
scroll-up | |
scroll-down | |
scroll-left | |
scroll-right | |
mouse-set-point | |
next-buffer | |
previous-buffer | |
previous-line | |
next-line | |
) | |
)) | |
(self-insert-command (or arg 1)) | |
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) | |
((looking-at "\\s\)") (forward-char 1) (backward-list 1)) | |
(t (self-insert-command (or arg 1)))))) | |
(global-set-key (kbd "%") 'goto-match-paren) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment