Skip to content

Instantly share code, notes, and snippets.

@cbaggers
Last active January 16, 2018 14:51
Show Gist options
  • Save cbaggers/140688558091a19543758b12f908c686 to your computer and use it in GitHub Desktop.
Save cbaggers/140688558091a19543758b12f908c686 to your computer and use it in GitHub Desktop.
little helpers
;; You might want to paste these in your .emacs file
;; when over one paren it shows it's match
(show-paren-mode t)
;; C-c ) jumps to the matching paren
(defun goto-match-paren (arg)
"Go to the matching if on (){}[], similar to vi style of % "
(interactive "p")
;; first, check for "outside of bracket" positions expected by forward-sexp, etc.
(cond ((looking-at "[\[\(\{]") (forward-sexp))
((looking-back "[\]\)\}]" 1) (backward-sexp))
;; now, try to succeed from inside of a bracket
((looking-at "[\]\)\}]") (forward-char) (backward-sexp))
((looking-back "[\[\(\{]" 1) (backward-char) (forward-sexp))
(t nil)))
(global-set-key (kbd "\C-c )") `goto-match-paren)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment