* whitespace-cleanup + untabify?
@ 2008-06-14 10:56 dsevilla
2008-06-14 12:02 ` Juanma Barranquero
` (7 more replies)
0 siblings, 8 replies; 15+ messages in thread
From: dsevilla @ 2008-06-14 10:56 UTC (permalink / raw)
To: help-gnu-emacs
Dear all:
I'm a no tab person. I would like my whitespace-cleanup command to
also perform an untabify. How can this be done? I haven't found any
option that connects untabify and whitespace-cleanup. I'm using:
GNU Emacs 23.0.60.1 (i486-pc-linux-gnu, GTK+ Version 2.12.9)
I would really appreciate the help.
Regards,
diego.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-14 10:56 whitespace-cleanup + untabify? dsevilla
@ 2008-06-14 12:02 ` Juanma Barranquero
2008-06-14 12:03 ` Nikolaj Schumacher
` (6 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Juanma Barranquero @ 2008-06-14 12:02 UTC (permalink / raw)
To: dsevilla@gmail.com; +Cc: help-gnu-emacs
On Sat, Jun 14, 2008 at 12:56, dsevilla@gmail.com <dsevilla@gmail.com> wrote:
> I haven't found any
> option that connects untabify and whitespace-cleanup. I'm using:
That really depends on how do you want to do the untabify.
For example, you can defadvice `whitespace-cleanup' like so
(defadvice whitespace-cleanup (after whitespace-untabify activate compile)
(save-restriction
(widen)
(untabify (point-min) (point-max))))
so when you do M-x whitespace cleanup, it first cleans up and then
untabifies. Take into account that untabify removes tabs anywhere in
the line; if you prefer only to untabify at the beginning of line, you
could use this instead:
(defadvice whitespace-cleanup (after whitespace-untabify activate compile)
(save-restriction
(widen)
(let ((tabify-regexp "^\t* [ \t]+"))
(untabify (point-min) (point-max)))))
Both examples untabify the whole buffer (that's what the
`save-restriction' and `widen' calls are for), so if you in fact only
want to untabify the region, it's even simpler:
(defadvice whitespace-cleanup (after whitespace-untabify activate compile)
(untabify (point-min) (point-max)))
Does this help?
Juanma
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-14 10:56 whitespace-cleanup + untabify? dsevilla
2008-06-14 12:02 ` Juanma Barranquero
@ 2008-06-14 12:03 ` Nikolaj Schumacher
2008-06-14 12:37 ` Kevin Rodgers
` (5 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Nikolaj Schumacher @ 2008-06-14 12:03 UTC (permalink / raw)
To: dsevilla@gmail.com; +Cc: help-gnu-emacs
"dsevilla@gmail.com" <dsevilla@gmail.com> wrote:
> I'm a no tab person. I would like my whitespace-cleanup command to
> also perform an untabify. How can this be done? I haven't found any
> option that connects untabify and whitespace-cleanup. I'm using:
Just write your own command:
(defun my-whitespace-cleanup ()
(interactive)
(whitespace-cleanup)
(untabify (point-min) (point-max)))
regards,
Nikolaj Schumacher
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-14 10:56 whitespace-cleanup + untabify? dsevilla
2008-06-14 12:02 ` Juanma Barranquero
2008-06-14 12:03 ` Nikolaj Schumacher
@ 2008-06-14 12:37 ` Kevin Rodgers
2008-06-14 16:49 ` Nikolaj Schumacher
2008-06-14 13:43 ` Juanma
` (4 subsequent siblings)
7 siblings, 1 reply; 15+ messages in thread
From: Kevin Rodgers @ 2008-06-14 12:37 UTC (permalink / raw)
To: help-gnu-emacs
dsevilla@gmail.com wrote:
> I'm a no tab person. I would like my whitespace-cleanup command to
> also perform an untabify. How can this be done? I haven't found any
> option that connects untabify and whitespace-cleanup. I'm using:
>
> GNU Emacs 23.0.60.1 (i486-pc-linux-gnu, GTK+ Version 2.12.9)
>
> I would really appreciate the help.
It's not documented, but because whitespace-global-mode is defined
via define-minor-mode there should be whitespace-global-mode-hook.
So perhaps something like this will work:
(add-hook 'whitespace-global-mode-hook
(lambda ()
(when whitespace-global-mode
(untabify (point-min) (point-max)))))
Alternatively, you could hook directly into find-file-hook,
write-file-functions, and kill-buffer-hook just like
whitespace-global-mode does.
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-14 10:56 whitespace-cleanup + untabify? dsevilla
` (2 preceding siblings ...)
2008-06-14 12:37 ` Kevin Rodgers
@ 2008-06-14 13:43 ` Juanma
2008-06-14 15:02 ` Rupert Swarbrick
` (3 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Juanma @ 2008-06-14 13:43 UTC (permalink / raw)
To: help-gnu-emacs
On Saturday 14 June 2008, dsevilla@gmail.com wrote:
> Dear all:
>
> I'm a no tab person. I would like my whitespace-cleanup command to
> also perform an untabify. How can this be done? I haven't found any
> option that connects untabify and whitespace-cleanup. I'm using:
It's easy to put things together in your own function:
(defun my-whitespace-cleanup ()
(interactive)
(whitespace-cleanup)
(call-interactively 'untabify))
That's the quick&dirty-est way and you should mark a region to use it (as it
would be for 'untabify' anyway). Bind it to a key. Done.
But, does 'whitespace-cleanup' work for you? I mean, the documentation of
`whitespace-buffer' says:
+-----------------------------------------------------------------------------+
| 3. Indentation space (8 or more spaces, that should be replaced with TABS). |
+-----------------------------------------------------------------------------+
Saludos,
Juan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-14 10:56 whitespace-cleanup + untabify? dsevilla
` (3 preceding siblings ...)
2008-06-14 13:43 ` Juanma
@ 2008-06-14 15:02 ` Rupert Swarbrick
2008-06-14 15:10 ` dsevilla
2008-06-14 16:24 ` Lennart Borgman (gmail)
` (2 subsequent siblings)
7 siblings, 1 reply; 15+ messages in thread
From: Rupert Swarbrick @ 2008-06-14 15:02 UTC (permalink / raw)
To: help-gnu-emacs
"dsevilla@gmail.com" <dsevilla@gmail.com> writes:
> Dear all:
>
> I'm a no tab person. I would like my whitespace-cleanup command to
> also perform an untabify. How can this be done? I haven't found any
> option that connects untabify and whitespace-cleanup. I'm using:
>
> GNU Emacs 23.0.60.1 (i486-pc-linux-gnu, GTK+ Version 2.12.9)
>
> I would really appreciate the help.
>
> Regards,
> diego.
I hope I've understood the problem correctly: it seems you want a
command to run whitespace-cleanup and untabify on the current
buffer. As far as I know such a command doesn't exist...
(defun both-cleanups ()
(interactive)
(untabify (point-min) (point-max))
(whitespace-cleanup))
... well, it does now!
I must admit I've never used whitespace-cleanup before, and can't get
it to do anything! But that applies to calling it manually too, so I
presume this will work ok for you.
You probably want to give it a better name and/or a keybinding.
Rupert
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-14 15:02 ` Rupert Swarbrick
@ 2008-06-14 15:10 ` dsevilla
0 siblings, 0 replies; 15+ messages in thread
From: dsevilla @ 2008-06-14 15:10 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 14, 5:02 pm, Rupert Swarbrick <rswarbr...@gmail.com> wrote:
> "dsevi...@gmail.com" <dsevi...@gmail.com> writes:
> > Dear all:
>
> > I'm a no tab person. I would like my whitespace-cleanup command to
> > also perform an untabify. How can this be done? I haven't found any
> > option that connects untabify and whitespace-cleanup. I'm using:
>
> > GNU Emacs 23.0.60.1 (i486-pc-linux-gnu, GTK+ Version 2.12.9)
>
> > I would really appreciate the help.
>
> > Regards,
> > diego.
>
> I hope I've understood the problem correctly: it seems you want a
> command to run whitespace-cleanup and untabify on the current
> buffer. As far as I know such a command doesn't exist...
>
> (defun both-cleanups ()
> (interactive)
> (untabify (point-min) (point-max))
> (whitespace-cleanup))
>
> ... well, it does now!
>
> I must admit I've never used whitespace-cleanup before, and can't get
> it to do anything! But that applies to calling it manually too, so I
> presume this will work ok for you.
>
> You probably want to give it a better name and/or a keybinding.
>
> Rupert
Really thanks, Rupert, that was it.
I thought you could configure whitespace cleanup command (that is, the
Whitespace group of Emacs) so that you could decide either if several
spaces were converted to a tab (depending on the default tab size or
the one defined locally for the buffer) or just all the tabs and
spaces were converted to just spaces.
Thanks again, I'll try this.
diego.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-14 10:56 whitespace-cleanup + untabify? dsevilla
` (4 preceding siblings ...)
2008-06-14 15:02 ` Rupert Swarbrick
@ 2008-06-14 16:24 ` Lennart Borgman (gmail)
[not found] ` <mailman.13261.1213458961.18990.help-gnu-emacs@gnu.org>
[not found] ` <mailman.13267.1213460678.18990.help-gnu-emacs@gnu.org>
7 siblings, 0 replies; 15+ messages in thread
From: Lennart Borgman (gmail) @ 2008-06-14 16:24 UTC (permalink / raw)
To: dsevilla@gmail.com; +Cc: help-gnu-emacs
dsevilla@gmail.com wrote:
> Dear all:
>
> I'm a no tab person. I would like my whitespace-cleanup command to
> also perform an untabify. How can this be done? I haven't found any
> option that connects untabify and whitespace-cleanup. I'm using:
>
> GNU Emacs 23.0.60.1 (i486-pc-linux-gnu, GTK+ Version 2.12.9)
I have never used whitespace-cleanup (I use delete-trailing-whitespace),
but from the doc of this function it looks like it also untabifies if
`indent-tabs-mode' is nil. Does not that work?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-14 12:37 ` Kevin Rodgers
@ 2008-06-14 16:49 ` Nikolaj Schumacher
0 siblings, 0 replies; 15+ messages in thread
From: Nikolaj Schumacher @ 2008-06-14 16:49 UTC (permalink / raw)
To: Kevin Rodgers; +Cc: help-gnu-emacs
Kevin Rodgers <kevin.d.rodgers@gmail.com> wrote:
> It's not documented, but because whitespace-global-mode is defined
> via define-minor-mode there should be whitespace-global-mode-hook.
> So perhaps something like this will work:
>
> (add-hook 'whitespace-global-mode-hook
> (lambda ()
> (when whitespace-global-mode
> (untabify (point-min) (point-max)))))
That won't work. It will probably only untabify the .emacs file.
It should instead add an `untabify' variant to
'find-file-hook, 'write-file-functions and 'kill-buffer-hook.
Of course that would ignore the setting of `whitespace-auto-cleanup',
and would stay active after the mode has been disabled.
I think the cleanest way would be a parallel mode:
(defun untabify-buffer ()
(untabify (point-min) (point-max))
nil ;; for write-file-functions
)
(define-minor-mode untabify-global-mode
:global t
:group 'whitespace
(if untabify-global-mode
(progn
(add-hook 'find-file-hook 'untabify-buffer)
(add-hook 'write-file-functions 'untabify-buffer nil t)
(add-hook 'kill-buffer-hook 'untabify-buffer))
(remove-hook 'find-file-hook 'untabify-buffer)
(remove-hook 'write-file-functions 'untabify-buffer t)
(remove-hook 'kill-buffer-hook 'untabify-buffer)))
(Not tested.)
regards,
Nikolaj Schumacher
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
[not found] ` <mailman.13261.1213458961.18990.help-gnu-emacs@gnu.org>
@ 2008-06-15 20:05 ` dsevilla
0 siblings, 0 replies; 15+ messages in thread
From: dsevilla @ 2008-06-15 20:05 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 14, 3:43 pm, Juanma <juanma_bel...@yahoo.es> wrote:
> On Saturday 14 June 2008, dsevi...@gmail.com wrote:
>
> > Dear all:
>
> > I'm a no tab person. I would like my whitespace-cleanup command to
> > also perform an untabify. How can this be done? I haven't found any
> > option that connects untabify and whitespace-cleanup. I'm using:
>
> It's easy to put things together in your own function:
>
> (defun my-whitespace-cleanup ()
> (interactive)
> (whitespace-cleanup)
> (call-interactively 'untabify))
>
> That's the quick&dirty-est way and you should mark a region to use it (as it
> would be for 'untabify' anyway). Bind it to a key. Done.
>
> But, does 'whitespace-cleanup' work for you? I mean, the documentation of
> `whitespace-buffer' says:
> +-----------------------------------------------------------------------------+
> | 3. Indentation space (8 or more spaces, that should be replaced with TABS). |
> +-----------------------------------------------------------------------------+
>
> Saludos,
> Juan
Hello, Juan:
Yes, it has worked always. It does what it should do, but certain tabs
weren't converted to spaces (as I wanted) and/or it inserted tabs (I
haven't tested this one, but still). What I wanted was to remove tabs
and substitute them by spaces. The solutions of defining a new
function worked nicely.
Thanks,
diego.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
[not found] ` <mailman.13267.1213460678.18990.help-gnu-emacs@gnu.org>
@ 2008-06-15 20:07 ` dsevilla
2008-06-15 20:53 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 15+ messages in thread
From: dsevilla @ 2008-06-15 20:07 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 14, 6:24 pm, "Lennart Borgman (gmail)"
<lennart.borg...@gmail.com> wrote:
> dsevi...@gmail.com wrote:
> > Dear all:
>
> > I'm a no tab person. I would like my whitespace-cleanup command to
> > also perform an untabify. How can this be done? I haven't found any
> > option that connects untabify and whitespace-cleanup. I'm using:
>
> > GNU Emacs 23.0.60.1 (i486-pc-linux-gnu, GTK+ Version 2.12.9)
>
> I have never used whitespace-cleanup (I use delete-trailing-whitespace),
> but from the doc of this function it looks like it also untabifies if
> `indent-tabs-mode' is nil. Does not that work?
Hi, Lennart:
Yes, that's what I thought, but was not the case, as if I applied
whitespace-cleanup and then untabify, the file was modified (that is,
it still converted *some* tabs to spaces), so I assumed it didn't work
this way. I had indent-tabs-mode set to nil also.
Thanks,
diego.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-15 20:07 ` dsevilla
@ 2008-06-15 20:53 ` Lennart Borgman (gmail)
2008-06-15 21:23 ` Nikolaj Schumacher
0 siblings, 1 reply; 15+ messages in thread
From: Lennart Borgman (gmail) @ 2008-06-15 20:53 UTC (permalink / raw)
To: dsevilla@gmail.com; +Cc: help-gnu-emacs
dsevilla@gmail.com wrote:
> On Jun 14, 6:24 pm, "Lennart Borgman (gmail)"
> <lennart.borg...@gmail.com> wrote:
>> dsevi...@gmail.com wrote:
>>> Dear all:
>>> I'm a no tab person. I would like my whitespace-cleanup command to
>>> also perform an untabify. How can this be done? I haven't found any
>>> option that connects untabify and whitespace-cleanup. I'm using:
>>> GNU Emacs 23.0.60.1 (i486-pc-linux-gnu, GTK+ Version 2.12.9)
>> I have never used whitespace-cleanup (I use delete-trailing-whitespace),
>> but from the doc of this function it looks like it also untabifies if
>> `indent-tabs-mode' is nil. Does not that work?
>
> Hi, Lennart:
>
> Yes, that's what I thought, but was not the case, as if I applied
> whitespace-cleanup and then untabify, the file was modified (that is,
> it still converted *some* tabs to spaces), so I assumed it didn't work
> this way. I had indent-tabs-mode set to nil also.
>
> Thanks,
> diego.
Hi diego
In that case it looks like a bug to me. Could you please send a bug report
M-x report-emacs-bug
You need to attach an example and exact instructions (starting from
"emacs -Q").
Thanks.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-15 20:53 ` Lennart Borgman (gmail)
@ 2008-06-15 21:23 ` Nikolaj Schumacher
2008-06-15 21:32 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 15+ messages in thread
From: Nikolaj Schumacher @ 2008-06-15 21:23 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: help-gnu-emacs, dsevilla@gmail.com
"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> wrote:
>>> I have never used whitespace-cleanup (I use delete-trailing-whitespace),
>>> but from the doc of this function it looks like it also untabifies if
>>> `indent-tabs-mode' is nil. Does not that work?
>>
>> Yes, that's what I thought, but was not the case, as if I applied
>> whitespace-cleanup and then untabify, the file was modified (that is,
>> it still converted *some* tabs to spaces), so I assumed it didn't work
>> this way. I had indent-tabs-mode set to nil also.
>
> In that case it looks like a bug to me. Could you please send a bug report
From the documentation it appears to me that it will transform 8
spaces to tabs, but not vice-versa. So I don't think it's necessarily a
bug. But I do think it would be a good feature to add.
regards,
Nikolaj Schumacher
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-15 21:23 ` Nikolaj Schumacher
@ 2008-06-15 21:32 ` Lennart Borgman (gmail)
2008-06-16 6:28 ` Thierry Volpiatto
0 siblings, 1 reply; 15+ messages in thread
From: Lennart Borgman (gmail) @ 2008-06-15 21:32 UTC (permalink / raw)
To: Nikolaj Schumacher; +Cc: help-gnu-emacs, dsevilla@gmail.com
Nikolaj Schumacher wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> wrote:
>
>>>> I have never used whitespace-cleanup (I use delete-trailing-whitespace),
>>>> but from the doc of this function it looks like it also untabifies if
>>>> `indent-tabs-mode' is nil. Does not that work?
>>> Yes, that's what I thought, but was not the case, as if I applied
>>> whitespace-cleanup and then untabify, the file was modified (that is,
>>> it still converted *some* tabs to spaces), so I assumed it didn't work
>>> this way. I had indent-tabs-mode set to nil also.
>> In that case it looks like a bug to me. Could you please send a bug report
>
>>From the documentation it appears to me that it will transform 8
> spaces to tabs, but not vice-versa. So I don't think it's necessarily a
> bug. But I do think it would be a good feature to add.
You might be right about the doc, I don't understand it ;-)
It looks like a simple alternative that is equivalent to untabify +
delete-trailing-whitespace indeed is a good feature to add.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: whitespace-cleanup + untabify?
2008-06-15 21:32 ` Lennart Borgman (gmail)
@ 2008-06-16 6:28 ` Thierry Volpiatto
0 siblings, 0 replies; 15+ messages in thread
From: Thierry Volpiatto @ 2008-06-16 6:28 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: help-gnu-emacs, dsevilla@gmail.com
"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> Nikolaj Schumacher wrote:
>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> wrote:
>>
>>>>> I have never used whitespace-cleanup (I use delete-trailing-whitespace),
>>>>> but from the doc of this function it looks like it also untabifies if
>>>>> `indent-tabs-mode' is nil. Does not that work?
>>>> Yes, that's what I thought, but was not the case, as if I applied
>>>> whitespace-cleanup and then untabify, the file was modified (that is,
>>>> it still converted *some* tabs to spaces), so I assumed it didn't work
>>>> this way. I had indent-tabs-mode set to nil also.
>>> In that case it looks like a bug to me. Could you please send a bug report
>>
>>>From the documentation it appears to me that it will transform 8
>> spaces to tabs, but not vice-versa. So I don't think it's necessarily a
>> bug. But I do think it would be a good feature to add.
>
> You might be right about the doc, I don't understand it ;-)
>
> It looks like a simple alternative that is equivalent to untabify +
> delete-trailing-whitespace indeed is a good feature to add.
>
>
Hello all,
did somebody try something like:
,----
| (add-hook 'picture-mode-hook 'untabify)
`----
Not tested but it should work.
--
A + Thierry
Pub key: http://pgp.mit.edu
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2008-06-16 6:28 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-14 10:56 whitespace-cleanup + untabify? dsevilla
2008-06-14 12:02 ` Juanma Barranquero
2008-06-14 12:03 ` Nikolaj Schumacher
2008-06-14 12:37 ` Kevin Rodgers
2008-06-14 16:49 ` Nikolaj Schumacher
2008-06-14 13:43 ` Juanma
2008-06-14 15:02 ` Rupert Swarbrick
2008-06-14 15:10 ` dsevilla
2008-06-14 16:24 ` Lennart Borgman (gmail)
[not found] ` <mailman.13261.1213458961.18990.help-gnu-emacs@gnu.org>
2008-06-15 20:05 ` dsevilla
[not found] ` <mailman.13267.1213460678.18990.help-gnu-emacs@gnu.org>
2008-06-15 20:07 ` dsevilla
2008-06-15 20:53 ` Lennart Borgman (gmail)
2008-06-15 21:23 ` Nikolaj Schumacher
2008-06-15 21:32 ` Lennart Borgman (gmail)
2008-06-16 6:28 ` Thierry Volpiatto
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).