From: Eshel Yaron Date: Tue, 9 May 2023 17:08:26 +0000 (+0300) Subject: Use matches for word-at-point as future history X-Git-Tag: v0.1.5 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1e3b1f0ef406b5dfc98ff6cfde56f93cf5a210cf;p=dict.git Use matches for word-at-point as future history * dict.el: bump version to 0.1.5. (dict-match-word): fix thinko. (dict-read-word): use all matches for word-at-point as the minibuffer's future history. * README.org (Displaying Word Definitions, Extending Dict): update. --- diff --git a/README.org b/README.org index 8cfe5a3..0f0faf2 100644 --- a/README.org +++ b/README.org @@ -48,13 +48,14 @@ Dict defines a single autoloaded command for displaying the word definitions: - 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 @@ -170,8 +171,8 @@ locally bind ~dict-display-definition-function~ to an appropriate function: #+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 diff --git a/dict.el b/dict.el index bb15337..7c3e2bb 100644 --- a/dict.el +++ b/dict.el @@ -5,7 +5,7 @@ ;; Author: Eshel Yaron ;; 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 @@ -144,21 +144,21 @@ beginning of a buffer with the server's response." (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." @@ -255,7 +255,7 @@ option to it first." (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)))