Skip to content

Instantly share code, notes, and snippets.

@randrews
Created August 22, 2009 23:39
Show Gist options
  • Save randrews/173046 to your computer and use it in GitHub Desktop.
Save randrews/173046 to your computer and use it in GitHub Desktop.
(defun matching-char (find other delta &optional start level)
(save-excursion
(let ((level (if level level 0))
(start (if start start (point))))
(if (and
start
(>= start (point-min))
(<= start (point-max)))
(goto-char start)
(error "Not within block"))
(cond
((looking-at find)
(if (= level 0)
(point)
(matching-char find other delta (+ start delta) (- level 1)))
)
((looking-at other)
(matching-char find other delta (+ start delta) (+ level 1)))
(t
(matching-char find other delta (+ start delta) level)
)
))))
(defun kill-block ()
"Kills the brace-delimited block which the point is currently within."
(interactive)
(kill-region (matching-char "{" "}" -1)
(+ 1 (matching-char "}" "{" 1))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment