SavchenkoValeriy / emacs-powerthesaurus

Powerthesaurus integration for Emacs
GNU General Public License v3.0
270 stars 11 forks source link

Look up current word under point #3

Closed mrcnski closed 6 years ago

mrcnski commented 6 years ago

First of all, thanks for the quick response to issue #2!

What I would really like to do with this package is to look up the word under the point. Currently in order to do this I have to select a region around a word. It's extra keypresses and also error prone if you're selecting with the mouse. Here are some ideas for alternatives that are more intuitive/ergonomic IMO:

  1. Add a new function to look up the word under the point, similar to ispell-word.
  2. Make the word under point the default, so I can press enter after calling powerthesaurus-lookup-word and it will look it up without me typing it out.
  3. Add support for calling C-u powerthesaurus-lookup-word to look up the word under point.

Let me know if you like any of these ideas or if they're all dumb.

SavchenkoValeriy commented 6 years ago

I thought of a function like this myself.

In my mind, it is another function, something like powerthesuarus-lookup-word-at-point, that calculates the beginning and the end of the word at point and calls powerthesaurus-lookup-word.

How does it sound to you?

mrcnski commented 6 years ago

@SavchenkoValeriy that sounds great! Thank you!

calculates the beginning and the end of the word at point

I wonder if you can't use the same logic used by ispell-word. It would be nice to have some consistency with that command's selection function.

SavchenkoValeriy commented 6 years ago

@m-cat I implemented the function the way I imagined it.

However, can you clarify (with an example, maybe) what do you mean when you say the same logic used byispell-word?

mrcnski commented 6 years ago

Sure @SavchenkoValeriy. I think the command should select words in the same manner that ispell-word does for consistency. For example, ispell-word will select the entirety of wasn't, despite the apostrophe in the middle, but it won't select all of punch-out. Someone who's used to this behavior may expect the same behavior from the new thesaurus command.

By the way, I had a look at your code and I think you can just use the function word-at-point. This should give us standard behavior that is consistent with similar commands while being simple to implement :) You also will be able to remove the check for whether the point is at the beginning of a word.

SavchenkoValeriy commented 6 years ago

@m-cat It would've been great to use word-at-point, but it's not enough because it returns only text without buffer positions that are required for replacement.

The current implementation supports the exact behavior you are talking about. It comes from the fact that word is defined by each mode separately and not by me or ispell.

mrcnski commented 6 years ago

Ah I see, I forgot this mode also does text replacements. Looks great to me!