Support nil value for dictionary-server
* net/lisp/dictionary.el (dictionary-server): Support choice to select the dictionary server to use * net/lisp/dictionary.el (dictionary-check-connection): Support nil value for dictionary-server This nil value is the new default value of that variable. When opening a new connection and dictionary-server is nil the code behaves the following way: - it will first try to connect to a dictd server running on localhost - if that fails, it queries the user if the alternative server (dict.org) should be consulted - if the user agrees, the connection is made to dict.org This allows the default value of dictionary-server not to connect a remote server by default. The user is always able to select a different server by customizing the variable dictionary-search.
This commit is contained in:
parent
837505075c
commit
2f1e4fbc42
1 changed files with 77 additions and 51 deletions
|
@ -44,13 +44,13 @@
|
|||
;; Stuff for customizing.
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defvar dictionary-server)
|
||||
(defvar dictionary-current-server)
|
||||
(defun dictionary-set-server-var (name value)
|
||||
(if (and (boundp 'dictionary-connection)
|
||||
dictionary-connection
|
||||
(eq (dictionary-connection-status dictionary-connection) 'up)
|
||||
(y-or-n-p
|
||||
(concat "Close existing connection to " dictionary-server "? ")))
|
||||
(concat "Close existing connection to " dictionary-current-server "? ")))
|
||||
(dictionary-connection-close dictionary-connection))
|
||||
(set-default name value))
|
||||
|
||||
|
@ -63,11 +63,22 @@
|
|||
:group 'dictionary)
|
||||
|
||||
(defcustom dictionary-server
|
||||
"dict.org"
|
||||
"This server is contacted for searching the dictionary"
|
||||
nil
|
||||
"This server is contacted for searching the dictionary.
|
||||
|
||||
You can specify here:
|
||||
|
||||
- Automatic: First try localhost, then dict.org after confirmation
|
||||
- localhost: Only use localhost
|
||||
- dict.org: Only use dict.org
|
||||
- User-defined: You can specify your own server here
|
||||
"
|
||||
:group 'dictionary
|
||||
:set 'dictionary-set-server-var
|
||||
:type 'string
|
||||
:type '(choice (const :tag "Automatic" nil)
|
||||
(const :tag "localhost" "localhost")
|
||||
(const :tag "dict.org" "dict.org")
|
||||
(string :tag "User-defined"))
|
||||
:version "28.1")
|
||||
|
||||
(defcustom dictionary-port
|
||||
|
@ -421,24 +432,23 @@ is utf-8"
|
|||
"Return the reply list stored in `reply'."
|
||||
(list 'get reply ''reply-list))
|
||||
|
||||
(defun dictionary-check-connection ()
|
||||
"Check if there is already a connection open"
|
||||
(if (not (and dictionary-connection
|
||||
(eq (dictionary-connection-status dictionary-connection) 'up)))
|
||||
(defun dictionary-open-server (server)
|
||||
"Opens a new connection to this server"
|
||||
(let ((wanted 'raw-text)
|
||||
(coding-system nil))
|
||||
(if (member wanted (coding-system-list))
|
||||
(setq coding-system wanted))
|
||||
(let ((coding-system-for-read coding-system)
|
||||
(coding-system-for-write coding-system))
|
||||
(message "Opening connection to %s:%s" dictionary-server
|
||||
(setq dictionary-current-server server)
|
||||
(message "Opening connection to %s:%s" server
|
||||
dictionary-port)
|
||||
(dictionary-connection-close dictionary-connection)
|
||||
(setq dictionary-connection
|
||||
(if dictionary-use-http-proxy
|
||||
(dictionary-connection-open dictionary-proxy-server
|
||||
dictionary-proxy-port)
|
||||
(dictionary-connection-open dictionary-server dictionary-port)))
|
||||
(dictionary-connection-open server dictionary-port)))
|
||||
(set-process-query-on-exit-flag
|
||||
(dictionary-connection-process dictionary-connection)
|
||||
nil)
|
||||
|
@ -448,7 +458,7 @@ is utf-8"
|
|||
dictionary-proxy-server
|
||||
dictionary-proxy-port)
|
||||
(dictionary-send-command (format "CONNECT %s:%d HTTP/1.1"
|
||||
dictionary-server
|
||||
server
|
||||
dictionary-port))
|
||||
;; just a \r\n combination
|
||||
(dictionary-send-command "")
|
||||
|
@ -470,7 +480,23 @@ is utf-8"
|
|||
(message nil)
|
||||
(unless (dictionary-check-reply reply 250)
|
||||
(error "Unknown server answer: %s"
|
||||
(dictionary-reply reply))))))))
|
||||
(dictionary-reply reply)))))))
|
||||
|
||||
(defun dictionary-check-connection ()
|
||||
"Check if there is already a connection open"
|
||||
(if (not (and dictionary-connection
|
||||
(eq (dictionary-connection-status dictionary-connection) 'up)))
|
||||
(if dictionary-server
|
||||
(dictionary-open-server dictionary-server)
|
||||
(let ((server "localhost"))
|
||||
(condition-case nil
|
||||
(dictionary-open-server server)
|
||||
(error
|
||||
(if (y-or-n-p
|
||||
(format "Failed to open server %s, continue with dict.org?"
|
||||
server))
|
||||
(dictionary-open-server "dict.org")
|
||||
(error "Failed automatic server selection, please customize dictionary-server"))))))))
|
||||
|
||||
(defun dictionary-mode-p ()
|
||||
"Return non-nil if current buffer has dictionary-mode"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue