nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFC: make the M-D word count consistent with how Ctrl+Right moves?


From: Victor Khong - Horsefly Realty
Subject: Re: RFC: make the M-D word count consistent with how Ctrl+Right moves?
Date: Sun, 24 Oct 2021 10:35:58 -0700

I think your explanation and approach is correct. It will make nano better.



On Sun, Oct 24, 2021 at 3:36 AM Benno Schulenberg <bensberg@telfort.nl> wrote:

Hi all,

Currently, when typing M-D to get a report about the number of lines
and words and characters, nano counts words as if punctuation forms
part of words, the same as what 'wc -w' does, meaning that it counts
a lone dash or asterisk or whatever as a separate word, which I think
is wrong.  Nano is an editor -- it should know what words are and not
count lone punctuation (or groups of punctuation) as words.

To see what I mean, do the following:

   echo "   one-two -- three.four   " >afile

Then run 'nano --ignore afile' and type: M-D.  Nano reports: "3 words".
>From a human viewpoint this can't be right, it should be either two
words or four words, depending on whether you count compound words as
one or as separate words.  Now type Ctrl+Right a few times.  See that
nano jumps from "one" to "two" to "three" to "four", skipping the "--".
So the next-word function sees four words.  In that case, I think M-D
should report four words too.

Now exit and run 'nano --ignore afile -W', adding the -W (--wordbounds)
option.  M-D still reports 3 words.  But see what Ctrl+Right does: it
skips "two", stops on "--", and skips "four".  Now the next-word function
does see three words.

Now try with 'vim afile' and type: g ^G.  Vim reports 3 words.  Use
Ctrl+Right a few times.  See that it skips "two" and "four", but stops
on the "--", like nano with --wordbounds.  Exit with: Esc :q!

Now try with 'emacs afile' and type: M-- M-=.  Emacs reports 4 words.
Use Ctrl+Right a few times.  See that it stops at the end of four words
and that it skips the "--".  (Emacs' Ctrl+Right behaves like nano when
using the option --afterends.)  Exit with: ^G ^X ^C.

For both Vim and Emacs the behavior of Ctrl+Right is consistent with
how many words they report.  I think nano should do the same and see
punctuation as word-forming only when --wordbounds (-W) is in effect.
So I propose to apply the attached patch.

Thoughts?  Opinions?


You may wonder: why change things when they have been this way for
sixteen years -- since commit a8824a19 [1] -- and nobody complained?
Well, I go by what Mike Frysinger once wrote (paraphrased): "Forget
history, make it do the right thing."

[1] https://git.savannah.gnu.org/cgit/nano.git/commit/?id=a8824a19


I found this issue by using M-D around line 20 in the README and
realizing that it counted each vertical line (|) as a word, which
I thought was silly.  Also, when I have a bulleted list, I don't
want nano to count the bullets themselves as words.  Etcetera.

(By the way, it was good to see that both Vim and Emacs report the
number of lines and words and characters in that order.  Nano does
it like that since version 5.4.  I changed it because I thought it
made more sense.  It's good to see those other editors agree.)

Benno

reply via email to

[Prev in Thread] Current Thread [Next in Thread]