all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Automatically checking parentheses before a global save not working.
@ 2010-07-01 13:49 Elena
       [not found] ` <87k4pffa8w.fsf@fh-trier.de>
  0 siblings, 1 reply; 4+ messages in thread
From: Elena @ 2010-07-01 13:49 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I've written a function to check parentheses of Lisp buffers during a
global save - after being added to `before-save-hook' - so that
whenever it spots an unbalanced parentheses, it offers the user a
chance to fix it. However, it seems I can't switch to the offending
buffer. Maybe I just don't understand the way `condition-case' works.

Here is my code:

(defun fix-parens-or-save-anyway ()
	"Check for unbalanced parentheses before saving. To be used with
`before-save-hook'.

If parentheses are balanced, do nothing. Otherwise let the user know
and ask for confirmation before saving. If user confirms, do nothing;
otherwise switch to such buffer and let the user fix the error.
"
	(condition-case nil
		(check-parens)
		(error
		 (unless (yes-or-no-p (format "%s: Unbalanced parentheses. Save
anyway?" (buffer-name)))
			 (switch-to-buffer (buffer-name))
			 (check-parens)))))

(defun my-emacs-lisp-save-hook()
	(add-hook 'before-save-hook
			  'fix-parens-or-save-anyway
			  nil ; Prepend this hook (default).
			  t ; This is a local hook.
			  ))

(add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-save-hook)

Thanks for your help.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-04 15:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-01 13:49 Automatically checking parentheses before a global save not working Elena
     [not found] ` <87k4pffa8w.fsf@fh-trier.de>
     [not found]   ` <e4d6ef68-2e04-44d8-9765-eda0bb8c338d@c10g2000yqi.googlegroups.com>
2010-07-01 19:11     ` Uday S Reddy
2010-08-04 15:37       ` Johan Bockgård
     [not found]     ` <87eifndnck.fsf@fh-trier.de>
2010-07-02  8:54       ` Elena

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.