# HG changeset patch # User Mike Sperber # Date 1390841103 -3600 # Node ID 6a6c89b53c5d33f6458cb2b3a8b7c1fab6922ea6 # Parent 10395934b99efc079f15a3a1bcc280b598dbc118 Add `check-parents' from GNU Emacs. 2014-01-27 Michael Sperber * lisp.el (check-parens): Add, from GNU Emacs. diff -r 10395934b99e -r 6a6c89b53c5d lisp/ChangeLog --- a/lisp/ChangeLog Mon Jan 27 17:41:46 2014 +0100 +++ b/lisp/ChangeLog Mon Jan 27 17:45:03 2014 +0100 @@ -1,3 +1,7 @@ +2014-01-27 Michael Sperber + + * lisp.el (check-parens): Add, from GNU Emacs. + 2014-01-27 Michael Sperber * custom.el (custom-declare-variable, defcustom): Add :risky and diff -r 10395934b99e -r 6a6c89b53c5d lisp/lisp.el --- a/lisp/lisp.el Mon Jan 27 17:41:46 2014 +0100 +++ b/lisp/lisp.el Mon Jan 27 17:45:03 2014 +0100 @@ -328,6 +328,26 @@ (delete-indentation)) (forward-char 1) (newline-and-indent)) + +(defun check-parens () ; lame name? + "Check for unbalanced parentheses in the current buffer. +More accurately, check the narrowed part of the buffer for unbalanced +expressions (\"sexps\") in general. This is done according to the +current syntax table and will find unbalanced brackets or quotes as +appropriate. (See Info node `(emacs)Parentheses'.) If imbalance is +found, an error is signaled and point is left at the first unbalanced +character." + (interactive) + (condition-case data + ;; Buffer can't have more than (point-max) sexps. + (scan-sexps (point-min) (point-max)) + (scan-error (goto-char (nth 2 data)) + ;; Could print (nth 1 data), which is either + ;; "Containing expression ends prematurely" or + ;; "Unbalanced parentheses", but those may not be so + ;; accurate/helpful, e.g. quotes may actually be + ;; mismatched. + (error "Unmatched bracket or quote")))) (defun lisp-complete-symbol () "Perform completion on Lisp symbol preceding point.