From: Po Lu Date: Sun, 8 Oct 2023 01:13:11 +0000 (+0800) Subject: Introduce a tool bar for dictionary mode X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a01203ce3374d6ce2ac8ea2992bff693ad73c0c2;p=emacs.git Introduce a tool bar for dictionary mode * lisp/doc-view.el (doc-view-minor-mode-menu): Correct typo in edit mode menu. * lisp/net/dictionary.el (dictionary-mode-menu): New menu. (dictionary-tool-bar-map): New variable; derive menu bar entries from the dictionary-mode-menu. (dictionary-mode): Set the tool bar map to dictionary-tool-bar-map. --- diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 210b7ace7d6..fb51661caac 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -661,7 +661,9 @@ Typically \"page-%s.png\".") '("DocView (edit)" ("Toggle edit/display" ["Edit document" (lambda ()) ; ignore but show no keybinding - :style radio :selected (eq major-mode 'doc-view--text-view-mode)] + ;; This is always selected since its menu is singular to the + ;; display minor mode. + :style radio :selected t] ["Display document" doc-view-toggle-display :style radio :selected (eq major-mode 'doc-view-mode)]) ["Exit DocView Mode" doc-view-minor-mode])) diff --git a/lisp/net/dictionary.el b/lisp/net/dictionary.el index ca706c3c6e9..d1f92334ee2 100644 --- a/lisp/net/dictionary.el +++ b/lisp/net/dictionary.el @@ -309,12 +309,12 @@ Otherwise, `dictionary-search' displays definitions in a *Dictionary* buffer." :version "30.1") (defface dictionary-word-definition-face -'((((supports (:family "DejaVu Serif"))) - (:family "DejaVu Serif")) - (((type x)) - (:font "Sans Serif")) - (t - (:font "default"))) + '((((supports (:family "DejaVu Serif"))) + (:family "DejaVu Serif")) + (((type x)) + (:font "Sans Serif")) + (t + (:font "default"))) "The face that is used for displaying the definition of the word." :group 'dictionary :version "28.1") @@ -405,6 +405,22 @@ Otherwise, `dictionary-search' displays definitions in a *Dictionary* buffer." "M-SPC" #'scroll-down-command "DEL" #'scroll-down-command) +(easy-menu-define dictionary-mode-menu dictionary-mode-map + "Menu for the Dictionary mode." + '("Dictionary" + ["Search Definition" dictionary-search + :help "Look up a new word"] + ["List Matching Words" dictionary-match-words + :help "List all words matching a pattern"] + ["Lookup Word At Point" dictionary-lookup-definition + :help "Look up the word at point"] + ["Select Dictionary" dictionary-select-dictionary + :help "Select one or more dictionaries to search within"] + ["Select Match Strategy" dictionary-select-strategy + :help "Select the algorithm to match queries and entries with"] + ["Back" dictionary-previous + :help "Return to the previous match or location"])) + (defvar dictionary-connection nil "The current network connection.") @@ -423,6 +439,30 @@ Otherwise, `dictionary-search' displays definitions in a *Dictionary* buffer." ;; Basic function providing startup actions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defvar dictionary-tool-bar-map + (let ((map (make-sparse-keymap))) + ;; Most of these items are the same as in the default tool bar + ;; map, but with extraneous items removed, and with extra search + ;; and navigation items. + (tool-bar-local-item-from-menu 'find-file "new" map + nil :label "New File" + :vert-only t) + (tool-bar-local-item-from-menu 'menu-find-file-existing "open" map + nil :label "Open" :vert-only t) + (tool-bar-local-item-from-menu 'dired "diropen" map nil :vert-only t) + (tool-bar-local-item-from-menu 'kill-this-buffer "close" map nil + :vert-only t) + (define-key-after map [separator-1] menu-bar-separator) + (tool-bar-local-item-from-menu 'dictionary-search "search" + map dictionary-mode-map :vert-only t + :help "Start a new search query.") + (tool-bar-local-item-from-menu 'dictionary-previous "left-arrow" + map dictionary-mode-map + :vert-only t + :help "Go backwards in history.") + map) + "Like the default `tool-bar-map', but with additions for Dictionary mode") + ;;;###autoload (define-derived-mode dictionary-mode special-mode "Dictionary" "Mode for searching a dictionary. @@ -452,6 +492,8 @@ This is a quick reference to this mode describing the default key bindings: (make-local-variable 'dictionary-positions) (make-local-variable 'dictionary-default-dictionary) (make-local-variable 'dictionary-default-strategy) + ;; Replace the tool bar map with `dictionary-tool-bar-map'. + (setq-local tool-bar-map dictionary-tool-bar-map) (add-hook 'kill-buffer-hook #'dictionary-close t t)) ;;;###autoload