evil icon indicating copy to clipboard operation
evil copied to clipboard

Add "zg" and "zG" bindings

Open condy0919 opened this issue 3 years ago • 13 comments

According to https://vimhelp.org/spell.txt.html, zg would

Add word under the cursor as a good word to the first name in 'spellfile'. A count may precede the command to indicate the entry in 'spellfile' to be used. A count of two uses the second entry.

In Visual mode the selected characters are added as a word (including white space!). When the cursor is on text that is marked as badly spelled then the marked text is used. Otherwise the word under the cursor, separated by non-word characters, is used.

If the word is explicitly marked as bad word in another spell file the result is unpredictable.

zG would

Like "zg" but add the word to the internal word list internal-wordlist.

ispell has no concept of internal-wordlist, but it provides a local words instead.

condy0919 avatar Jul 09 '21 19:07 condy0919

Why it failed on Emacs 24.5 only?

condy0919 avatar Jul 09 '21 19:07 condy0919

I can't figure out why it failed only on Emacs 24.5. Download the Emacs 24.5 tarball, grep every symbol in the lisp directory, all have definitions.

condy0919 avatar Jul 11 '21 00:07 condy0919

See https://github.com/emacs-evil/evil/pull/1487#issuecomment-876368014

wasamasa avatar Jul 11 '21 13:07 wasamasa

See #1487 (comment)

I see...

condy0919 avatar Jul 11 '21 14:07 condy0919

@wasamasa ping

condy0919 avatar Jul 13 '21 04:07 condy0919

More general issue: The Vim helpfile claims a few more things about those commands:

  • There may be a count to indicate which spellfile entry to use, defaulting to the first. For this you'd need to use evil-define-command with (interactive "<c>"). Does the concept of spellfile entries even make sense for ispell? What about repeatability? If not, then it should be marked as non-repeatable.
  • Visual mode is not handled at all. Some experimentation with Vim is necessary to figure out how exactly it behaves. It claims both that a selection including whitespace may be used, but that a word at point may be used as well.

wasamasa avatar Jul 13 '21 11:07 wasamasa

More general issue: The Vim helpfile claims a few more things about those commands:

  • There may be a count to indicate which spellfile entry to use, defaulting to the first. For this you'd need to use evil-define-command with (interactive "<c>"). Does the concept of spellfile entries even make sense for ispell? What about repeatability? If not, then it should be marked as non-repeatable.

No, ispell-personal-dictionary can't be a list. But I found doom-emacs provides a non-compatible mechanism which behaves like there are 3 spellfile entries (personal/buffer-local/session dict) when "zg" adding words.

internal-wordlist The internal word list is used for all buffers where 'spell' is set. It is not stored, it is lost when you exit Vim. It is also cleared when 'encoding' is set.

"zG" adds the word to the internal-wordlist which is effective in session-level. Yes, this patch implementes wrong. Sorry :'(

We can't mimic vim perfectly, so which one is better is arguable.

  1. "zg" personal/buffer-local/session dict, "zG" buffer-local dict.
  2. "zg" personal/buffer-local/session dict, "zG" session dict.
  3. "zg" personal/buffer-local dict, "zG" session dict.

Personally, I prefer the third one, it's more orthogonal. Thoughts?

EDITED: Playing in vim, it's non-rerepeatable.

  • Visual mode is not handled at all. Some experimentation with Vim is necessary to figure out how exactly it behaves. It claims both that a selection including whitespace may be used, but that a word at point may be used as well.

I try to avoid this when implementating. Consider the following case: mis speelled has been inserted in the personal dict, but ispell only recognizes the speelled as CORRECT.

image

KSSysLab avatar Jul 13 '21 12:07 KSSysLab

:'( it's me

condy0919 avatar Jul 14 '21 13:07 condy0919

No, ispell-personal-dictionary can't be a list. But I found doom-emacs provides a non-compatible mechanism which behaves like there are 3 spellfile entries (personal/buffer-local/session dict) when "zg" adding words.

Uh-oh. I'd consult with the Doom people then. Maybe they'd prefer your approach. Maybe their approach is worth using.

"zG" adds the word to the internal-wordlist which is effective in session-level. Yes, this patch implementes wrong. Sorry :'(

We can't mimic vim perfectly, so which one is better is arguable.

  1. "zg" personal/buffer-local/session dict, "zG" buffer-local dict.
  2. "zg" personal/buffer-local/session dict, "zG" session dict.
  3. "zg" personal/buffer-local dict, "zG" session dict.

Personally, I prefer the third one, it's more orthogonal. Thoughts?

Agreed, the third option makes most sense.

EDITED: Playing in vim, it's non-rerepeatable.

  • Visual mode is not handled at all. Some experimentation with Vim is necessary to figure out how exactly it behaves. It claims both that a selection including whitespace may be used, but that a word at point may be used as well.

I try to avoid this when implementating. Consider the following case: mis speelled has been inserted in the personal dict, but ispell only recognizes the speelled as CORRECT.

image

OK, so not repeatable and no handling of visual mode either. In that case it's debatable whether evil-define-cmd adds any benefit.

wasamasa avatar Jul 17 '21 10:07 wasamasa

Updated.

I found the session is also buffer-local which is different with vim. Perhaps making "zg" add words to personal and "zG" add words to buffer-local/session-buffer-local is reasonable?

condy0919 avatar Jul 18 '21 08:07 condy0919

Seems like no more comments.

image

condy0919 avatar Jul 22 '21 19:07 condy0919

Updated. string without properties will be used. @wasamasa

condy0919 avatar Jul 22 '21 19:07 condy0919

Oh, I see! I took some time to read up on it and I think your proposal makes sense; zg -> personal dict, zG -> session, but I'm not sure about using the universal argument; the universal arg is generally very unvimlike. Perhaps there's another key we could use? Since evil doesn't have zu for undo, how about zu -> add to buffer-local personal dict and zU -> remove from buffer-local personal dict?

Not sure we need the old zu keys since, with ispell, I assume we can undo a zg with zG, or a zw with zW. Need to test that assumption though.

Opinions from @hlissner

condy0919 avatar Jul 23 '21 18:07 condy0919