* New line and trailing whitespaces
[not found] <kcaicxrup2f3usy37v4aupgu7uvmifnxkeyc2hx5n5qpqnuj7b.ref@okar6momrmhs>
@ 2024-04-20 12:10 ` Ergus
2024-04-20 13:50 ` Eli Zaretskii
0 siblings, 1 reply; 16+ messages in thread
From: Ergus @ 2024-04-20 12:10 UTC (permalink / raw)
To: help-gnu-emacs
Hi:
Using visualstudio recently I have found a nice behavior I would like to
port to emacs.
When the cursor is in an empty line and I press enter, the cursor jumps
to the new line and indents (similar to what emacs does) but also
removes the trailing whitespaces in the previous/leaving line.
I thought to implement that behavior in emacs but I figured out that the
newline command is 1. much more complex that what I expected (creating a
lambda on the fly that then fsets to finally only use if when
non-interactive mode)
2. That non-interactive function already does something similar to the
cleaning of previous line.
SO the questions are...
1. Isn't there a way to simplify the code newline command at least to not
create a lambda on the fly? Isn't there any penalty for doing that on
every RET?
2. Isn't it better to use some pre/post hooks in order to "modularize"
the newline behavior (like electric-indent-mode, auto-fill-mode)
3. What's the recommended method to implement the desired behavior then?
Thanks in advance,
Ergus
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-20 12:10 ` New line and trailing whitespaces Ergus
@ 2024-04-20 13:50 ` Eli Zaretskii
2024-04-20 14:16 ` Eli Zaretskii
0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-20 13:50 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Sat, 20 Apr 2024 14:10:34 +0200
> From: Ergus <spacibba@aol.com>
>
> When the cursor is in an empty line and I press enter, the cursor jumps
> to the new line and indents (similar to what emacs does) but also
> removes the trailing whitespaces in the previous/leaving line.
Emacs does that since a long time ago (unless I misunderstand what you
mean). In what mode did you NOT see Emacs removing trailing
whitespace from the previous line, and can you show a recipe for
reproducing this behavior?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-20 13:50 ` Eli Zaretskii
@ 2024-04-20 14:16 ` Eli Zaretskii
2024-04-21 1:12 ` Ergus
0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-20 14:16 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Sat, 20 Apr 2024 16:50:22 +0300
> From: Eli Zaretskii <eliz@gnu.org>
>
> > Date: Sat, 20 Apr 2024 14:10:34 +0200
> > From: Ergus <spacibba@aol.com>
> >
> > When the cursor is in an empty line and I press enter, the cursor jumps
> > to the new line and indents (similar to what emacs does) but also
> > removes the trailing whitespaces in the previous/leaving line.
>
> Emacs does that since a long time ago (unless I misunderstand what you
> mean).
Just to be more specific: it's the electric-indent-mode, which is ON
by default in Emacs since v24, that does this. So if you don't see
this when you press RET, just turning electric-indent-mode should be
all you need.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-20 14:16 ` Eli Zaretskii
@ 2024-04-21 1:12 ` Ergus
2024-04-21 5:23 ` Eli Zaretskii
0 siblings, 1 reply; 16+ messages in thread
From: Ergus @ 2024-04-21 1:12 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
On Sat, Apr 20, 2024 at 05:16:37PM GMT, Eli Zaretskii wrote:
>> Date: Sat, 20 Apr 2024 16:50:22 +0300
>> From: Eli Zaretskii <eliz@gnu.org>
>>
>> > Date: Sat, 20 Apr 2024 14:10:34 +0200
>> > From: Ergus <spacibba@aol.com>
>> >
>> > When the cursor is in an empty line and I press enter, the cursor jumps
>> > to the new line and indents (similar to what emacs does) but also
>> > removes the trailing whitespaces in the previous/leaving line.
>>
>> Emacs does that since a long time ago (unless I misunderstand what you
>> mean).
>
>Just to be more specific: it's the electric-indent-mode, which is ON
>by default in Emacs since v24, that does this. So if you don't see
>this when you press RET, just turning electric-indent-mode should be
>all you need.
>
Hi Eli:
This was it... very thanks. For me these two (indentation and cleanup)
were unrelated features. Because I disabled the indentation but I would
like to keep the cleanup... Any way I can live with it.
A somehow unrelate question.. I don't find a face to change the tab-mark
color in whitespace mode... Is it documented somewhere?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-21 1:12 ` Ergus
@ 2024-04-21 5:23 ` Eli Zaretskii
2024-04-21 21:05 ` Ergus
0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-21 5:23 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Sun, 21 Apr 2024 03:12:37 +0200
> From: Ergus <spacibba@aol.com>
> Cc: help-gnu-emacs@gnu.org
>
> A somehow unrelate question.. I don't find a face to change the tab-mark
> color in whitespace mode... Is it documented somewhere?
Isn't that whitespace-tab?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-21 5:23 ` Eli Zaretskii
@ 2024-04-21 21:05 ` Ergus
2024-04-22 5:39 ` Eli Zaretskii
0 siblings, 1 reply; 16+ messages in thread
From: Ergus @ 2024-04-21 21:05 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
Hi Eli:
On Sun, Apr 21, 2024 at 08:23:45AM GMT, Eli Zaretskii wrote:
>> Date: Sun, 21 Apr 2024 03:12:37 +0200
>> From: Ergus <spacibba@aol.com>
>> Cc: help-gnu-emacs@gnu.org
>>
>> A somehow unrelate question.. I don't find a face to change the tab-mark
>> color in whitespace mode... Is it documented somewhere?
>
>Isn't that whitespace-tab?
>
Actually no.
That face seems apply only to the tab whitespace when whitespace-style
has `tabs`, but not to when `tab-mark` applies.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-21 21:05 ` Ergus
@ 2024-04-22 5:39 ` Eli Zaretskii
2024-04-22 12:22 ` Ergus
2024-04-22 12:34 ` Ergus
0 siblings, 2 replies; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-22 5:39 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Sun, 21 Apr 2024 23:05:57 +0200
> From: Ergus <spacibba@aol.com>
> Cc: help-gnu-emacs@gnu.org
>
> Hi Eli:
>
> On Sun, Apr 21, 2024 at 08:23:45AM GMT, Eli Zaretskii wrote:
> >> Date: Sun, 21 Apr 2024 03:12:37 +0200
> >> From: Ergus <spacibba@aol.com>
> >> Cc: help-gnu-emacs@gnu.org
> >>
> >> A somehow unrelate question.. I don't find a face to change the tab-mark
> >> color in whitespace mode... Is it documented somewhere?
> >
> >Isn't that whitespace-tab?
> >
> Actually no.
>
> That face seems apply only to the tab whitespace when whitespace-style
> has `tabs`, but not to when `tab-mark` applies.
You lost me here. But if all you want is to know what face is used on
some text, simply use "M-x describe-text-properties RET" with point on
that text.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-22 5:39 ` Eli Zaretskii
@ 2024-04-22 12:22 ` Ergus
2024-04-23 8:06 ` Eli Zaretskii
2024-04-22 12:34 ` Ergus
1 sibling, 1 reply; 16+ messages in thread
From: Ergus @ 2024-04-22 12:22 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
Hi Eli:
On Mon, Apr 22, 2024 at 08:39:31AM GMT, Eli Zaretskii wrote:
>> Date: Sun, 21 Apr 2024 23:05:57 +0200
>> From: Ergus <spacibba@aol.com>
>> Cc: help-gnu-emacs@gnu.org
>>
>> Hi Eli:
>>
>> On Sun, Apr 21, 2024 at 08:23:45AM GMT, Eli Zaretskii wrote:
>> >> Date: Sun, 21 Apr 2024 03:12:37 +0200
>> >> From: Ergus <spacibba@aol.com>
>> >> Cc: help-gnu-emacs@gnu.org
>> >>
>> >> A somehow unrelate question.. I don't find a face to change the tab-mark
>> >> color in whitespace mode... Is it documented somewhere?
>> >
>> >Isn't that whitespace-tab?
>> >
>> Actually no.
>>
>> That face seems apply only to the tab whitespace when whitespace-style
>> has `tabs`, but not to when `tab-mark` applies.
>
>You lost me here. But if all you want is to know what face is used on
>some text, simply use "M-x describe-text-properties RET" with point on
>that text.
>
Whitespace mode "shows" the tabs in two (independent) ways:
1. "Colorizing" the tab whitespace with some color (face tabs)
2. Add a mark in the whitespace space like | or � (tab-mark)
The whitespace-tab face applies only to 1, but I don't find how to make
it apply to 2
Define the whitespace-tab face foreground and background
(setq-default whitespace-style '(faces tab-mark))
(whitespace-mode 1)
TAB
I see: the �, but it is always white, independently of whitespace-tab face.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-22 5:39 ` Eli Zaretskii
2024-04-22 12:22 ` Ergus
@ 2024-04-22 12:34 ` Ergus
1 sibling, 0 replies; 16+ messages in thread
From: Ergus @ 2024-04-22 12:34 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
On Mon, Apr 22, 2024 at 08:39:31AM GMT, Eli Zaretskii wrote:
>> Date: Sun, 21 Apr 2024 23:05:57 +0200
>> From: Ergus <spacibba@aol.com>
>> Cc: help-gnu-emacs@gnu.org
>>
>> Hi Eli:
>>
>> On Sun, Apr 21, 2024 at 08:23:45AM GMT, Eli Zaretskii wrote:
>> >> Date: Sun, 21 Apr 2024 03:12:37 +0200
>> >> From: Ergus <spacibba@aol.com>
>> >> Cc: help-gnu-emacs@gnu.org
>> >>
>> >> A somehow unrelate question.. I don't find a face to change the tab-mark
>> >> color in whitespace mode... Is it documented somewhere?
>> >
>> >Isn't that whitespace-tab?
>> >
>> Actually no.
>>
>> That face seems apply only to the tab whitespace when whitespace-style
>> has `tabs`, but not to when `tab-mark` applies.
>
>You lost me here. But if all you want is to know what face is used on
>some text,
> simply use "M-x describe-text-properties RET" with point on
>that text.
>
Text content at position 5697:
There are text properties here:
fontified t
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-22 12:22 ` Ergus
@ 2024-04-23 8:06 ` Eli Zaretskii
2024-04-23 15:38 ` Ergus
0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-23 8:06 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Mon, 22 Apr 2024 14:22:43 +0200
> From: Ergus <spacibba@aol.com>
> Cc: help-gnu-emacs@gnu.org
>
> >> That face seems apply only to the tab whitespace when whitespace-style
> >> has `tabs`, but not to when `tab-mark` applies.
> >
> >You lost me here. But if all you want is to know what face is used on
> >some text, simply use "M-x describe-text-properties RET" with point on
> >that text.
> >
> Whitespace mode "shows" the tabs in two (independent) ways:
>
> 1. "Colorizing" the tab whitespace with some color (face tabs)
> 2. Add a mark in the whitespace space like | or � (tab-mark)
>
> The whitespace-tab face applies only to 1, but I don't find how to make
> it apply to 2
>
>
> Define the whitespace-tab face foreground and background
> (setq-default whitespace-style '(faces tab-mark))
> (whitespace-mode 1)
> TAB
>
> I see: the �, but it is always white, independently of whitespace-tab face.
You need to customize whitespace-display-mappings. Specifically, the
tab-mark element of the value is by default the vector '[?» ?\t], and
you need to replace each of these two characters with a glyph that has
the face you want, using make-glyph-code. Caveat: a comment in
whitespace.el explains why only newlines are given a face:
;; Only insert face bits on NEWLINE char mapping to avoid
;; obstruction of other faces like TABs and (HARD) SPACEs
;; faces, font-lock faces, etc.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-23 8:06 ` Eli Zaretskii
@ 2024-04-23 15:38 ` Ergus
2024-04-23 16:19 ` Eli Zaretskii
0 siblings, 1 reply; 16+ messages in thread
From: Ergus @ 2024-04-23 15:38 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
On Tue, Apr 23, 2024 at 11:06:02AM GMT, Eli Zaretskii wrote:
>> Date: Mon, 22 Apr 2024 14:22:43 +0200
>> From: Ergus <spacibba@aol.com>
>> Cc: help-gnu-emacs@gnu.org
>>
>> >> That face seems apply only to the tab whitespace when whitespace-style
>> >> has `tabs`, but not to when `tab-mark` applies.
>> >
>> >You lost me here. But if all you want is to know what face is used on
>> >some text, simply use "M-x describe-text-properties RET" with point on
>> >that text.
>> >
>> Whitespace mode "shows" the tabs in two (independent) ways:
>>
>> 1. "Colorizing" the tab whitespace with some color (face tabs)
>> 2. Add a mark in the whitespace space like | or � (tab-mark)
>>
>> The whitespace-tab face applies only to 1, but I don't find how to make
>> it apply to 2
>>
>>
>> Define the whitespace-tab face foreground and background
>> (setq-default whitespace-style '(faces tab-mark))
>> (whitespace-mode 1)
>> TAB
>>
>> I see: the �, but it is always white, independently of whitespace-tab face.
>
>You need to customize whitespace-display-mappings. Specifically, the
>tab-mark element of the value is by default the vector '[?� ?\t], and
>you need to replace each of these two characters with a glyph that has
>the face you want, using make-glyph-code. Caveat: a comment in
>whitespace.el explains why only newlines are given a face:
>
> ;; Only insert face bits on NEWLINE char mapping to avoid
> ;; obstruction of other faces like TABs and (HARD) SPACEs
> ;; faces, font-lock faces, etc.
>
Ahh this is exactly what I want..
Do you think it worth adding your paragraph as a comment somewhere in
whitespace or reference that in its manual section?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-23 15:38 ` Ergus
@ 2024-04-23 16:19 ` Eli Zaretskii
2024-04-24 2:41 ` Ergus
0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-23 16:19 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Tue, 23 Apr 2024 17:38:15 +0200
> From: Ergus <spacibba@aol.com>
> Cc: help-gnu-emacs@gnu.org
>
> >You need to customize whitespace-display-mappings. Specifically, the
> >tab-mark element of the value is by default the vector '[?� ?\t], and
> >you need to replace each of these two characters with a glyph that has
> >the face you want, using make-glyph-code. Caveat: a comment in
> >whitespace.el explains why only newlines are given a face:
> >
> > ;; Only insert face bits on NEWLINE char mapping to avoid
> > ;; obstruction of other faces like TABs and (HARD) SPACEs
> > ;; faces, font-lock faces, etc.
> >
>
> Ahh this is exactly what I want..
>
> Do you think it worth adding your paragraph as a comment somewhere in
> whitespace or reference that in its manual section?
IMO, if we want users to be able to do this, we need a more
user-friendly way of doing that. Like define a special face, and make
whitespace.el use make-glyph-code with that face, given some user
option setting.
Patches welcome.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-23 16:19 ` Eli Zaretskii
@ 2024-04-24 2:41 ` Ergus
2024-04-24 7:05 ` Eli Zaretskii
0 siblings, 1 reply; 16+ messages in thread
From: Ergus @ 2024-04-24 2:41 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
On Tue, Apr 23, 2024 at 07:19:02PM GMT, Eli Zaretskii wrote:
>> Date: Tue, 23 Apr 2024 17:38:15 +0200
>> From: Ergus <spacibba@aol.com>
>> Cc: help-gnu-emacs@gnu.org
>>
>> >You need to customize whitespace-display-mappings. Specifically, the
>> >tab-mark element of the value is by default the vector '[?� ?\t], and
>> >you need to replace each of these two characters with a glyph that has
>> >the face you want, using make-glyph-code. Caveat: a comment in
>> >whitespace.el explains why only newlines are given a face:
>> >
>> > ;; Only insert face bits on NEWLINE char mapping to avoid
>> > ;; obstruction of other faces like TABs and (HARD) SPACEs
>> > ;; faces, font-lock faces, etc.
>> >
>>
>> Ahh this is exactly what I want..
>>
>> Do you think it worth adding your paragraph as a comment somewhere in
>> whitespace or reference that in its manual section?
>
>IMO, if we want users to be able to do this, we need a more
>user-friendly way of doing that. Like define a special face, and make
>whitespace.el use make-glyph-code with that face, given some user
>option setting.
>
>Patches welcome.
>
Hi Eli:
I tried this.
(with-eval-after-load 'whitespace
(setq whitespace-style '(faces tab-mark)
whitespace-display-mappings `((tab-mark ?\t [,(make-glyph-code ?� 'whitespace-tab) ?\t] ))
))
(whitespace-mode 1)
But I only get the error:
wrong-type-argument number-or-marker-p (187 . 235)
Some idea what I am doing wrong?
Best,
Ergus
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-24 2:41 ` Ergus
@ 2024-04-24 7:05 ` Eli Zaretskii
2024-04-24 14:48 ` Ergus
0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-24 7:05 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Wed, 24 Apr 2024 04:41:26 +0200
> From: Ergus <spacibba@aol.com>
> Cc: help-gnu-emacs@gnu.org
>
> I tried this.
>
> (with-eval-after-load 'whitespace
> (setq whitespace-style '(faces tab-mark)
> whitespace-display-mappings `((tab-mark ?\t [,(make-glyph-code ?» 'whitespace-tab) ?\t] ))
> ))
> (whitespace-mode 1)
>
> But I only get the error:
>
> wrong-type-argument number-or-marker-p (187 . 235)
>
> Some idea what I am doing wrong?
It's a bug in whitespace.el, which I just fixed on the master branch:
it didn't work correctly with glyph codes. You seem to have a lot of
faces defined (more than 64 of them), so you bumped into this corner
case.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-24 7:05 ` Eli Zaretskii
@ 2024-04-24 14:48 ` Ergus
2024-04-24 15:45 ` Eli Zaretskii
0 siblings, 1 reply; 16+ messages in thread
From: Ergus @ 2024-04-24 14:48 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
On Wed, Apr 24, 2024 at 10:05:55AM GMT, Eli Zaretskii wrote:
>> Date: Wed, 24 Apr 2024 04:41:26 +0200
>> From: Ergus <spacibba@aol.com>
>> Cc: help-gnu-emacs@gnu.org
>>
>> I tried this.
>>
>> (with-eval-after-load 'whitespace
>> (setq whitespace-style '(faces tab-mark)
>> whitespace-display-mappings `((tab-mark ?\t [,(make-glyph-code ?� 'whitespace-tab) ?\t] ))
>> ))
>> (whitespace-mode 1)
>>
>> But I only get the error:
>>
>> wrong-type-argument number-or-marker-p (187 . 235)
>>
>> Some idea what I am doing wrong?
>
>It's a bug in whitespace.el, which I just fixed on the master branch:
>it didn't work correctly with glyph codes. You seem to have a lot of
>faces defined (more than 64 of them), so you bumped into this corner
>case.
>
Thank you very much. It works now. I don't actually add any new face if
they exist is because the were added by packages.
About the user friendly interface you mentioned previously.
I may be wrong, but I think it doesn't need a new face and custom
option, we just need to use the same whitespace-tab face for
tab-mark. It will be more coherent because the tabs (space highlight)
only uses the :background and the tab-mark will use only the
:foreground. Simpler and with all the flexibility. WDYT?
Thanks again,
Best,
Ergus
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: New line and trailing whitespaces
2024-04-24 14:48 ` Ergus
@ 2024-04-24 15:45 ` Eli Zaretskii
0 siblings, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-24 15:45 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Wed, 24 Apr 2024 16:48:06 +0200
> From: Ergus <spacibba@aol.com>
> Cc: help-gnu-emacs@gnu.org
>
> About the user friendly interface you mentioned previously.
>
> I may be wrong, but I think it doesn't need a new face and custom
> option, we just need to use the same whitespace-tab face for
> tab-mark. It will be more coherent because the tabs (space highlight)
> only uses the :background and the tab-mark will use only the
> :foreground. Simpler and with all the flexibility. WDYT?
What I meant was that activating this should be more user-friendly
(and simpler) than having to write Lisp code which uses
make-glyph-code and other stuff. We don't necessarily need to invent
new faces.
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2024-04-24 15:45 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <kcaicxrup2f3usy37v4aupgu7uvmifnxkeyc2hx5n5qpqnuj7b.ref@okar6momrmhs>
2024-04-20 12:10 ` New line and trailing whitespaces Ergus
2024-04-20 13:50 ` Eli Zaretskii
2024-04-20 14:16 ` Eli Zaretskii
2024-04-21 1:12 ` Ergus
2024-04-21 5:23 ` Eli Zaretskii
2024-04-21 21:05 ` Ergus
2024-04-22 5:39 ` Eli Zaretskii
2024-04-22 12:22 ` Ergus
2024-04-23 8:06 ` Eli Zaretskii
2024-04-23 15:38 ` Ergus
2024-04-23 16:19 ` Eli Zaretskii
2024-04-24 2:41 ` Ergus
2024-04-24 7:05 ` Eli Zaretskii
2024-04-24 14:48 ` Ergus
2024-04-24 15:45 ` Eli Zaretskii
2024-04-22 12:34 ` Ergus
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).