From: Juri Linkov Date: Tue, 9 Feb 2021 18:29:54 +0000 (+0200) Subject: * lisp/net/dictionary.el: Dictionary improvements (bug#45262) X-Git-Tag: emacs-28.0.90~3847 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=552d2b9083c2dac210fd8f565b2d46897ae9d4ed;p=emacs.git * lisp/net/dictionary.el: Dictionary improvements (bug#45262) * lisp/net/dictionary.el (dictionary-link-dictionary): New defcustom. (dictionary-mark-reference): Use dictionary-link-dictionary. (dictionary-post-buffer-hook): New defcustom. (dictionary-post-buffer): Run dictionary-post-buffer-hook. (dictionary-mode-map): Bind 'S-SPC' to scroll-down-command. (dictionary-search-default): Use possibly multi-word data at point. --- diff --git a/lisp/net/dictionary.el b/lisp/net/dictionary.el index ccc24cbf303..6f086053b6a 100644 --- a/lisp/net/dictionary.el +++ b/lisp/net/dictionary.el @@ -160,6 +160,18 @@ by the choice value: :type 'boolean :version "28.1") +(defcustom dictionary-link-dictionary + "*" + "The dictionary which is used in links. +* means to create links that search all dictionaries, +nil means to create links that search only in the same dictionary +where the current word was found." + :group 'dictionary + :type '(choice (const :tag "Link to all dictionaries" "*") + (const :tag "Link only to the same dictionary" nil) + (string :tag "User choice")) + :version "28.1") + (defcustom dictionary-mode-hook nil "Hook run in dictionary mode buffers." @@ -167,6 +179,13 @@ by the choice value: :type 'hook :version "28.1") +(defcustom dictionary-post-buffer-hook + nil + "Hook run at the end of every update of the dictionary buffer." + :group 'dictionary + :type 'hook + :version "28.1") + (defcustom dictionary-use-http-proxy nil "Connects via a HTTP proxy using the CONNECT command when not nil." @@ -323,8 +342,9 @@ is utf-8" (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.") @@ -772,7 +792,8 @@ of matching words." (goto-char dictionary-marker) (set-buffer-modified-p nil) - (setq buffer-read-only t)) + (setq buffer-read-only t) + (run-hooks 'dictionary-post-buffer-hook)) (defun dictionary-display-search-result (reply) "Start displaying the result in REPLY." @@ -842,6 +863,8 @@ The word is taken from the buffer, the DICTIONARY is given as argument." (setq word (replace-match " " t t word))) (while (string-match "[*\"]" word) (setq word (replace-match "" t t word))) + (when dictionary-link-dictionary + (setq dictionary dictionary-link-dictionary)) (unless (equal word displayed-word) (make-button start end :type 'dictionary-link @@ -1117,9 +1140,11 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"." ;; - 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