I'm somewhat confused by why the following piece of code
does not work the way that I expect. I have
find-unbalanced-parentheses, which errors when there is
unbalanced parens. I tried adding a save hook, that is local
to only emacs-lisp mode files that calls find-unbalanced-parentheses.
However, after this code runs, the after-save-hook is run in all
buffers, and not just emacs-lisp-mode buffers.
(defun check-for-unbalanced-parens-on-save ()
(interactive)
(make-local-hook 'after-save-hook)
(add-hook 'after-save-hook 'find-unbalanced-parentheses))
(add-hook 'emacs-lisp-mode-hook 'check-for-unbalanced-parens-on-save)
-jeff
------
;; This originally came from zmacs-stuff.el in tmc-hacks
(defun find-unbalanced-parentheses ()
"Check the buffer for unbalanced parentheses. Stops at any that are
unbalanced."
(interactive)
(let ((start-point (point)))
(goto-char (point-min))
(condition-case e
(while (/= (point) (point-max))
(forward-sexp))
(error
;; If this is an extra left paren error, we have to scan backwards to
;; find the exact left paren in error
(cond ((and (eq (car e) 'error)
(string-equal (cadr e) "Unbalanced parentheses"))
;; left paren error
(goto-char (point-max))
(while (/= (point) (point-min))
(condition-case e (backward-sexp)
(error
(error "Probably an extra left parenthesis here.")))))
(t (error "Probably an extra right parenthesis here.")))))
(goto-char start-point)
(message "All parentheses appear balanced.")))