From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Skip Montanaro Newsgroups: gmane.emacs.help Subject: Temporarily disable a write hook? Date: Fri, 14 Jul 2017 10:03:16 -0500 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1500044642 30500 195.159.176.226 (14 Jul 2017 15:04:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 14 Jul 2017 15:04:02 +0000 (UTC) To: Help GNU Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jul 14 17:03:56 2017 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 1dW28J-0007Ri-JM for geh-help-gnu-emacs@m.gmane.org; Fri, 14 Jul 2017 17:03:55 +0200 Original-Received: from localhost ([::1]:38435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW28M-0000QJ-4l for geh-help-gnu-emacs@m.gmane.org; Fri, 14 Jul 2017 11:03:58 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW27p-0000Q9-Nb for help-gnu-emacs@gnu.org; Fri, 14 Jul 2017 11:03:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW27o-0005kc-RC for help-gnu-emacs@gnu.org; Fri, 14 Jul 2017 11:03:25 -0400 Original-Received: from mail-it0-x22c.google.com ([2607:f8b0:4001:c0b::22c]:37664) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dW27o-0005jh-NX for help-gnu-emacs@gnu.org; Fri, 14 Jul 2017 11:03:24 -0400 Original-Received: by mail-it0-x22c.google.com with SMTP id m84so26563158ita.0 for ; Fri, 14 Jul 2017 08:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=N0vfqwJG0Bjj+28guB6GpJ9HjmBTozAhnMlh5HBkJVk=; b=CJjGw0DntKd9w7cC7+BoUXWMvxkqtPfhRY+OjtDjT4koFQtkxEpHunYFTjB2ldZCxg /1sMtDc2O0UdCwuhFPEsVDFo2ku50N3txK6UAqvRnL1zRn1+dT94ifpLh3HaR1KdAmI8 sUQpjRnMfqxqoPFndTWNTFELNzz78kYnlBMg706kg7EuOr5Tz3Q5CidG33LupPAVbX/a Qp3dfCThvc8Uv4BeTwrerOrnsZwrS3z9BckclmfXAckVhQp/1nv6e8YINGNvdTNVZNQB Yr9thvuWYWNa09913UesOJnwNJdxutIOSk/BYJb5COlHgzi9/8Y6zAknj2sjqerK/lHM 48+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=N0vfqwJG0Bjj+28guB6GpJ9HjmBTozAhnMlh5HBkJVk=; b=GvVDoYAOX+7tiwy7y1JC/k7jQ9FyEG0laC/2NKNEhCeizxpPN8uOHoNYz+yeRqYgVG Jhz0isQ7HzWUkaE8tItMCNBdh8AinjeK7xiz8GWcVZCUaCPm837x7rxXugrsPCb8dO4p n5rxh1LeKPcJNXg2tMKJGjBCgQUewXytiB9wExaWGTmGkr5otAeF7pSbWfbAat1BlTTL 07vi6DVzc3T0XI5xXQpNwrackrHQCKcZQyHdTYYbCs4TjRKXE5jOM44IVwx6jhQa7APp fdyJlEkA5eIlsh8tTLhC815MSjvEmjds+q/XhMJCLomRbNqdEgpjBQ256PgPYKjV3DBL OuLQ== X-Gm-Message-State: AIVw111kaCk/97drF2pczj08ZD571Jd585NRRh+FjxAoNUL6//hdMDPI xf7/91ZqMOMkYr6YjJr4PSVnDaX0XB6p X-Received: by 10.36.248.132 with SMTP id a126mr4374048ith.0.1500044597327; Fri, 14 Jul 2017 08:03:17 -0700 (PDT) Original-Received: by 10.107.32.144 with HTTP; Fri, 14 Jul 2017 08:03:16 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::22c 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:113764 Archived-At: I'm a Python programmer, so I often edit Python source. I don't want trailing whitespace. That holds true for almost everything else I edit (C, SQL, Bash, etc...). In fact, even if I'm editing text files (ReST, Markdown, LaTeX, whatever), I want this behavior. Accordingly, I have this in ~/.emacs: (add-hook 'before-save-hook 'delete-trailing-whitespace) Well, I got burned by this. I was editing a CSV file in which one cell in the last column of a row ended with a space. It was, unfortunately, a regular expression, so the space was significant. Given that I *do* want to zap trailing whitespace on write *almost all the time*, how best to solve this issue? Is there a way to conditionally invoke the before-save-hook, or do I simply write my own wrapper which stares at the file extension to decide whether to call delete-trailing-whitespace? I was hoping that save-buffer didn't pay attention to the numeric prefix, but that was too much to ask. It is intimately concerned with the value of the numeric prefix. (I suppose I could write my own wrapper for save-buffer which suppresses the before-save-hook if the numeric prefix is negative, or something, but I'd be opening myself up for a later behavioral change to Emacs.) Also out-of-the-ordinary in this particular example, though the file was in CSV format, I didn't give it a ".csv" extension for some reason, so I couldn't just say, "ah, it ends in '.csv', avoid the call to (delete-trailing-whitespace)." Oh, the tangled webs we weave... Skip