From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.help Subject: Re: How to exclude a major mode from a hook Date: Wed, 11 Feb 2015 11:15:01 +0100 Message-ID: <878ug4hhzu.fsf@yahoo.fr> References: <87twysx0nz.fsf@Equus.decebal.nl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1423649703 17952 80.91.229.3 (11 Feb 2015 10:15:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 11 Feb 2015 10:15:03 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Cecil Westerhof Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Feb 11 11:14:54 2015 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 1YLUJo-0006DC-Ir for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Feb 2015 11:14:52 +0100 Original-Received: from localhost ([::1]:43915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLUJn-00068L-Gh for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Feb 2015 05:14:51 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLUJc-00063i-Sv for help-gnu-emacs@gnu.org; Wed, 11 Feb 2015 05:14:41 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLUJX-0003Eg-Ug for help-gnu-emacs@gnu.org; Wed, 11 Feb 2015 05:14:40 -0500 Original-Received: from mxin.ulb.ac.be ([164.15.128.112]:2839) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLUJX-0003DY-Oh for help-gnu-emacs@gnu.org; Wed, 11 Feb 2015 05:14:35 -0500 Original-Received: from mathsrv4.ulb.ac.be (HELO localhost) ([164.15.133.241]) by smtp.ulb.ac.be with ESMTP; 11 Feb 2015 11:14:33 +0100 In-Reply-To: <87twysx0nz.fsf@Equus.decebal.nl> (Cecil Westerhof's message of "Wed, 11 Feb 2015 10:22:40 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 164.15.128.112 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:102635 Archived-At: Hi, Cecil Westerhof writes: > I had the following in my .emacs: > (add-hook 'before-save-hook 'delete-trailing-whitespace) IMO this is not the right thing to do, because one day you'll want to edit a file in which trailing white spaces are important and you'll wonder why it's all screwed up. I would suggest to use a function that checks for trailing whitespaces (with exceptions, such as the signature delimiter in message-mode) and (interactievly) prompts if there is something to fix. I don't know if such a function exists. > So I rewrote it to: > (add-hook 'before-save-hook (lambda () (when (not (string= major-mode "message-mode")) > 'delete-trailing-whitespace))) The condition (string= major-mode "message-mode") can be written as (eq major-mode 'message-mode) and would be better written as (derived-mode-p 'message-mode) -- Nicolas