[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Automatically checking parentheses before a global save not working.
From: |
Elena |
Subject: |
Automatically checking parentheses before a global save not working. |
Date: |
Wed, 08 Dec 2010 15:16:44 -0000 |
User-agent: |
G2/1.0 |
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.
- Automatically checking parentheses before a global save not working.,
Elena <=