From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: post-command-hook to slow? Date: Thu, 05 Jun 2014 19:29:33 +0200 Organization: Informatimago Message-ID: <8761kf5koy.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1401989736 1919 80.91.229.3 (5 Jun 2014 17:35:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Jun 2014 17:35:36 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 05 19:35:30 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WsbZV-0003WB-Er for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Jun 2014 19:35:25 +0200 Original-Received: from localhost ([::1]:42953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsbZV-0001R9-2B for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Jun 2014 13:35:25 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 61 Original-X-Trace: individual.net GkDYtOItxxp7HwQ75rmchAmzsZ/a9F5poRSCmYzVMfAOdemifd Cancel-Lock: sha1:NmJjOGFlZTJkNjM0MDBhMzllNzUwYTcxZjA0NmM2ODc5ZDhhYjAwOA== sha1:ZpA3FtB325c9xbKUU1+RVFr8LiY= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:205752 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:98022 Archived-At: Thorsten Jolitz 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). >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. 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. 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. Do you use with-temp-buffer? You probably should, instead of creating the buffer and later killing it. -- __Pascal Bourguignon__ http://www.informatimago.com/ "Le mercure monte ? C'est le moment d'acheter !"