Download
(provide 'wn-org)
(defgroup wn-org nil
"Wordnet org-mode interface."
:group 'wn-org)
(defcustom wn-org-command "wn"
"Shell command for wordnet."
:type 'string
:group 'wn-org)
(defcustom wn-org-mode-hook nil
"Normal hook run after entering wn-org mode."
:type 'hook
:group 'wn-org)
(defcustom wn-org-options
" -over\
-antsn -antsv -antsa -antsr\
-hypen -hypev\
-hypon -hypov\
-entav\
-synsn -synsv -synsa -synsr\
-smemn\
-ssubn\
-sprtn\
-membn\
-subsn\
-partn\
-meron\
-holon\
-causv\
-perta -pertr\
-attrn -attra\
-derin -deriv\
-domnn -domnv -domna -domnr\
-domtn -domtv -domta -domtr\
-famln -famlv -famla -famlr\
-framv\
-coorn -coorv\
-simsv\
-hmern\
-hholn\
-grepn -grepv -grepa -grepr"
"Command line options for wn"
:type 'string
:group 'wn-org)
(defcustom wn-org-section-headings
'("Antonyms" "Synonyms" "Hyponyms" "Troponyms"
"Meronyms" "Holonyms" "Pertainyms"
"Member" "Substance" "Part"
"Attributes" "Derived" "Domain" "Familiarity"
"Coordinate" "Grep" "Similarity"
"Entailment" "'Cause To'" "Sample" "Overview")
"Section headings
to which the `*' org-mode section label is added."
:type 'list
:group 'wn-org)
(define-derived-mode wn-org-mode
org-mode "WordNet"
"Major mode for WordNet dictionary search.
\\{wn-org-mode-map}"
(run-hooks 'wn-org-mode-hook))
(define-key wn-org-mode-map (kbd "q") 'wn-org-quit)
(defun wn-org-quit ()
"Kill Word Net windows and buffer."
(interactive)
(let ((buffer (current-buffer)))
(delete-windows-on buffer)
(kill-buffer buffer)))
(defun wn-org-replace-regexp (regexp-string repl-string)
(goto-char (point-min))
(while (re-search-forward regexp-string nil t)
(replace-match repl-string t nil)))
(defun wn-org-search (word)
"Search WordNet for WORD if provided otherwise prompt for it.
The word at the point is suggested which can be replaced."
(interactive (list (read-string "Wordnet: " (current-word))))
(unless word
(setq word (read-string "Word: ")))
(let ((buf (get-buffer-create "*WordNet*")))
(with-current-buffer buf
(setq buffer-read-only t)
(let ((inhibit-read-only t))
(erase-buffer)
(insert
(shell-command-to-string
(format "%s %s %s" wn-org-command word wn-org-options)))
(delete-matching-lines "^ *$" (point-min) (point-max))
(wn-org-replace-regexp
(concat "^" (regexp-opt wn-org-section-headings t))
"* \\1")
(goto-char (point-min))
(while (re-search-forward "^\\*.*\n\\*" nil t)
(replace-match "*" t t)
(backward-char)
)
(wn-org-replace-regexp "^Sense \\([1-9]*\\)" " \\1. ")
(wn-org-replace-regexp " [=*]>" " +")
(unless (eq major-mode 'wn-org-mode)
(wn-org-mode))
(indent-region (point-min) (point-max))
(fill-region (point-min) (point-max))
(goto-char (point-min))
))
(unless (eq (current-buffer) buf)
(unless (cdr (window-list))
(split-window-vertically))
(other-window 1)
(switch-to-buffer buf))))
(defalias 'wn-org 'wn-org-search)