SavchenkoValeriy / emacs-powerthesaurus

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

Simplified two commands into one: powerthesaurus-lookup-word-region-or-thing-at-point-or-ask #4

Closed sewkokot closed 6 years ago

sewkokot commented 6 years ago

I wrote a command which combines the two commands: powerthesaurus-lookup-word and powerthesaurus-lookup-word-at-point into one. This way I can bind it to one key instead of two. Perhaps it can be implemented directly in the library?

(defun powerthesaurus-lookup-word-region-or-thing-at-point-or-ask ()
  "Wrapper function for powerthesaurus-lookup-word commands.

If a region is selected use powerthesaurus-lookup-word
if a thing at point is not empty use powerthesaurus-lookup-word-at-point
otherwise as for word using powerthesaurus-lookup-word"
  (interactive)
  (let (beg end bounds)
    (if (use-region-p)
        (progn
          (setq beg (region-beginning))
          (setq end (region-end))
          (powerthesaurus-lookup-word beg end))
      (if (thing-at-point 'word)
          (powerthesaurus-lookup-word-at-point (point))
        (powerthesaurus-lookup-word)))))
SavchenkoValeriy commented 6 years ago

Hello. Sorry for such a late reaction, somehow I overlooked the notification. I like your idea, the only thing I changed is the name. Now it's a DWIM function. Thank you!