From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: How to apply a minor mode to all buffers Date: Wed, 07 Feb 2007 00:42:49 -0700 Message-ID: References: <877ivkjb66.fsf@trick.ulm.malte.spiess> <87lkjgs6lf.wl%leonardo.boiko@corp.orolix.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1170834213 12034 80.91.229.12 (7 Feb 2007 07:43:33 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 7 Feb 2007 07:43:33 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Feb 07 08:43:31 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HEhSh-0001gO-LQ for geh-help-gnu-emacs@m.gmane.org; Wed, 07 Feb 2007 08:43:28 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HEhSd-0001p8-SF for geh-help-gnu-emacs@m.gmane.org; Wed, 07 Feb 2007 02:43:23 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HEhSR-0001oq-GU for help-gnu-emacs@gnu.org; Wed, 07 Feb 2007 02:43:11 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HEhSP-0001oe-1z for help-gnu-emacs@gnu.org; Wed, 07 Feb 2007 02:43:10 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HEhSO-0001ob-Q9 for help-gnu-emacs@gnu.org; Wed, 07 Feb 2007 02:43:08 -0500 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HEhSO-00027y-Bz for help-gnu-emacs@gnu.org; Wed, 07 Feb 2007 02:43:08 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HEhSE-0006a2-Hu for help-gnu-emacs@gnu.org; Wed, 07 Feb 2007 08:42:58 +0100 Original-Received: from c-24-9-156-178.hsd1.co.comcast.net ([24.9.156.178]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 07 Feb 2007 08:42:58 +0100 Original-Received: from kevin.d.rodgers by c-24-9-156-178.hsd1.co.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 07 Feb 2007 08:42:58 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 67 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: c-24-9-156-178.hsd1.co.comcast.net User-Agent: Thunderbird 1.5.0.9 (Macintosh/20061207) In-Reply-To: <87lkjgs6lf.wl%leonardo.boiko@corp.orolix.com> X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:40932 Archived-At: leoboiko@gmail.com wrote: > At Mon, 22 Jan 2007 11:57:35 -0500, > Stefan Monnier wrote: >> You could start with find-file-hook. > > find-file-hook won’t apply to buffers unrelated to files, though. > after-change-major-mode-hook almost does the trick, but it still > doesn’t get fundamental-mode. Do you do much editing in Fundamental mode? > What I’d like is fundamental-mode-hook. > > “Damn vim users”, I said. “Keep leaving those trailing whitespaces > all over the place. It disrupts my mental concentration, for I have > show-trailing-whitespace globally as t, and I have to stop whatever > I’m doing to delete-trailing-whitespace.” > > “You could put it in a hook, you know”, said my friend. > > “Yes, of course”, I replied, with my best “why I didn’t think of this > before” voice. “But I need to test whether the buffer is read-only, > else we’d generate lots of beeps”: > > > (setq-default show-trailing-whitespace nil) > > (defun leoboiko/delete-and-show-trailing-whitespace () > "If the buffer is not readonly, delete trailing whitespace and turn on > `show-trailing-whitespace'." > (interactive) > (if (not buffer-read-only) > (progn > (delete-trailing-whitespace) > (setq show-trailing-whitespace t)))) You may still want to show it even if you can't delete it: (unless buffer-read-only (delete-trailing-whitespace)) (show-trailing-whitespace) > (add-hook 'hook-for-all-buffers ;; what to put here? > 'leoboiko/delete-and-show-trailing-whitespace) > > My first attempt was find-file-hook, but I want it to apply to > non-file buffers too (like email drafts, etc). My second attempt was > fundamental-mode-hook, but there is no such thing. My third attempt > (after reading fundamental-mode’s source) was > after-change-major-mode-hook, but this still doesn’t work for > fundamental buffers (say, if I simply create a scratch buffer). How about: (add-hook 'find-file-hook 'delete/show-trailing-whitespace) (add-hook 'text-mode-hook 'delete/show-trailing-whitespace) (setq default-major-mode 'text-mode) > The rationale I saw about why there is no fundamental-mode-hook is > that variable customizations on fundamental mode are really global > customizations. That’s nice, but I don’t want to change variables, I > want to be able to run arbitrary functions every time a buffer is > created. -- Kevin Rodgers Denver, Colorado, USA