From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.devel Subject: occur-mode-hook run too early to be useful Date: Wed, 28 Aug 2002 11:16:57 +0200 Sender: emacs-devel-admin@gnu.org Message-ID: <20020828103157.9D0E.LEKTU@terra.es> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: main.gmane.org 1030526275 20417 127.0.0.1 (28 Aug 2002 09:17:55 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 28 Aug 2002 09:17:55 +0000 (UTC) Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17jyxT-0005J9-00 for ; Wed, 28 Aug 2002 11:17:51 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17jzTC-0006y5-00 for ; Wed, 28 Aug 2002 11:50:38 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17jyyo-0003Rk-00; Wed, 28 Aug 2002 05:19:14 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17jywf-0003Mt-00 for emacs-devel@gnu.org; Wed, 28 Aug 2002 05:17:01 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17jywd-0003MR-00 for emacs-devel@gnu.org; Wed, 28 Aug 2002 05:17:01 -0400 Original-Received: from [62.22.27.141] (helo=mail.peoplecall.com) by monty-python.gnu.org with esmtp (Exim 4.10) id 17jywd-0003M6-00 for emacs-devel@gnu.org; Wed, 28 Aug 2002 05:16:59 -0400 Original-Received: from [62.22.27.143] (jbarranquero.ofi.peoplecall.com [62.22.27.143]) by mail.peoplecall.com (8.11.6/8.11.6) with ESMTP id g7S9GvB29215 for ; Wed, 28 Aug 2002 11:16:57 +0200 Original-To: emacs-devel@gnu.org X-Mailer: Becky! ver. 2.05.04 Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:7033 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:7033 =46rom the doc of `occur-rename-buffer': > Rename the current *Occur* buffer to *Occur: original-buffer-name*. > Here `original-buffer-name' is the buffer name were occur was originally = run. > When given the prefix argument, the renaming will not clobber the existin= g > buffer(s) of that name, but use `generate-new-buffer-name' instead. > You can add this to `occur-mode-hook' if you always want a separate *Occu= r* > buffer for each buffer where you invoke `occur'. That's not true because occur-mode-hook is run too early. For example: M-: (add-hook 'occur-mode-hook #'(lambda () (occur-rename-buffer t))) C-h N M-x occur "GNU/Linux" ; Buffer is called "*Occur: *" C-x 1 M-x occur "Unix" ; Buffer is called "*Occur: *<2>" instead of "*Occur: NEWS*" and "*Occur: NEWS*<2>". The reason is that occur-1 runs occur-mode (and hence occur-mode-hook), erases the buffer, and only then sets `occur-revert-arguments' (that `occur-rename-buffer' needs). The patch to fix that is trivial: just move the call to (run-hooks 'occur-mode-hook) from `occur-mode' to the end of `occur-1', and voil=E0. As always, though, I have a philosophical question: should be `occur-mode-hook' be run from any other place than `occur-mode'? For normal major modes the answer is no, I suppose, but `occur-mode' is a special mode, only called from inside `occur-1'. After `occur-mode' runs, the buffer either has the old contents (that will be obliterated immediately afterwards) or it is empty, so in fact running `occur-mode-hook' at that moment is only useful for non-contents-related hook functions. I want, for example, to resize the occur window after doing M-x occur, and as it stands now it's not posible to do that through `occur-mode-hook' (I'd have to revert to using defadvice, etc.). So, it is OK to move the call to run-hooks to occur-1? /L/e/k/t/u