Fix byte-compiler errors, opt. dep now required

visual-fill-column is now required, instead of being used when
available
This commit is contained in:
TEC 2021-01-02 04:27:21 +08:00
parent e6aadc6b69
commit c3bb28fead
Signed by: tec
GPG Key ID: 779591AFDB81F06C
1 changed files with 84 additions and 82 deletions

166
lexic.el
View File

@ -11,7 +11,7 @@
;; Maintainer: TEC <tec@tecosaur.com>
;; Version: 0.0.1
;; Homepage: https://github.com/tecosaur/lexic
;; Package-Requires: ((emacs "26.3") (dash "2.17.0"))
;; Package-Requires: ((emacs "26.3") (dash "2.17.0") (visual-fill-column "2.2"))
;;; License:
@ -92,8 +92,81 @@
(require 'outline)
(require 'dash)
(require 'visual-fill-column)
(require 'cl-lib)
;;;;##################################################################
;;;; User Options, Variables
;;;;##################################################################
(defvar lexic-buffer-name "*lexic*"
"The name of the buffer of lexic.")
(defvar lexic-dictionary-list t
"A list of dictionaries to use.
Each entry is a string denoting the name of a dictionary, which
is then passed to lexic through the '-u' command line option.
Any non-list value means using all the dictionaries.")
(defvar lexic-dictionary-alist nil
"An alist of dictionaries, used to interactively form
dictionary list. It has the form:
((\"full\" . t)
(\"group1\" \"dict1\" \"dict2\" ...)
(\"group2\" \"dict2\" \"dict3\"))
Any cons cell here means using all dictionaries.")
(defvar lexic-program-path (executable-find "sdcv")
"The path of lexic program.")
(defvar lexic-dictionary-path nil
"The path of dictionaries.")
(defvar lexic-word-processor nil
"This is the function that take a word (stirng)
and return a word or a list of words for lookup by `lexic-search'.
All lookup result(s) will finally be concatenated together.
`nil' value means do nothing with the original word.
The following is an example. This function takes the original word and
compare whether simplified and traditional form of the word are the same.
If not, look up both of the words.
(lambda (word)
(let ((sim (chinese-conv word \"simplified\"))
(tra (chinese-conv word \"traditional\")))
(if (not (string= sim tra))
(list sim tra)
word)))
")
(defvar lexic-current-dictionary-list nil)
(defvar lexic-wait-timeout 2
"The max time (in seconds) to wait for the lexic process to produce some output.")
(defvar lexic-wait-interval 0.1
"The interval (in seconds) to sleep each time to wait for lexic's output.")
(defconst lexic-process-name "%lexic-mode-process%")
(defconst lexic-process-buffer-name "*lexic-mode-process*")
(defvar lexic-word-prompts '("Enter word or phrase: ")
"A list of prompts that lexic use to prompt for word.")
(defvar lexic-choice-prompts '("Your choice[-1 to abort]: ")
"A list of prompts that lexic use to prompt for a choice of multiple candicates.")
(defvar lexic-result-patterns '("^Found [0-9]+ items, similar to [*?/|]*\\(.+?\\)[*?]*\\.")
"A list of patterns to extract result word of lexic.
Special characters are stripped.")
(defvar lexic--search-history nil)
(defvar lexic--search-history-position -1)
(defvar lexic-expand-abbreviations t
"Whether or not to try to expand abbreviations, where they are expected.")
;;; ==================================================================
;;; Frontend, search word and display lexic buffer
@ -208,8 +281,6 @@ TODO decouple the tool from the general method."
(let (resize-mini-windows)
(shell-command (concat lexic-program-path " -l") lexic-buffer-name)))
(defvar lexic-current-dictionary-list nil)
(defun lexic-generate-dictionary-argument ()
"Generate the appropriate stcv dictionary argument.
Using `lexic-current-dictionary-list' and `lexic-dictionary-path'."
@ -220,9 +291,6 @@ Using `lexic-current-dictionary-list' and `lexic-dictionary-path'."
(list "-u" dict))
lexic-current-dictionary-list))))
(defvar lexic--search-history nil)
(defvar lexic--search-history-position -1)
(defun lexic-search-history-backwards ()
"Show the previous word searched."
(interactive)
@ -307,10 +375,9 @@ Turning on Text mode runs the normal hook `lexic-mode-hook'."
(setq buffer-read-only t)
(setq-local outline-regexp "\u200B+")
(setq-local outline-heading-end-regexp "\u2008")
(when (require 'visual-fill-column nil t)
(setq-local visual-fill-column-center-text t)
(visual-fill-column-mode 1)
(setq-local display-line-numbers-type nil)))
(setq-local visual-fill-column-center-text t)
(visual-fill-column-mode 1)
(setq-local display-line-numbers-type nil))
(defun lexic-mode-reinit ()
"Re-initialize buffer.
@ -436,24 +503,6 @@ Optional argument RAW-P signals whether the result should be formatted or not."
(if raw-p result
(lexic-format-result result))))
(defvar lexic-wait-timeout 2
"The max time (in seconds) to wait for the lexic process to produce some output.")
(defvar lexic-wait-interval 0.1
"The interval (in seconds) to sleep each time to wait for lexic's output.")
(defconst lexic-process-name "%lexic-mode-process%")
(defconst lexic-process-buffer-name "*lexic-mode-process*")
(defvar lexic-word-prompts '("Enter word or phrase: ")
"A list of prompts that lexic use to prompt for word.")
(defvar lexic-choice-prompts '("Your choice[-1 to abort]: ")
"A list of prompts that lexic use to prompt for a choice of multiple candicates.")
(defvar lexic-result-patterns '("^Found [0-9]+ items, similar to [*?/|]*\\(.+?\\)[*?]*\\.")
"A list of patterns to extract result word of lexic.
Special characters are stripped.")
(defun lexic-get-process ()
"Get or create the lexic process."
(let ((process (get-process lexic-process-name)))
@ -596,7 +645,7 @@ Returns a list of plists with keys :word, :dict, and :info."
'face 'outline-3)
(propertize
(mapconcat 'identity (cadr dict-suggestions) "\n\u200B\u200B\u200B")
'face 'font-lock-keyword-face)))
'face 'font-lock-keyword-face)))
(sort suggestions
(lambda (a b)
(< (or (lexic-dictionary-spec (car a) :priority) 1)
@ -660,10 +709,6 @@ entry."
(search-forward-regexp "\u200B+"))
(point)))
(defun lexic-dictionary-spec (dict spec)
"Helper function to get a :SPEC of a given DICT."
(plist-get (cdr (assoc dict lexic-dictionary-specs)) spec))
(defvar lexic-dictionary-specs
'(("Webster's Revised Unabridged Dictionary (1913)"
:formatter lexic-format-webster
@ -689,6 +734,10 @@ according to lexic, and the cdr is a plist whith the following options:
:formatter - a function with signature (ENTRY WORD) that returns a string
:priority - sort priority, defaults to 1")
(defun lexic-dictionary-spec (dict spec)
"Helper function to get a :SPEC of a given DICT."
(plist-get (cdr (assoc dict lexic-dictionary-specs)) spec))
(defun lexic-format-webster (entry &optional _expected-word)
"Make a Webster's dictionary ENTRY for WORD look nice.
Designed for Webster's Revised Unabridged Dictionary (1913),
@ -739,8 +788,8 @@ This should also work nicely with GCIDE."
(etymology (lexic-format-expand-abbreviations (match-string (if alternative-forms 6 5) match)))
(category (lexic-format-expand-abbreviations (match-string 7 match)))
(last-newline (lambda (text) (- (length text)
(or (save-match-data
(string-match "\n[^\n]*\\'" text)) 0)))))
(or (save-match-data
(string-match "\n[^\n]*\\'" text)) 0)))))
(concat
"\u200B\u200B\u200B"
(propertize word2
@ -853,9 +902,6 @@ This should also work nicely with GCIDE."
(propertize (concat " "(match-string 1 match) ": ")
'face 'bold)))))
(defvar lexic-expand-abbreviations t
"Whether or not to try to expand abbreviations, where they are expected.")
(defun lexic-format-expand-abbreviations (content &optional force)
"Expand certain standard abbreviations in CONTENT when `lexic-expand-abbreviations' or FORCE are non-nil."
(when content
@ -1853,49 +1899,5 @@ Designed using http://download.huzheng.org/bigdict/stardict-Soule_s_Dictionary_o
","
(propertize "," 'face 'font-lock-type-face))))
;;;;##################################################################
;;;; User Options, Variables
;;;;##################################################################
(defvar lexic-buffer-name "*lexic*"
"The name of the buffer of lexic.")
(defvar lexic-dictionary-list t
"A list of dictionaries to use.
Each entry is a string denoting the name of a dictionary, which
is then passed to lexic through the '-u' command line option.
Any non-list value means using all the dictionaries.")
(defvar lexic-dictionary-alist nil
"An alist of dictionaries, used to interactively form
dictionary list. It has the form:
((\"full\" . t)
(\"group1\" \"dict1\" \"dict2\" ...)
(\"group2\" \"dict2\" \"dict3\"))
Any cons cell here means using all dictionaries.")
(defvar lexic-program-path (executable-find "sdcv")
"The path of lexic program.")
(defvar lexic-dictionary-path nil
"The path of dictionaries.")
(defvar lexic-word-processor nil
"This is the function that take a word (stirng)
and return a word or a list of words for lookup by `lexic-search'.
All lookup result(s) will finally be concatenated together.
`nil' value means do nothing with the original word.
The following is an example. This function takes the original word and
compare whether simplified and traditional form of the word are the same.
If not, look up both of the words.
(lambda (word)
(let ((sim (chinese-conv word \"simplified\"))
(tra (chinese-conv word \"traditional\")))
(if (not (string= sim tra))
(list sim tra)
word)))
")
(provide 'lexic)
;;; lexic.el ends here