Commit f1e9b326 authored by Yuanle Song's avatar Yuanle Song

v2.5.0 add completion for zero-input-set-im;

use string for input method name in `zero-input-ims'.
parent f3d85a67
......@@ -111,11 +111,58 @@ cd ~/lisp/elisp/zero/
* later :entry:
* current :entry:
**
** 2019-11-03 add completion support for zero-input-set-im
complete registered im symbols.
** 2019-10-23 checkdoc and package-lint can't ignore some non-issues.
I can't run them in git pre-commit hook.
* done :entry:
** 2019-11-03 add completion support for zero-input-set-im
complete registered im symbols.
- 2020-02-16
Function: completing-read prompt collection &optional predicate
make sure non-interactively usage still works.
(zero-input-set-im 'pinyin)
- DONE allow input method name to be string.
to add backward compatibility, symbol is also supported.
symbol is auto converted to lower case string.
string is a better fit for names. it can include unicode strings easier.
- problems
- how to call completing-read when call interactively?
search: use completing-read with interactive function
just call the function when &optional arg is nil.
- (zero-input-set-im 'pinyin)
this doesn't allow input pinyin after switching to table and back。
if then else issue.
fixed.
- DONE when im name is string, alist eq comparison won't work.
change to string-equal based compare.
search: assq-delete-all but with string-equal
emacs - Elisp: How to delete an element from an association list with string key - Stack Overflow
https://stackoverflow.com/questions/9812393/elisp-how-to-delete-an-element-from-an-association-list-with-string-key
- (zero-input-set-im 'pinyin)
method not registered.
(assq im-name zero-input-ims)
(assoc im-name zero-input-ims)
- try switch to empty and back.
(zero-input-set-im 'pinyin)
(zero-input-set-im 'empty)
it works.
** 2020-02-16 declare zero-input-punctuation-level, zero-input-full-width-p using defcustom
use set-default to set the value.
......
......@@ -133,7 +133,7 @@ If item is not in lst, return nil."
;; zero-input-el version
(defvar zero-input-version nil "Zero package version.")
(setq zero-input-version "2.4.0")
(setq zero-input-version "2.5.0")
;; FSM state
(defconst zero-input--state-im-off 'IM-OFF)
......@@ -797,11 +797,14 @@ virtual functions corresponding variable
registered input method is saved in `zero-input-ims'"
;; add or replace entry in `zero-input-ims'
(unless (symbolp im-name)
(signal 'wrong-type-argument (list 'symbolp im-name)))
(setq zero-input-ims (assq-delete-all im-name zero-input-ims))
(unless (stringp im-name)
(signal 'wrong-type-argument (list 'stringp im-name)))
(setq zero-input-ims (delq (assoc im-name zero-input-ims) zero-input-ims))
(setq zero-input-ims (push (cons im-name im-functions-alist) zero-input-ims)))
;; Built-in empty input method. It only handles Chinese punctuation.
(zero-input-register-im "empty" nil)
;;============
;; public API
;;============
......@@ -845,21 +848,32 @@ LEVEL the level to set to."
(message "punctuation level set to %s" zero-input-punctuation-level))
;;;###autoload
(defun zero-input-set-im (im-name)
(defun zero-input-set-im (&optional im-name)
"Select zero input method for current buffer.
if IM-NAME is nil, use default empty input method"
;; TODO provide auto completion for im-name
(interactive "SSet input method to: ")
IM-NAME (a string) should be a registered input method in zero-input."
(interactive)
;; when switch away from an IM, run last IM's :shutdown function.
(if zero-input-im
(let ((shutdown-func (cdr (assq :shutdown (cdr (assq zero-input-im zero-input-ims))))))
(let ((shutdown-func (cdr (assq :shutdown (cdr (assoc zero-input-im zero-input-ims))))))
(if (functionp shutdown-func)
(funcall shutdown-func))))
(if im-name
(let ((im-functions (cdr (assq im-name zero-input-ims))))
(if im-functions
(cond
((null im-name)
;; TODO is there an easier way to provide auto complete in mini buffer?
;; I used a recursive call to the same function.
(let ((im-name-str (completing-read "Set input method to: " zero-input-ims)))
(if (s-blank? im-name-str)
(error "Input method name is required")
(zero-input-set-im im-name-str))))
((symbolp im-name)
;; for backward compatibility
(zero-input-set-im (symbol-name im-name)))
(t (let* ((im-slot (assoc im-name zero-input-ims))
(im-functions (cdr im-slot)))
(if im-slot
(progn
(zero-input-debug "switching to %s input method" im-name)
;; TODO create a macro to reduce code duplication and human
;; error.
;;
......@@ -895,16 +909,7 @@ if IM-NAME is nil, use default empty input method"
(if (functionp init-func)
(funcall init-func)))
(setq zero-input-im im-name))
(error "Input method %s not registered in zero" im-name)))
(zero-input-debug "using default empty input method")
(setq zero-input-build-candidates-func 'zero-input-build-candidates-default)
(setq zero-input-build-candidates-async-func 'zero-input-build-candidates-async-default)
(setq zero-input-can-start-sequence-func 'zero-input-can-start-sequence-default)
(setq zero-input-handle-preedit-char-func 'zero-input-handle-preedit-char-default)
(setq zero-input-get-preedit-str-for-panel-func 'zero-input-get-preedit-str-for-panel-default)
(setq zero-input-backspace-func 'zero-input-backspace-default)
(setq zero-input-preedit-start-func nil)
(setq zero-input-preedit-end-func nil)))
(error "Input method %S not registered in zero" im-name))))))
;;;###autoload
(defun zero-input-set-default-im (im-name)
......
......@@ -356,7 +356,7 @@ DIGIT 0 means delete 10th candidate."
(defun zero-input-pinyin-register-im ()
"Register pinyin input method in zero framework."
(zero-input-register-im
'pinyin
"pinyin"
(append
(if zero-input-pinyin-use-async-fetch
'((:build-candidates-async . zero-input-pinyin-build-candidates-async))
......
......@@ -69,7 +69,7 @@
;;===============================
(zero-input-register-im
'zero-input-table
"zero-input-table"
'((:build-candidates . zero-input-table-build-candidates)
(:can-start-sequence . zero-input-table-can-start-sequence)))
......
......@@ -12,7 +12,7 @@
;; See the License for the specific language governing permissions and
;; limitations under the License.
;; Version: 2.4.0
;; Version: 2.5.0
;; URL: https://gitlab.emacsos.com/sylecn/zero-el
;; Package-Requires: ((emacs "24.3") (s "1.2.0"))
......@@ -246,7 +246,7 @@ If item is not in lst, return nil."
;; zero-input-el version
(defvar zero-input-version nil "Zero package version.")
(setq zero-input-version "2.4.0")
(setq zero-input-version "2.5.0")
;; FSM state
(defconst zero-input--state-im-off 'IM-OFF)
......@@ -910,11 +910,14 @@ virtual functions corresponding variable
registered input method is saved in `zero-input-ims'"
;; add or replace entry in `zero-input-ims'
(unless (symbolp im-name)
(signal 'wrong-type-argument (list 'symbolp im-name)))
(setq zero-input-ims (assq-delete-all im-name zero-input-ims))
(unless (stringp im-name)
(signal 'wrong-type-argument (list 'stringp im-name)))
(setq zero-input-ims (delq (assoc im-name zero-input-ims) zero-input-ims))
(setq zero-input-ims (push (cons im-name im-functions-alist) zero-input-ims)))
;; Built-in empty input method. It only handles Chinese punctuation.
(zero-input-register-im "empty" nil)
;;============
;; public API
;;============
......@@ -958,21 +961,32 @@ LEVEL the level to set to."
(message "punctuation level set to %s" zero-input-punctuation-level))
;;;###autoload
(defun zero-input-set-im (im-name)
(defun zero-input-set-im (&optional im-name)
"Select zero input method for current buffer.
if IM-NAME is nil, use default empty input method"
;; TODO provide auto completion for im-name
(interactive "SSet input method to: ")
IM-NAME (a string) should be a registered input method in zero-input."
(interactive)
;; when switch away from an IM, run last IM's :shutdown function.
(if zero-input-im
(let ((shutdown-func (cdr (assq :shutdown (cdr (assq zero-input-im zero-input-ims))))))
(let ((shutdown-func (cdr (assq :shutdown (cdr (assoc zero-input-im zero-input-ims))))))
(if (functionp shutdown-func)
(funcall shutdown-func))))
(if im-name
(let ((im-functions (cdr (assq im-name zero-input-ims))))
(if im-functions
(cond
((null im-name)
;; TODO is there an easier way to provide auto complete in mini buffer?
;; I used a recursive call to the same function.
(let ((im-name-str (completing-read "Set input method to: " zero-input-ims)))
(if (s-blank? im-name-str)
(error "Input method name is required")
(zero-input-set-im im-name-str))))
((symbolp im-name)
;; for backward compatibility
(zero-input-set-im (symbol-name im-name)))
(t (let* ((im-slot (assoc im-name zero-input-ims))
(im-functions (cdr im-slot)))
(if im-slot
(progn
(zero-input-debug "switching to %s input method" im-name)
;; TODO create a macro to reduce code duplication and human
;; error.
;;
......@@ -1008,16 +1022,7 @@ if IM-NAME is nil, use default empty input method"
(if (functionp init-func)
(funcall init-func)))
(setq zero-input-im im-name))
(error "Input method %s not registered in zero" im-name)))
(zero-input-debug "using default empty input method")
(setq zero-input-build-candidates-func 'zero-input-build-candidates-default)
(setq zero-input-build-candidates-async-func 'zero-input-build-candidates-async-default)
(setq zero-input-can-start-sequence-func 'zero-input-can-start-sequence-default)
(setq zero-input-handle-preedit-char-func 'zero-input-handle-preedit-char-default)
(setq zero-input-get-preedit-str-for-panel-func 'zero-input-get-preedit-str-for-panel-default)
(setq zero-input-backspace-func 'zero-input-backspace-default)
(setq zero-input-preedit-start-func nil)
(setq zero-input-preedit-end-func nil)))
(error "Input method %S not registered in zero" im-name))))))
;;;###autoload
(defun zero-input-set-default-im (im-name)
......@@ -1088,7 +1093,7 @@ if IM-NAME is nil, use default empty input method"
;;===============================
(zero-input-register-im
'zero-input-table
"zero-input-table"
'((:build-candidates . zero-input-table-build-candidates)
(:can-start-sequence . zero-input-table-can-start-sequence)))
......@@ -1548,7 +1553,7 @@ DIGIT 0 means delete 10th candidate."
(defun zero-input-pinyin-register-im ()
"Register pinyin input method in zero framework."
(zero-input-register-im
'pinyin
"pinyin"
(append
(if zero-input-pinyin-use-async-fetch
'((:build-candidates-async . zero-input-pinyin-build-candidates-async))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment