unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* whitespace issues
@ 2015-06-30 14:17 Rusi
  2015-06-30 14:54 ` tomas
                   ` (9 more replies)
  0 siblings, 10 replies; 15+ messages in thread
From: Rusi @ 2015-06-30 14:17 UTC (permalink / raw)
  To: help-gnu-emacs

I have two somewhat related questions, both around whitespace:

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?


2. How to make a dirty crlf file in emacs?
By dirty I mean, some lines ending LF (ie Unix) and some ending CRLF (ie DOS)
[This is to test that such dirty-files are not add-able into git]


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
  2015-06-30 14:17 whitespace issues Rusi
@ 2015-06-30 14:54 ` tomas
       [not found] ` <mailman.6025.1435676084.904.help-gnu-emacs@gnu.org>
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: tomas @ 2015-06-30 14:54 UTC (permalink / raw)
  To: Rusi; +Cc: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, Jun 30, 2015 at 07:17:39AM -0700, Rusi wrote:
> I have two somewhat related questions, both around whitespace:
> 
> 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?

I'll leave that to more knowledgeable.

> 2. How to make a dirty crlf file in emacs?
> By dirty I mean, some lines ending LF (ie Unix) and some ending CRLF (ie DOS)
> [This is to test that such dirty-files are not add-able into git]

Since CR == CTLR-M, create a file with a buffer coding system
whatever-nix (e.g. utf8-unix). This is the default on a sensible
operating system anyway :-)

At the end of a line, type CTRL-Q CTRL-M -- voilà, this line has crlf
at its end. Check either with hexl-mode, or outside Emacs with hexdump -C.

regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlWSraQACgkQBcgs9XrR2kZ89ACfSaNmH/5SeCDcV5r+yAnVZbig
MtMAn2ogT/O7Z6vHpFBctGwobLonf+HG
=MoaO
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
       [not found] ` <mailman.6025.1435676084.904.help-gnu-emacs@gnu.org>
@ 2015-06-30 14:57   ` Rusi
  0 siblings, 0 replies; 15+ messages in thread
From: Rusi @ 2015-06-30 14:57 UTC (permalink / raw)
  To: help-gnu-emacs

On Tuesday, June 30, 2015 at 8:24:46 PM UTC+5:30, to...@tuxteam.de wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Tue, Jun 30, 2015 at 07:17:39AM -0700, Rusi wrote:
> > I have two somewhat related questions, both around whitespace:
> > 
> > 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?
> 
> I'll leave that to more knowledgeable.
> 
> > 2. How to make a dirty crlf file in emacs?
> > By dirty I mean, some lines ending LF (ie Unix) and some ending CRLF (ie DOS)
> > [This is to test that such dirty-files are not add-able into git]
> 
> Since CR == CTLR-M, create a file with a buffer coding system
> whatever-nix (e.g. utf8-unix). This is the default on a sensible
> operating system anyway :-)
> 
> At the end of a line, type CTRL-Q CTRL-M -- voilà, this line has crlf
> at its end. Check either with hexl-mode, or outside Emacs with hexdump -C.

Neat! Thanks!
[Its 2015 and our version systems cant get this right]


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
  2015-06-30 14:17 whitespace issues Rusi
  2015-06-30 14:54 ` tomas
       [not found] ` <mailman.6025.1435676084.904.help-gnu-emacs@gnu.org>
@ 2015-06-30 15:03 ` Jorge A. Alfaro-Murillo
  2015-06-30 15:06 ` Óscar Fuentes
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2015-06-30 15:03 UTC (permalink / raw)
  To: help-gnu-emacs

Rusi writes:

> I have two somewhat related questions, both around whitespace: 
> 
> 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?

(add-hook 'before-save-hook 
          (lambda () (save-excursion (untabify (point-min) 
          (point-max)))))

> 2. How to make a dirty crlf file in emacs? By dirty I mean, some 
> lines ending LF (ie Unix) and some ending CRLF (ie DOS) [This is 
> to test that such dirty-files are not add-able into git]

This I don't know.

Best,
-- 
Jorge.




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
  2015-06-30 14:17 whitespace issues Rusi
                   ` (2 preceding siblings ...)
  2015-06-30 15:03 ` Jorge A. Alfaro-Murillo
@ 2015-06-30 15:06 ` Óscar Fuentes
  2015-06-30 15:24 ` Ian Zimmerman
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Óscar Fuentes @ 2015-06-30 15:06 UTC (permalink / raw)
  To: help-gnu-emacs

Rusi <rustompmody@gmail.com> writes:

> I have two somewhat related questions, both around whitespace:
>
> 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?

https://github.com/purcell/whitespace-cleanup-mode

I use https://github.com/lewang/ws-butler which smarter in the sense
that only cleans the lines you touched.

[snip]




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
  2015-06-30 14:17 whitespace issues Rusi
                   ` (3 preceding siblings ...)
  2015-06-30 15:06 ` Óscar Fuentes
@ 2015-06-30 15:24 ` Ian Zimmerman
       [not found] ` <mailman.6026.1435676539.904.help-gnu-emacs@gnu.org>
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Ian Zimmerman @ 2015-06-30 15:24 UTC (permalink / raw)
  To: help-gnu-emacs

On 2015-06-30 07:17 -0700, Rusi wrote:

> 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?

Yes, see write-file-functions and untabify

> 2. How to make a dirty crlf file in emacs?  By dirty I mean, some
> lines ending LF (ie Unix) and some ending CRLF (ie DOS)

Emacs is probably the wrong tool for this, I would try some combination
of sed, tr, awk, jot

-- 
Please *no* private copies of mailing list or newsgroup messages.
Rule 420: All persons more than eight miles high to leave the court.




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
       [not found] ` <mailman.6026.1435676539.904.help-gnu-emacs@gnu.org>
@ 2015-06-30 16:21   ` Rusi
  2015-06-30 16:35     ` Rasmus
  0 siblings, 1 reply; 15+ messages in thread
From: Rusi @ 2015-06-30 16:21 UTC (permalink / raw)
  To: help-gnu-emacs

On Tuesday, June 30, 2015 at 8:32:21 PM UTC+5:30, Jorge A. Alfaro-Murillo wrote:
> Rusi writes:
> 
> > I have two somewhat related questions, both around whitespace: 
> > 
> > 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?
> 
> (add-hook 'before-save-hook 
>           (lambda () (save-excursion (untabify (point-min) 
>           (point-max)))))

How to have this only for (say) python-mode?


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
  2015-06-30 14:17 whitespace issues Rusi
                   ` (5 preceding siblings ...)
       [not found] ` <mailman.6026.1435676539.904.help-gnu-emacs@gnu.org>
@ 2015-06-30 16:27 ` Dan Espen
  2015-06-30 23:25 ` Emanuel Berg
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Dan Espen @ 2015-06-30 16:27 UTC (permalink / raw)
  To: help-gnu-emacs

Rusi <rustompmody@gmail.com> writes:

> I have two somewhat related questions, both around whitespace:
>
> 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?

Yes, but if you set indent-tabs-mode to nil hitting tab will
insert spaces instead of tabs so you won't have to remove tabs.

-- 
Dan Espen


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
  2015-06-30 16:21   ` Rusi
@ 2015-06-30 16:35     ` Rasmus
  0 siblings, 0 replies; 15+ messages in thread
From: Rasmus @ 2015-06-30 16:35 UTC (permalink / raw)
  To: help-gnu-emacs

Rusi <rustompmody@gmail.com> writes:

> How to have this only for (say) python-mode?

Condition on the mode, (member major-mode list-of-rm-tab-modes).

Rasmus

-- 
Warning: Everything saved will be lost




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
  2015-06-30 14:17 whitespace issues Rusi
                   ` (6 preceding siblings ...)
  2015-06-30 16:27 ` Dan Espen
@ 2015-06-30 23:25 ` Emanuel Berg
       [not found] ` <mailman.6027.1435676795.904.help-gnu-emacs@gnu.org>
       [not found] ` <mailman.6071.1435706838.904.help-gnu-emacs@gnu.org>
  9 siblings, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2015-06-30 23:25 UTC (permalink / raw)
  To: help-gnu-emacs

Rusi <rustompmody@gmail.com> 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.

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
       [not found] ` <mailman.6027.1435676795.904.help-gnu-emacs@gnu.org>
@ 2015-07-01  2:37   ` Rusi
  2015-07-01  8:06     ` tomas
  0 siblings, 1 reply; 15+ messages in thread
From: Rusi @ 2015-07-01  2:37 UTC (permalink / raw)
  To: help-gnu-emacs

On Tuesday, June 30, 2015 at 8:36:37 PM UTC+5:30, Óscar Fuentes wrote:
> Rusi  writes:
>
> > I have two somewhat related questions, both around whitespace:
> >
> > 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?
> 
> https://github.com/purcell/whitespace-cleanup-mode
> 
> I use https://github.com/lewang/ws-butler which smarter in the sense
> that only cleans the lines you touched.

Thanks Oscar -- looks interesting.
But this is not so much for me as for my kids er... students, and would like to
minimize moving parts like extra installs


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
       [not found] ` <mailman.6071.1435706838.904.help-gnu-emacs@gnu.org>
@ 2015-07-01  2:50   ` Rusi
  2015-07-01 14:33     ` Jorge A. Alfaro-Murillo
  2015-07-01 17:14     ` Emanuel Berg
  0 siblings, 2 replies; 15+ messages in thread
From: Rusi @ 2015-07-01  2:50 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
  2015-07-01  2:37   ` Rusi
@ 2015-07-01  8:06     ` tomas
  0 siblings, 0 replies; 15+ messages in thread
From: tomas @ 2015-07-01  8:06 UTC (permalink / raw)
  To: Rusi; +Cc: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, Jun 30, 2015 at 07:37:17PM -0700, Rusi wrote:
> On Tuesday, June 30, 2015 at 8:36:37 PM UTC+5:30, Óscar Fuentes wrote:
> > Rusi  writes:
> >
> > > I have two somewhat related questions, both around whitespace:
> > >
> > > 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?
> > 
> > https://github.com/purcell/whitespace-cleanup-mode

I don't know whether it has been mentioned in the thread, but there's
a "whitespace-cleanup" which is part of the standard Emacs distribution.

I use it from time to time, whenever I suspect that whitespace is
messed up in a file. Very handy.

- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlWTn58ACgkQBcgs9XrR2kbVVwCeIw3pwcPaDWH+vL8WZ3g8Y6l4
nPoAn0zOEPp8X1EQ6gqfKlswnvUfO+B6
=Favr
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
  2015-07-01  2:50   ` Rusi
@ 2015-07-01 14:33     ` Jorge A. Alfaro-Murillo
  2015-07-01 17:14     ` Emanuel Berg
  1 sibling, 0 replies; 15+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2015-07-01 14:33 UTC (permalink / raw)
  To: help-gnu-emacs

Rusi writes:
 
> 1. dunno about the save-excursion

That makes saves the point, the mark, and the current buffer and 
the restores those things after it is done. I don't think you need 
it in this case as untabify, point-min and point-max don't move 
the point or the mark.

-- 
Jorge.




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: whitespace issues
  2015-07-01  2:50   ` Rusi
  2015-07-01 14:33     ` Jorge A. Alfaro-Murillo
@ 2015-07-01 17:14     ` Emanuel Berg
  1 sibling, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2015-07-01 17:14 UTC (permalink / raw)
  To: help-gnu-emacs

Rusi <rustompmody@gmail.com> writes:

> (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

You don't need it. Examine `untabify' as that is the
only thing that could possible be the reason to use
it. It isn't, but when in doubt, isolate what is
doubted and test it.

> 2. member rather than equal/eq so that other modes
> can be added as desired

Indeed, however then should it still be named
"untab-python"? Unless there are several Python modes,
which OTOH wouldn't surprise me considering how much
extracurriculuous activity that comes with...

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-07-01 17:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-30 14:17 whitespace issues Rusi
2015-06-30 14:54 ` tomas
     [not found] ` <mailman.6025.1435676084.904.help-gnu-emacs@gnu.org>
2015-06-30 14:57   ` Rusi
2015-06-30 15:03 ` Jorge A. Alfaro-Murillo
2015-06-30 15:06 ` Óscar Fuentes
2015-06-30 15:24 ` Ian Zimmerman
     [not found] ` <mailman.6026.1435676539.904.help-gnu-emacs@gnu.org>
2015-06-30 16:21   ` Rusi
2015-06-30 16:35     ` Rasmus
2015-06-30 16:27 ` Dan Espen
2015-06-30 23:25 ` Emanuel Berg
     [not found] ` <mailman.6027.1435676795.904.help-gnu-emacs@gnu.org>
2015-07-01  2:37   ` Rusi
2015-07-01  8:06     ` tomas
     [not found] ` <mailman.6071.1435706838.904.help-gnu-emacs@gnu.org>
2015-07-01  2:50   ` Rusi
2015-07-01 14:33     ` Jorge A. Alfaro-Murillo
2015-07-01 17:14     ` Emanuel Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).