Subject: bug#45262: Dictionary improvements

From: Juri Linkov <[email-masked]>
Date: Tue, 15 Dec 2020 22:05:27 +0200

X-Debbugs-CC: Torsten Hilbrich <[email-masked]>

Thanks for merging dictionary to master!  I tried to use it,
and encountered several minor issues that I propose to improve:

1. For scrolling most other modes use scroll-up-command,
   and also bind S-SPC to scroll-down-command like this:

diff --git a/lisp/net/dictionary.el b/lisp/net/dictionary.el
index 0df9d8b142..24e2b8d2ee 100644
--- a/lisp/net/dictionary.el
+++ b/lisp/net/dictionary.el
@@ -323,8 +323,9 @@ dictionary-mode-map
     (define-key map "l" 'dictionary-previous)
     (define-key map "n" 'forward-button)
     (define-key map "p" 'backward-button)
-    (define-key map " " 'scroll-up)
-    (define-key map (read-kbd-macro "M-SPC") 'scroll-down)
+    (define-key map " " 'scroll-up-command)
+    (define-key map [?\S-\ ] 'scroll-down-command)
+    (define-key map (read-kbd-macro "M-SPC") 'scroll-down-command)
     map)
   "Keymap for the dictionary mode.")
 
2. When point is on a multi-word link in the *Dictionary* buffer
   then the command 'M-x dictionary-search' fetches only one word
   from the buffer.  Instead of this, it could fetch the whole link
   for possible editing in the minibuffer before searching again:

diff --git a/lisp/net/dictionary.el b/lisp/net/dictionary.el
index 0df9d8b142..24e2b8d2ee 100644
--- a/lisp/net/dictionary.el
+++ b/lisp/net/dictionary.el
@@ -1119,9 +1120,11 @@ dictionary-display-match-lines
 ;; - if region is active returns its contents
 ;; - otherwise return the word near the point
 (defun dictionary-search-default ()
-  (if (use-region-p)
-      (buffer-substring-no-properties (region-beginning) (region-end))
-    (current-word t)))
+  (cond
+   ((use-region-p)
+    (buffer-substring-no-properties (region-beginning) (region-end)))
+   ((car (get-char-property (point) 'data)))
+   (t (current-word t))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; User callable commands

3. There is the hook dictionary-mode-hook, and I use it to enable
   outline-minor-mode in the *Dictionary* buffer (using word entry lines
   are outline-regexp headings).  But there is a need to hide subheadings
   every time when the *Dictionary* buffer is updated, but there is no such hook.
   Maybe better to add a hook with a name like dictionary-search-post-hook
   to be called from dictionary-post-buffer.

4. 'dictionary' uses switch-to-buffer-other-window to force the output buffer
   in another window.  Other commands use pop-to-buffer that requires just
   such customization to display it in the same window:

  (push '("\\`\\*Dictionary\\*\\(?:<[^>]+>\\)?\\'" display-buffer-same-window)
        display-buffer-alist)

  But since switch-to-buffer-other-window calls pop-to-buffer with 't'
  for its arg 'action', this means that this requires more complex customization:

  (push '("\\`\\*Dictionary\\*\\(?:<[^>]+>\\)?\\'"
         display-buffer-same-window
         (inhibit-same-window . nil))
      display-buffer-alist)

  The difference is in the need to add '(inhibit-same-window . nil)'.

5. When clicking on a word link in the *Dictionary* buffer,
   it displays the word definition only in the same dictionary,
   while it would be better to search it in all dictionaries
   for more coverage.

   This is not a patch, but demonstrates the problem.
   Maybe this should be customizable?

diff --git a/lisp/net/dictionary.el b/lisp/net/dictionary.el
index 0df9d8b142..24e2b8d2ee 100644
--- a/lisp/net/dictionary.el
+++ b/lisp/net/dictionary.el
@@ -848,7 +849,7 @@ dictionary-mark-reference
     (unless (equal word displayed-word)
       (make-button start end :type 'dictionary-link
                    'callback call
-                   'data (cons word dictionary)
+                   'data (cons word "*")
                    'help-echo (concat "Press Mouse-2 to lookup \""
                                       word "\" in \"" dictionary "\"")))))