Created
January 22, 2013 02:03
-
-
Save benhsu/4591417 to your computer and use it in GitHub Desktop.
closes the s-expression at point
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 close-sexp () | |
;; closes the s-expression at point | |
;; by computing how many open parens and close parens | |
;; there are and inserting the appropriate number | |
;; bug: doesnt handle backquoted parens like \( \) properly | |
(interactive) | |
(let ((pt (point)) | |
(numopen 0) | |
(numclose 0)) | |
(save-excursion | |
(beginning-of-buffer) | |
(while (< (point) pt) | |
(if (eq (char-after) ?\() | |
(setq numopen (+ 1 numopen))) | |
(if (eq (char-after) ?\)) | |
(setq numclose (+ 1 numclose))) | |
(forward-char 1) )) | |
(dotimes (n (- numopen numclose)) | |
(insert-char ?\))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment