- Command: dict-describe-word :: Prompt for a word and display its definition.
-This command prompts for a word in the minibuffer, obtains its definition from a
-dictionary server, and displays it in a =*Help*= buffer. (See [[info:emacs#Help][Help]] in the Emacs
-manual.)
+This command prompts for a word in the minibuffer, obtains its
+definition from a dictionary server, and displays it in a =*Help*=
+buffer. (See [[info:emacs#Help][Help]] in the Emacs manual.)
-~dict-describe-word~ uses the word at point, if any, as the minibuffer's default
-argument (see [[info:emacs#Basic Minibuffer][Basic Minibuffer]]). This means that you can display the definition
-of the word at point by typing ~M-x dict-describe-word RET RET~.
+~dict-describe-word~ uses dictionary matches for the word at point, if
+any, as the minibuffer's "future history" (see [[info:emacs#Minibuffer History][Minibuffer History]]).
+This means that you can display the definition of the word at point by
+typing ~M-x dict-describe-word RET RET~.
Dictionary servers usually support several dictionaries that you can query.
When Dict asks the dictionary server for a word definition, it needs to specify
#+FINDEX: dict-read-word
Note the use of the function ~dict-read-word~ in the above definition.
This helper function prompts for a word defined in dictionary, with
-completion, using the word at point as the minibuffer's default
-argument. This is also what ~dict-describe-word~ uses to prompt for a
+completion, using the word at point as the minibuffer's "future
+history". This is also what ~dict-describe-word~ uses to prompt for a
word when you call it interactively.
* Motivation Behind Dict
;; Author: Eshel Yaron <me@eshelyaron.com>
;; Keywords: help, comm
;; URL: http://git.eshelyaron.com/gitweb/?p=dict.git
-;; Package-Version: 0.1.4
+;; Package-Version: 0.1.5
;; Package-Requires: ((emacs "28.1"))
;; This program is free software; you can redistribute it and/or modify
(unless (string-empty-p word)
(if (string= (car dict-match-cache) word)
(cdr dict-match-cache)
- (setq dict-match-cache
- (cons word
- (dict-command
- (format "match %s %s \"%s\""
- (dict-dictionary)
- (dict-strategy)
- word)
- (lambda ()
- (let ((result nil))
- (search-forward "\r\n152" nil t)
- (while (not (looking-at (rx "\r\n.\r\n")))
- (search-forward "\r\n" nil t)
- (search-forward " " nil t)
- (push (read (current-buffer)) result))
- (reverse result)))))))))
+ (let ((matches (dict-command
+ (format "match %s %s \"%s\""
+ (dict-dictionary)
+ (dict-strategy)
+ word)
+ (lambda ()
+ (let ((result nil))
+ (search-forward "\r\n152" nil t)
+ (while (not (looking-at (rx "\r\n.\r\n")))
+ (search-forward "\r\n" nil t)
+ (search-forward " " nil t)
+ (push (read (current-buffer)) result))
+ (reverse result))))))
+ (setq dict-match-cache (cons word matches))
+ matches))))
(defun dict-define-word (word)
"Return the dictionary definition of WORD, or nil if not defined."
(let* ((enable-recursive-minibuffers t)
(completion-ignore-case t)
(word-at-point (thing-at-point 'word t))
- (default (car (dict-match-word word-at-point))))
+ (default (dict-match-word word-at-point)))
(completing-read (format-prompt "Word" default)
(completion-table-dynamic #'dict-match-word)
nil t nil 'dict-read-word-history default t)))