From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Temporarily suppress a hook? Date: Mon, 09 Jul 2018 10:41:02 -0400 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1531147186 2147 195.159.176.226 (9 Jul 2018 14:39:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 9 Jul 2018 14:39:46 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 09 16:39:42 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 1fcXKC-0000KE-Np for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Jul 2018 16:39:36 +0200 Original-Received: from localhost ([::1]:42440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcXMJ-0008V1-Qs for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Jul 2018 10:41:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcXLn-0008SX-Rw for help-gnu-emacs@gnu.org; Mon, 09 Jul 2018 10:41:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcXLj-0004Iv-Un for help-gnu-emacs@gnu.org; Mon, 09 Jul 2018 10:41:15 -0400 Original-Received: from [195.159.176.226] (port=39155 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fcXLj-0004IU-My for help-gnu-emacs@gnu.org; Mon, 09 Jul 2018 10:41:11 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fcXJY-000811-TZ for help-gnu-emacs@gnu.org; Mon, 09 Jul 2018 16:38:56 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 25 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:aC00TLTmWyQrbjL37R7iXUtiuFI= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 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:117398 Archived-At: > I have before-save-hook defined in ~/.emacs > (add-hook 'before-save-hook 'delete-trailing-whitespace) [...] > possible. Is it possible to suppress the before-save-hook on a > per-file basis? I suggest you file a feature request (via M-x report-emacs-bug) I think it should be possible to buffer-locally "remove" a function from a hook, even if that function was added globally (I toyed with an implementation of that idea which added `(not . FUNCTION)` to the (buffer-local part of the) hook, and then `run-hook` would honor such a value by disregarding any subsequent occurrence of FUNCTION). With my hack, you'd be able to do: (add-hook 'my-special-mode-hook (lambda () (remove-hook 'before-save-hook #'delete-trailing-whitespace 'local))) so that buffers using `my-special-mode` won't delete their trailing spaces. Stefan