[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Automatically checking parentheses before a global save not working.
From: |
Andreas Politz |
Subject: |
Re: Automatically checking parentheses before a global save not working. |
Date: |
Wed, 08 Dec 2010 15:16:55 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Elena <egarrulo@gmail.com> writes:
> On 1 Lug, 18:16, Andreas Politz <poli...@fh-trier.de> wrote:
>> > (switch-to-buffer (buffer-name))
>>
>> There is no user interaction at this point.
>
> What do you mean, please? Can't I call `switch-to-buffer' there?
> However, `yes-or-no-p' (which interacts with the user) works, and the
> buffer to fix is being correctly identified by name.
My impression is, that you want this behaviour :
1. Switch to buffer x
2. Let user edit buffer x
3. Recheck parens
But your lisp code does not wait for 2. and I don't understand why you
would think it will. You would have to enter a `recursive-edit', edit
the buffer, then leave the recursive-edit. At this point your code would
continue with 3. .
(condition-case nil
(check-parens)
(error
(when (yes-or-no-p (format "Fix parens in buffer %s ?" (buffer-name)))
(switch-to-buffer (current-buffer))
(recursive-edit) ;;Edit and press C-M-c
(check-parens))))
>
>> You could try something
>> with `recursive-edit', but I don't know if it is a good idea to change
>> the buffer state at this point (in the `before-save-hook').
>
,,changing buffer state'' == ,,editing buffer'' != ,,switching buffers''
> If I can't switch buffer right away, maybe an alternative and safe
> approach would be to set a delayed switch, which would run after
> termination of `condition-case'.
You can, but see above.
>
>>
>> Also, I suppose running the hook is wrapped in some
>> current-buffer-saving-macro.
>
> Yes, this function has been locally added to `before-save-hook' into
> `emacs-lisp-mode'.
>
What I was talking about was the code running ,,on top'' of yours, which
is located in `basic-buffer-save' :
(defun basic-save-buffer ()
(save-current-buffer
...
(run-hooks 'before-save-hook)
...))
I think that's why switch-to-buffer has no lasting effect.
> Thanks for you help.
-ap