all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* delete-trailing-whitespace behavior change?
@ 2018-12-12 12:24 Skip Montanaro
  2018-12-12 17:47 ` Kaushal Modi
  0 siblings, 1 reply; 6+ messages in thread
From: Skip Montanaro @ 2018-12-12 12:24 UTC (permalink / raw)
  To: Help GNU Emacs

I've defined this hook in ~/.emacs for ages (a decade or so, I suspect):

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Recently, I've noticed that the last newline of files seems to be deleted.
Not always, but pretty frequently. I'm running 25.2.2 at home and 25.3.2 at
work. I think I switched from 24 to 25 in the past few months. I can't seem
to quickly lay my hands on Emacs 24 without going through a
download/install cycle, but I wonder if delete-trailing-whitespace might
have changed between 24 and 25?

Any insight would be appreciated...

Skip Montanaro


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

* Re: delete-trailing-whitespace behavior change?
       [not found] <mailman.5630.1544617495.1284.help-gnu-emacs@gnu.org>
@ 2018-12-12 15:40 ` Loris Bennett
  2018-12-12 17:34   ` Skip Montanaro
  2018-12-12 21:26   ` Javier
  0 siblings, 2 replies; 6+ messages in thread
From: Loris Bennett @ 2018-12-12 15:40 UTC (permalink / raw)
  To: help-gnu-emacs

Skip Montanaro <skip.montanaro@gmail.com> writes:

> I've defined this hook in ~/.emacs for ages (a decade or so, I suspect):
>
> (add-hook 'before-save-hook 'delete-trailing-whitespace)
>
> Recently, I've noticed that the last newline of files seems to be deleted.
> Not always, but pretty frequently. I'm running 25.2.2 at home and 25.3.2 at
> work. I think I switched from 24 to 25 in the past few months. I can't seem
> to quickly lay my hands on Emacs 24 without going through a
> download/install cycle, but I wonder if delete-trailing-whitespace might
> have changed between 24 and 25?
>
> Any insight would be appreciated...

I have this setting too and my Emacs 25.1.1 deletes all empty newlines
at the end of a file, which it is what it says on the tin:

  If this command acts on the entire buffer (i.e. if called
  interactively with the mark inactive, or called from Lisp with END
  nil), it also deletes all trailing lines at the end of the buffer if
  the variable ‘delete-trailing-lines’ is non-nil.

The 24.5.1 tins say the same thing.

Cheers,

Loris

-- 
This signature is currently under construction.


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

* Re: delete-trailing-whitespace behavior change?
  2018-12-12 15:40 ` delete-trailing-whitespace behavior change? Loris Bennett
@ 2018-12-12 17:34   ` Skip Montanaro
  2018-12-12 21:26   ` Javier
  1 sibling, 0 replies; 6+ messages in thread
From: Skip Montanaro @ 2018-12-12 17:34 UTC (permalink / raw)
  To: loris.bennett; +Cc: Help GNU Emacs

> I have this setting too and my Emacs 25.1.1 deletes all empty newlines
> at the end of a file, ...

Sorry, I probably wasn't clear in my original message. What I see is
that the newline at the end of the last non-empty line is deleted. So,
consider that I have this buffer (using C/Python/etc string notation
to make clear what I have):

"abc\ndef\nghi\n"

When written, it sometimes (maybe always, but I'm not certain of that)
results in

"abc\ndef\nghi"

That doesn't seem correct to me.

Skip



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

* Re: delete-trailing-whitespace behavior change?
  2018-12-12 12:24 Skip Montanaro
@ 2018-12-12 17:47 ` Kaushal Modi
  0 siblings, 0 replies; 6+ messages in thread
From: Kaushal Modi @ 2018-12-12 17:47 UTC (permalink / raw)
  To: skip.montanaro; +Cc: Help Gnu Emacs mailing list

On Wed, Dec 12, 2018 at 7:25 AM Skip Montanaro <skip.montanaro@gmail.com> wrote:
> Recently, I've noticed that the last newline of files seems to be deleted.
> Not always, but pretty frequently.

I don't know how this would cause randomness in deleting the final
newline, but do you have the variable require-final-newline set to nil
(default) by any chance.

If it is nil, a final newline is not auto-inserted. But if set to t,
that final newline is auto inserted on saving a file.



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

* Re: delete-trailing-whitespace behavior change?
  2018-12-12 15:40 ` delete-trailing-whitespace behavior change? Loris Bennett
  2018-12-12 17:34   ` Skip Montanaro
@ 2018-12-12 21:26   ` Javier
  2018-12-13  3:51     ` Skip Montanaro
  1 sibling, 1 reply; 6+ messages in thread
From: Javier @ 2018-12-12 21:26 UTC (permalink / raw)
  To: help-gnu-emacs

Loris Bennett <loris.bennett@fu-berlin.de> wrote:
> I have this setting too and my Emacs 25.1.1 deletes all empty newlines
> at the end of a file, which it is what it says on the tin:
> 
>   If this command acts on the entire buffer (i.e. if called
>   interactively with the mark inactive, or called from Lisp with END
>   nil), it also deletes all trailing lines at the end of the buffer if
>   the variable ‘delete-trailing-lines’ is non-nil.
> 
> The 24.5.1 tins say the same thing.

The option delete-trailing-lines appeared in version 24.3.
So there may be a change of behaviour between 24.1, 24.2 and 25.x

From /usr/share/emacs/*/etc/NEWS*

    * Editing Changes in Emacs 24.3
    ** New option `delete-trailing-lines' specifies whether
    M-x delete-trailing-whitespace should delete trailing lines at the end
    of the buffer.  It defaults to t.


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

* Re: delete-trailing-whitespace behavior change?
  2018-12-12 21:26   ` Javier
@ 2018-12-13  3:51     ` Skip Montanaro
  0 siblings, 0 replies; 6+ messages in thread
From: Skip Montanaro @ 2018-12-13  3:51 UTC (permalink / raw)
  To: Help GNU Emacs

Thanks for the responses. This has been going on for awhile now, and
precisely because of that randomness Kaushal mentioned, I've been
hesitant to report the problem before. I can't say that it happens
only at work, or at work and at home. I'm not even certain it's an
Emacs issue. It's possible some something injected into the toolchain
(maybe a git hook?) has been wreaking havoc with final newlines. Alas,
most other people at work are vim users (and don't write much Python
code) and could care less about extra whitespace, so my
before-write-hook often deletes a few spaces.

Regarding variables, both delete-trailing-lines and
require-final-newline are t. Neither is tweaked in ~/.emacs.

Skip



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

end of thread, other threads:[~2018-12-13  3:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.5630.1544617495.1284.help-gnu-emacs@gnu.org>
2018-12-12 15:40 ` delete-trailing-whitespace behavior change? Loris Bennett
2018-12-12 17:34   ` Skip Montanaro
2018-12-12 21:26   ` Javier
2018-12-13  3:51     ` Skip Montanaro
2018-12-12 12:24 Skip Montanaro
2018-12-12 17:47 ` Kaushal Modi

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.