From: Thorsten Jolitz <tjolitz@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: post-command-hook to slow?
Date: Thu, 05 Jun 2014 20:11:58 +0200 [thread overview]
Message-ID: <87bnu7ql8x.fsf@gmail.com> (raw)
In-Reply-To: 8761kf5koy.fsf@kuiper.lan.informatimago.com
"Pascal J. Bourguignon" <pjb@informatimago.com> writes:
> Thorsten Jolitz <tjolitz@gmail.com> writes:
>
>> Hi List,
>>
>> I call a command to be executed in a temporary buffer, and that command
>> runs a post-command-hook. Here is some pseudocode:
>>
>> ,----------------------------------
>> | open-temp-buffer
>> | set-buffer-mode
>> | call-interactively cmd
>> | copy-content-and-exit-temp-buffer
>> `----------------------------------
>>
>> Unfortunately the post-command-hook of cmd is executed only after the
>> temp buffer is already exited (i.e. in the original buffer in a
>> different/wrong major-mode with the needed markers lost).
>>
>> Is that to be expected? Will `copy-content-and-exit-temp-buffer' be
>> executed before the post-command-hook of cmd has a chance to be
>> executed?
>
> post-command-hook is called after each command. Ie. after each
> character you type! So indeed, it should be very fast. Perhaps you
> could keep your temp buffer around (you can hide such a buffer by
> prefixing its name with a space).
right, when tends to forget that ...
> From a quick scan, I don't see anything in call-interactively that would
> make it not execute the command synchronously.
> Furthermore, post-command-hooks are not called by call-interactively.
>
> If cmd is this-command, then what you are doing, is to call
> this-command a second time, after it has already been called. This
> call-interactively works with your temp buffer, but the original command
> call was done before post-command-hooks were called of course.
hmmm ... may be a bit more context:
what I do is call `outorg-edit-as-org' in a programming language buffer,
e.g. an emacs-lisp buffer. Then a temporary edit buffer in Org-mode is
opened (not using with-temp-buffer since normally it should stay around
for editing) until it is closed again.
Now I reuse that mechanism for calling Org commands without any user
editing - open the Org-mode temp buffer, execute the command, close the
temp buffer and copy the results to the source buffer.
So the post-command-hooks are not mine, but those from some Org-mode
functions, I just have to deal with them.
> If what you want to do is to wrap some commands to make them work in a
> different buffer, then you cannot use post-command-hook to do that, and
> just both pre-command-hook and post-command-hook wouldn't be very safe
> (if anything breaks, you could end with a dangling state).
>
> In that case, I would advise you to use an around advice on the command
> instead. cf. defadvice.
unfortunately its not my choice, since very basic Org commands like
org-todo run post-command-hook.
> Some commands may rely on the selected window in a hidden way, so if the
> commands you call in the post-command-hook use a window, wrapping them in
> a (with-selected-window window (call-interactively …)) could help.
cmd and its hook function is Org-mode code I cannot change ... but
still, I'm going to experiment with this, looks promising.
> Do you use with-temp-buffer? You probably should, instead of creating
> the buffer and later killing it.
It would be better for this use case, but I don't want to reimplement
existing functionality, just reuse what is already there and works.
I put some message-calls printing out `current-buffer' in `cmd' and its
post-command-hook function, and its really strange - cmd is executed in
the temp buffer (in Org-mode), the hook in the original emacs-lisp
source-code buffer
<emacs-lisp-buffer>
|
,----------------------------------
| open-temp-buffer
| set-buffer-mode
| call-interactively cmd }<org-mode-buffer>
| copy-content-and-exit-temp-buffer
`----------------------------------
|
<emacs-lisp-buffer>
although it shouldn't in my view, and everything you wrote seems to
indicate that
,-----------------------
| call-interactively cmd
`-----------------------
should quickly run cmd and post-command-hook before
,----------------------------------
| copy-content-and-exit-temp-buffer
`----------------------------------
is executed - but apparently not.
Thanks for your answer.
--
cheers,
Thorsten
next prev parent reply other threads:[~2014-06-05 18:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.3007.1401978250.1147.help-gnu-emacs@gnu.org>
2014-06-05 17:29 ` post-command-hook to slow? Pascal J. Bourguignon
2014-06-05 18:11 ` Thorsten Jolitz [this message]
[not found] ` <mailman.3038.1401991947.1147.help-gnu-emacs@gnu.org>
2014-06-05 20:19 ` Pascal J. Bourguignon
2014-06-05 21:09 ` Thorsten Jolitz
[not found] ` <mailman.3061.1402002590.1147.help-gnu-emacs@gnu.org>
2014-06-05 23:05 ` Pascal J. Bourguignon
2014-06-06 17:37 ` Thorsten Jolitz
[not found] ` <mailman.3167.1402076299.1147.help-gnu-emacs@gnu.org>
2014-06-06 18:47 ` Pascal J. Bourguignon
2014-06-05 14:23 Thorsten Jolitz
2014-06-06 2:27 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bnu7ql8x.fsf@gmail.com \
--to=tjolitz@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).