From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rusi Newsgroups: gmane.emacs.help Subject: Re: whitespace issues Date: Tue, 30 Jun 2015 19:50:02 -0700 (PDT) Message-ID: <1a3dafd0-7772-43a2-a6cc-d83634003eb6@googlegroups.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1435719020 24228 80.91.229.3 (1 Jul 2015 02:50:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 1 Jul 2015 02:50:20 +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 Jul 01 04:50:19 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 1ZA86N-00035W-0S for geh-help-gnu-emacs@m.gmane.org; Wed, 01 Jul 2015 04:50:19 +0200 Original-Received: from localhost ([::1]:49439 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZA86M-0003OC-8Y for geh-help-gnu-emacs@m.gmane.org; Tue, 30 Jun 2015 22:50:18 -0400 X-Received: by 10.52.166.12 with SMTP id zc12mr30074453vdb.5.1435719003594; Tue, 30 Jun 2015 19:50:03 -0700 (PDT) X-Received: by 10.50.50.38 with SMTP id z6mr363999ign.14.1435719003551; Tue, 30 Jun 2015 19:50:03 -0700 (PDT) Original-Path: usenet.stanford.edu!t90no141542qga.0!news-out.google.com!a16ni9782ign.0!nntp.google.com!ff1no283546igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=59.94.112.100; posting-account=mBpa7woAAAAGLEWUUKpmbxm-Quu5D8ui Original-NNTP-Posting-Host: 59.94.112.100 User-Agent: G2/1.0 Injection-Date: Wed, 01 Jul 2015 02:50:03 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:213063 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:105350 Archived-At: On Wednesday, July 1, 2015 at 4:57:21 AM UTC+5:30, Emanuel Berg wrote: > Rusi writes: > > > 1. Is it possible to have some sort of save-hook so > > that all leading (indentation) whitespace is cleaned > > up to space alone and tabs are removed? > > Do this and indentation will be in whitespaces only: > > (setq-default indent-tabs-mode nil) > > Only in Makefiles you still get tabs - otherwise they > (the Makefiles) won't work. > > But to answer your question, yes, you can use > `before-save-hook' and `untabify'. > > If you want to add exceptions, it could look like > this: > > (defun untab-all () > (unless (member major-mode '(makefile-gmake-mode > makefile-mode) ) ; exceptions > (untabify (point-min) (point-max))) > nil) ; tell 'did not write buffer to disk' > > But I think it is better to have the file as you edit > it be as close to the finished form as possible, and > not have it post-processed like that. Ok thanks Emanuel, Jorge Putting your two together I have -------------------- (add-hook 'before-save-hook 'untab-python ) (defun untab-python () (when (member major-mode '(python-mode)) (untabify (point-min) (point-max))) nil) ---------------------- 1. dunno about the save-excursion 2. member rather than equal/eq so that other modes can be added as desired