From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.help Subject: Re: Temporarily suppress a hook? Date: Mon, 9 Jul 2018 13:07:06 +0100 Message-ID: References: <3b2c670c-e07e-4a35-a2a4-f933e23329f2@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1531137956 7600 195.159.176.226 (9 Jul 2018 12:05:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 9 Jul 2018 12:05:56 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org List" To: Skip Montanaro Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 09 14:05:52 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fcUvP-0001sf-TZ for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Jul 2018 14:05:52 +0200 Original-Received: from localhost ([::1]:41226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcUxX-0000WK-21 for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Jul 2018 08:08:03 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcUwr-0000V1-Ka for help-gnu-emacs@gnu.org; Mon, 09 Jul 2018 08:07:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcUwq-0005S2-FU for help-gnu-emacs@gnu.org; Mon, 09 Jul 2018 08:07:21 -0400 Original-Received: from mail-it0-x232.google.com ([2607:f8b0:4001:c0b::232]:37870) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fcUwq-0005Rq-8N for help-gnu-emacs@gnu.org; Mon, 09 Jul 2018 08:07:20 -0400 Original-Received: by mail-it0-x232.google.com with SMTP id p17-v6so26008303itc.2 for ; Mon, 09 Jul 2018 05:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=twOzhyNg2hcXm8H3UYQKBAwOA+H4A5Q8JKxdgqWwduY=; b=FLFUhNmTJQw23mBTXvLUuna0tdhtVyCM6XE7lQy1NAZWNabAyN2wAPWwtRi/QKaHe5 sksp1t6R1AdErNRQBgZeifRG7bnrz+hIr3tRvlFHtJW4B8Mtq6D158t4izN9G+e4hli1 4XlY5q0YUS4Hfeqf8mzxmTiaMpKugZFd7QewiRlQHq3j3DCOJKDFz5kLIwqh9oEVOWzG R8rf1CXAgBNLir5e4oM2qgvVMJQ3WW3LSk7RoRPNwi20gsjdcid5nVe17fQ0YFqFP9LB gtAvJzvaYN6+HzQlO63Ca/LpDKvX4T64XNOA0uvi5SC9Usj7lN4k/EegYLqwEEGPATaa /Pzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=twOzhyNg2hcXm8H3UYQKBAwOA+H4A5Q8JKxdgqWwduY=; b=nyin+CKlcCz+UnbmdaAjPp8csjY5N70bH6EXmMYoFu2M8jGkj1Ve7ZkqTNcQUVhtD+ Y2ZHI+AKaFiYkEhaBxhcqn6bCE1mw7f2sPBmhFioRTlL8WlZ8VdTObnfn4kRJzfD+LvO nneV/7yqZbP78tdq6RhlnBOKAC07P6SoDWfGKnSmUa9fi6yFvy/hk9bNh4+zafOJ8Rub BSzcg6JP0QxHhp4mF30SI2Gkt0qazES9EpJemHwEFmpQMO0MnhcWIsm0eWp0u9WO/Z+m xIPrcgjM/2Vx/I/UyNxGrjqO05rPC1SkNgwFZoHFpkrpzjVYk8hgl9/4vVl5qUi2IueZ cHHw== X-Gm-Message-State: APt69E3gRcVGZ1CxtNtRV+QqCa3bjy7i05Ix+FIbKrabzNcLSxNNzR6V 4uK3D1AMfUMDcecuGOGQcRU0Uff4X53yicop/jQ= X-Google-Smtp-Source: AAOMgpcWNF7UkmO5dB79kGU1MzFOcBC4ivlUIM0z+onS95fWz4UYufl38nuQogA8z/vaguua9YxK5/dI+YRannyYJNs= X-Received: by 2002:a02:664b:: with SMTP id l11-v6mr17130434jaf.70.1531138039382; Mon, 09 Jul 2018 05:07:19 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::232 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.help:117397 Archived-At: On Mon, Jul 9, 2018, 02:40 Skip Montanaro wrote: > > I have before-save-hook defined in ~/.emacs > > > (add-hook 'before-save-hook 'delete-trailing-whitespace) > > > Both `add-hook' and `remove-hook' take an optional > > LOCAL argument, to affect only the current buffer > > (the buffer-local value of the hook). > > > > It's not clear how that helps me. In essentially every other file I edit,= I > want to delete trailing whitespace, so I enable it globally. It seems > buffer-local enabling of that hook would be appropriate if I only > occasionally wanted to enable it. > Indeed, using remove-hook with a local argument in those special buffers won't help you if you've already affected the global value of before-save-hook. But you can add the hook locally, as Drew suggests, in those buffers where you need it, and refrain from doing so in the buffers where you don't. Prog-mode is a very pervasive mode: many modes derive from it. Here's what I mean (add-hook 'prog-mode-hook (lambda () (add-hook 'before-save-hook 'delete-trailing-whitespace nil t))) Now, in those special files/buffers (some special major mode?), a remove-hook should do what you want. Jo=C3=A3o