Wordnet and Emacs

Something else I did to pass the time. This is going into my posts.el file, with the keybinding C-c w.

(defun get-current-word () 
  "Returns the current, or the last entered word."
  (save-excursion
    (backward-word)
    (setq start (point))
    (forward-word)
    (setq end (point))
    (buffer-substring-no-properties start end)))

(defvar wordnet-bin-path 
  "C:/Progra~1/WordNet/2.1/bin/wn.exe"
  "This should point to the full path of the wordnet command")

(defun wordnet-current-word ()
  "Shows the Wordnet overview for the current word." 
  (interactive)
  (save-window-excursion
    (let ((buf (get-buffer-create "*wordnet*"))
          (word (get-current-word)))
      (save-window-excursion
        (set-buffer buf)
        (clear-buffer buf)
        (insert (concat "Wordnet overview for " word ": "))
        (call-process wordnet-bin-path nil "*wordnet*" t word "-over")
        (switch-to-buffer "*wordnet*")
        (beginning-of-buffer)
        (read-string "Press Enter to continue… ")))))

(defun clear-buffer (buf)
  "Clear a buffer"
  (save-excursion
    (set-buffer buf)
    (kill-region (point-min) (point-max))))

For those that don’t speak code, that thing will show me the Wordnet overview of any word I’m currently typing. Boring, but a tiny-bit useful. To me.

Update: added the clear-buffer function definition. I forgot it’s not a built-in.