summaryrefslogtreecommitdiff
path: root/lisp/net/dictionary.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/net/dictionary.el')
-rw-r--r--lisp/net/dictionary.el137
1 files changed, 80 insertions, 57 deletions
diff --git a/lisp/net/dictionary.el b/lisp/net/dictionary.el
index ccc24cbf303..f33cbaf1126 100644
--- a/lisp/net/dictionary.el
+++ b/lisp/net/dictionary.el
@@ -35,7 +35,6 @@
;;; Code:
(require 'cl-lib)
-(require 'easymenu)
(require 'custom)
(require 'dictionary-connection)
(require 'button)
@@ -77,7 +76,7 @@ You can specify here:
- dict.org: Only use dict.org
- User-defined: You can specify your own server here"
:group 'dictionary
- :set 'dictionary-set-server-var
+ :set #'dictionary-set-server-var
:type '(choice (const :tag "Automatic" nil)
(const :tag "localhost" "localhost")
(const :tag "dict.org" "dict.org")
@@ -89,7 +88,7 @@ You can specify here:
"The port of the dictionary server.
This port is propably always 2628 so there should be no need to modify it."
:group 'dictionary
- :set 'dictionary-set-server-var
+ :set #'dictionary-set-server-var
:type 'number
:version "28.1")
@@ -127,9 +126,9 @@ by the choice value:
The found word exactly matches the searched word.
-- Similiar sounding
+- Similar sounding
- The found word sounds similiar to the searched word. For this match type
+ The found word sounds similar to the searched word. For this match type
the soundex algorithm defined by Donald E. Knuth is used. It will only
works with english words and the algorithm is not very reliable (i.e.,
the soundex algorithm is quite simple).
@@ -148,7 +147,7 @@ by the choice value:
dictionary server."
:group 'dictionary
:type '(choice (const :tag "Exact match" "exact")
- (const :tag "Similiar sounding" "soundex")
+ (const :tag "Similar sounding" "soundex")
(const :tag "Levenshtein distance one" "lev")
(string :tag "User choice"))
:version "28.1")
@@ -160,6 +159,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,11 +178,18 @@ 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."
:group 'dictionary-proxy
- :set 'dictionary-set-server-var
+ :set #'dictionary-set-server-var
:type 'boolean
:version "28.1")
@@ -179,7 +197,7 @@ by the choice value:
"proxy"
"The name of the HTTP proxy to use when `dictionary-use-http-proxy' is set."
:group 'dictionary-proxy
- :set 'dictionary-set-server-var
+ :set #'dictionary-set-server-var
:type 'string
:version "28.1")
@@ -187,7 +205,7 @@ by the choice value:
3128
"The port of the proxy server, used only when `dictionary-use-http-proxy' is set."
:group 'dictionary-proxy
- :set 'dictionary-set-server-var
+ :set #'dictionary-set-server-var
:type 'number
:version "28.1")
@@ -313,18 +331,19 @@ is utf-8"
(suppress-keymap map)
(set-keymap-parent map button-buffer-map)
- (define-key map "q" 'dictionary-close)
- (define-key map "h" 'dictionary-help)
- (define-key map "s" 'dictionary-search)
- (define-key map "d" 'dictionary-lookup-definition)
- (define-key map "D" 'dictionary-select-dictionary)
- (define-key map "M" 'dictionary-select-strategy)
- (define-key map "m" 'dictionary-match-words)
- (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 "q" #'dictionary-close)
+ (define-key map "h" #'dictionary-help)
+ (define-key map "s" #'dictionary-search)
+ (define-key map "d" #'dictionary-lookup-definition)
+ (define-key map "D" #'dictionary-select-dictionary)
+ (define-key map "M" #'dictionary-select-strategy)
+ (define-key map "m" #'dictionary-match-words)
+ (define-key map "l" #'dictionary-previous)
+ (define-key map "n" #'forward-button)
+ (define-key map "p" #'backward-button)
+ (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.")
@@ -394,12 +413,12 @@ This is a quick reference to this mode describing the default key bindings:
(make-local-variable 'dictionary-default-dictionary)
(make-local-variable 'dictionary-default-strategy)
- (add-hook 'kill-buffer-hook 'dictionary-close t t)
+ (add-hook 'kill-buffer-hook #'dictionary-close t t)
(run-hooks 'dictionary-mode-hook))
;;;###autoload
(defun dictionary ()
- "Create a new dictonary buffer and install `dictionary-mode'."
+ "Create a new dictionary buffer and install `dictionary-mode'."
(interactive)
(let ((buffer (or (and dictionary-use-single-buffer
(get-buffer "*Dictionary*"))
@@ -516,7 +535,7 @@ The connection takes the proxy setting in customization group
;; Dealing with closing the buffer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defun dictionary-close (&rest ignored)
+(defun dictionary-close (&rest _ignored)
"Close the current dictionary buffer and its connection."
(interactive)
(if (eq major-mode 'dictionary-mode)
@@ -548,7 +567,7 @@ The connection takes the proxy setting in customization group
answer)))
(defun dictionary-split-string (string)
- "Split STRING constiting of space-separated words into elements.
+ "Split STRING consisting of space-separated words into elements.
This function knows about the special meaning of quotes (\")"
(let ((list))
(while (and string (> (length string) 0))
@@ -650,7 +669,7 @@ previous state."
(setq dictionary-positions (cons (point) (window-start))))
;; Restore the previous state
-(defun dictionary-restore-state (&rest ignored)
+(defun dictionary-restore-state (&rest _ignored)
"Restore the state just before the last operation."
(let ((position (pop dictionary-position-stack))
(data (pop dictionary-data-stack)))
@@ -702,13 +721,14 @@ of matching words."
(if (dictionary-check-reply reply 552)
(progn
(unless nomatching
- (beep)
- (insert "Word not found, maybe you are looking "
- "for one of these words\n\n")
- (dictionary-do-matching word
- dictionary
- "."
- 'dictionary-display-only-match-result)
+ (insert "Word not found")
+ (dictionary-do-matching
+ word
+ dictionary
+ "."
+ (lambda (reply)
+ (insert ", maybe you are looking for one of these words\n\n")
+ (dictionary-display-only-match-result reply)))
(dictionary-post-buffer)))
(if (dictionary-check-reply reply 550)
(error "Dictionary \"%s\" is unknown, please select an existing one"
@@ -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."
@@ -809,7 +830,7 @@ The DICTIONARY is only used for decoding the bytes to display the DESCRIPTION."
(defun dictionary-display-word-definition (reply word dictionary)
"Insert the definition in REPLY for the current WORD from DICTIONARY.
It will replace links which are found in the REPLY and replace
-them with buttons to perform a a new search."
+them with buttons to perform a new search."
(let ((start (point)))
(insert (dictionary-decode-charset reply dictionary))
(insert "\n\n")
@@ -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
@@ -850,7 +873,7 @@ The word is taken from the buffer, the DICTIONARY is given as argument."
'help-echo (concat "Press Mouse-2 to lookup \""
word "\" in \"" dictionary "\"")))))
-(defun dictionary-select-dictionary (&rest ignored)
+(defun dictionary-select-dictionary (&rest _ignored)
"Save the current state and start a dictionary selection."
(interactive)
(dictionary-ensure-buffer)
@@ -858,7 +881,7 @@ The word is taken from the buffer, the DICTIONARY is given as argument."
(dictionary-do-select-dictionary)
(dictionary-store-state 'dictionary-do-select-dictionary nil))
-(defun dictionary-do-select-dictionary (&rest ignored)
+(defun dictionary-do-select-dictionary (&rest _ignored)
"The workhorse for doing the dictionary selection."
(message "Looking up databases and descriptions")
@@ -871,7 +894,7 @@ The word is taken from the buffer, the DICTIONARY is given as argument."
(unless (dictionary-check-reply reply 110)
(error "Unknown server answer: %s"
(dictionary-reply reply)))
- (dictionary-display-dictionarys))))
+ (dictionary-display-dictionaries))))
(defun dictionary-simple-split-string (string &optional pattern)
"Return a list of substrings of STRING which are separated by PATTERN.
@@ -886,7 +909,7 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
start (match-end 0)))
(nreverse (cons (substring string start) parts))))
-(defun dictionary-display-dictionarys ()
+(defun dictionary-display-dictionaries ()
"Handle the display of all dictionaries existing on the server."
(dictionary-pre-buffer)
(insert "Please select your default dictionary:\n\n")
@@ -894,7 +917,7 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
(dictionary-display-dictionary-line "! \"The first matching dictionary\"")
(let* ((reply (dictionary-read-answer))
(list (dictionary-simple-split-string reply "\n+")))
- (mapc 'dictionary-display-dictionary-line list))
+ (mapc #'dictionary-display-dictionary-line list))
(dictionary-post-buffer))
(defun dictionary-display-dictionary-line (string)
@@ -962,7 +985,7 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
(dictionary-store-state 'dictionary-display-more-info dictionary))))
-(defun dictionary-select-strategy (&rest ignored)
+(defun dictionary-select-strategy (&rest _ignored)
"Save the current state and start a strategy selection."
(interactive)
(dictionary-ensure-buffer)
@@ -992,7 +1015,7 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
(dictionary-display-strategy-line ". \"The servers default\"")
(let* ((reply (dictionary-read-answer))
(list (dictionary-simple-split-string reply "\n+")))
- (mapc 'dictionary-display-strategy-line list))
+ (mapc #'dictionary-display-strategy-line list))
(dictionary-post-buffer))
(defun dictionary-display-strategy-line (string)
@@ -1008,7 +1031,7 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
'help-echo (purecopy "Mouse-2 to select this matching algorithm"))
(insert "\n")))))
-(defun dictionary-set-strategy (strategy &rest ignored)
+(defun dictionary-set-strategy (strategy &rest _ignored)
"Select this STRATEGY as new default."
(setq dictionary-default-strategy strategy)
(dictionary-restore-state)
@@ -1052,7 +1075,6 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
(defun dictionary-display-only-match-result (reply)
"Display the results from the current matches in REPLY without the headers."
-
(let ((number (nth 1 (dictionary-reply-list reply)))
(list (dictionary-simple-split-string (dictionary-read-answer) "\n+")))
(insert number " matching word" (if (equal number "1") "" "s")
@@ -1117,9 +1139,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
@@ -1146,7 +1170,7 @@ allows editing it."
;; if called by pressing the button
(unless word
(setq word (read-string "Search word: " nil 'dictionary-word-history)))
- ;; just in case non-interactivly called
+ ;; just in case non-interactively called
(unless dictionary
(setq dictionary dictionary-default-dictionary))
(dictionary-new-search (cons word dictionary)))
@@ -1170,7 +1194,7 @@ allows editing it."
(describe-function 'dictionary-mode))
;;;###autoload
-(defun dictionary-match-words (&optional pattern &rest ignored)
+(defun dictionary-match-words (&optional pattern &rest _ignored)
"Search PATTERN in current default dictionary using default strategy."
(interactive)
;; can't use interactive because of mouse events
@@ -1224,10 +1248,10 @@ allows editing it."
;;; Tooltip support
-;; Add a mode indicater named "Dict"
+;; Add a mode indicator named "Dict"
(defvar dictionary-tooltip-mode
nil
- "Indicates wheather the dictionary tooltip mode is active.")
+ "Indicates whether the dictionary tooltip mode is active.")
(nconc minor-mode-alist '((dictionary-tooltip-mode " Dict")))
(defcustom dictionary-tooltip-dictionary
@@ -1246,7 +1270,7 @@ allows editing it."
(defun dictionary-read-definition (&ignore)
(let ((list (dictionary-simple-split-string (dictionary-read-answer) "\n+")))
- (mapconcat 'identity (cdr list) "\n")))
+ (mapconcat #'identity (cdr list) "\n")))
;;; Tooltip support for GNU Emacs
(defvar global-dictionary-tooltip-mode
@@ -1298,8 +1322,8 @@ will be set to nil."
(interactive)
(tooltip-mode on)
(if on
- (add-hook 'tooltip-functions 'dictionary-display-tooltip)
- (remove-hook 'tooltip-functions 'dictionary-display-tooltip)))
+ (add-hook 'tooltip-functions #'dictionary-display-tooltip)
+ (remove-hook 'tooltip-functions #'dictionary-display-tooltip)))
;;;###autoload
(defun dictionary-tooltip-mode (&optional arg)
@@ -1340,9 +1364,8 @@ any buffer where (dictionary-tooltip-mode 1) has been called."
(make-local-variable 'dictionary-tooltip-mouse-event)
(setq-default track-mouse on)
(dictionary-switch-tooltip-mode 1)
- (if on
- (global-set-key [mouse-movement] 'dictionary-tooltip-track-mouse)
- (global-set-key [mouse-movement] 'ignore))
+ (global-set-key [mouse-movement]
+ (if on #'dictionary-tooltip-track-mouse #'ignore))
on))
(provide 'dictionary)