Commit 5647052b authored by Yuanle Song's avatar Yuanle Song
Browse files

v1.0.1 fix all byte-compile warnings

added "make compile" to byte-compile and run tests in emacs batch mode.
parent 25a49fde
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
compile:
	emacs -Q --batch -l zero-reload-all.el -f zero-rebuild -l zero-table.el -f ert-run-tests-batch
zip:
	git archive -o zero-el.zip --prefix=zero/ HEAD
.PHONY: zip
.PHONY: zip compile
+49 −49
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@
;; dependencies
;;==============

(require 'cl)
(require 'cl-macs)
(require 's)
(require 'zero-panel)

@@ -79,15 +79,15 @@ respectively."

(defun zero-get-point-position ()
  "return current point's position (x y) based on origin of screen top left corner"
  (destructuring-bind (x y line-height) (ibus-compute-pixel-position)
  (cl-destructuring-bind (x y line-height) (ibus-compute-pixel-position)
    (cond
     ((functionp 'window-absolute-pixel-position)
      ;; introduced in emacs 26
      (destructuring-bind (x . y) (window-absolute-pixel-position)
      (cl-destructuring-bind (x . y) (window-absolute-pixel-position)
	(list x (+ y line-height))))
     ((functionp 'frame-edges)
      ;; introduced in emacs 25
      (destructuring-bind (frame-x frame-y &rest _)
      (cl-destructuring-bind (frame-x frame-y &rest rest)
	  (frame-edges nil 'inner-edges)
	(list (+ frame-x x) (+ frame-y y line-height))))
     (t
@@ -129,7 +129,7 @@ if item is not in lst, return nil"

;; zero-el version
(defvar zero-version nil "zero-el package version")
(setq zero-version "1.0.0")
(setq zero-version "1.0.1")

;; FSM state
(defconst *zero-state-im-off* 'IM-OFF)
@@ -140,32 +140,6 @@ if item is not in lst, return nil"
(defconst *zero-punctuation-level-full* 'FULL)
(defconst *zero-punctuation-level-none* 'NONE)

;;; concrete input method should define these functions and set them in the
;;; corresponding *-func variable.
(defun zero-build-candidates-default (_preedit-str _fetch-size) nil)
(defun zero-can-start-sequence-default (_ch) nil)
(defun zero-get-preedit-str-for-panel-default () zero-preedit-str)
(defvar zero-build-candidates-func 'zero-build-candidates-default
  "contains a function to build candidates from preedit-str. The function accepts param preedit-str, fetch-size, returns candidate list.")
(defvar zero-build-candidates-async-func 'zero-build-candidates-async-default
  "contains a function to build candidates from preedit-str. The function accepts param preedit-str, fetch-size, and a complete-func that should be called on returned candidate list.")
(defvar zero-can-start-sequence-func 'zero-can-start-sequence-default
  "contains a function to decide whether a char can start a preedit sequence")
(defvar zero-handle-preedit-char-func 'zero-handle-preedit-char-default
  "contains a function to handle IM-PREEDITING state char insert.
The function should return t if char is handled.
This allow input method to override default logic.")
(defvar zero-get-preedit-str-for-panel-func 'zero-get-preedit-str-for-panel-default
  "contains a function that return preedit-str to show in zero-panel")
(defvar zero-backspace-func 'zero-backspace-default
  "contains a function to handle <backward> char")
(defvar zero-handle-preedit-char-func 'zero-handle-preedit-char-default
  "hanlde character insert in `*zero-state-im-preediting*' mode")
(defvar zero-preedit-start-func 'nil
  "called when enter `*zero-state-im-preediting*' state")
(defvar zero-preedit-end-func 'nil
  "called when leave `*zero-state-im-preediting*' state")

(defvar zero-im nil
  "current input method. if nil, the empty input method will be used.
in the empty input method, only punctuation is handled. Other keys are pass through")
@@ -209,6 +183,32 @@ otherwise, next single quote insert close quote")
(defvar zero-previous-page-key ?\- "previous page key")
(defvar zero-next-page-key ?\= "next page key")

;;; concrete input method should define these functions and set them in the
;;; corresponding *-func variable.
(defun zero-build-candidates-default (_preedit-str _fetch-size) nil)
(defun zero-can-start-sequence-default (_ch) nil)
(defun zero-get-preedit-str-for-panel-default () zero-preedit-str)
(defvar zero-build-candidates-func 'zero-build-candidates-default
  "contains a function to build candidates from preedit-str. The function accepts param preedit-str, fetch-size, returns candidate list.")
(defvar zero-build-candidates-async-func 'zero-build-candidates-async-default
  "contains a function to build candidates from preedit-str. The function accepts param preedit-str, fetch-size, and a complete-func that should be called on returned candidate list.")
(defvar zero-can-start-sequence-func 'zero-can-start-sequence-default
  "contains a function to decide whether a char can start a preedit sequence")
(defvar zero-handle-preedit-char-func 'zero-handle-preedit-char-default
  "contains a function to handle IM-PREEDITING state char insert.
The function should return t if char is handled.
This allow input method to override default logic.")
(defvar zero-get-preedit-str-for-panel-func 'zero-get-preedit-str-for-panel-default
  "contains a function that return preedit-str to show in zero-panel")
(defvar zero-backspace-func 'zero-backspace-default
  "contains a function to handle <backward> char")
(defvar zero-handle-preedit-char-func 'zero-handle-preedit-char-default
  "hanlde character insert in `*zero-state-im-preediting*' mode")
(defvar zero-preedit-start-func 'nil
  "called when enter `*zero-state-im-preediting*' state")
(defvar zero-preedit-end-func 'nil
  "called when leave `*zero-state-im-preediting*' state")

(defvar zero-enable-debug t
  "whether to enable debug.
if t, `zero-debug' will output debug msg in *zero-debug* buffer")
@@ -252,17 +252,17 @@ if t, `zero-debug' will output debug msg in *zero-debug* buffer")

(defun zero-candidates-on-page (candidates)
  "return candidates on current page for given candidates list"
  (flet ((take (n lst)
          "take the first n element from lst. if there is not enough
elements, return lst as it is."
          (loop
  (cl-flet ((take (n lst)
	       "take the first n element from lst. if there is not
enough elements, return lst as it is."
	       (cl-loop
		for lst* = lst then (cdr lst*)
		for n* = n then (1- n*)
		until (or (zerop n*) (null lst*))
		collect (car lst*)))
	    (drop (n lst)
	       "drop the first n elements from lst"
          (loop
	       (cl-loop
		for lst* = lst then (cdr lst*)
		for n* = n then (1- n*)
		until (or (zerop n*) (null lst*))
@@ -274,7 +274,7 @@ elements, return lst as it is."
  "show candidates using zero-panel via IPC/RPC"
  (let ((candidates-on-page (zero-candidates-on-page (or candidates
							 zero-candidates))))
    (destructuring-bind (x y) (zero-get-point-position)
    (cl-destructuring-bind (x y) (zero-get-point-position)
      (zero-panel-show-candidates
       (funcall zero-get-preedit-str-for-panel-func)
       (length candidates-on-page)
@@ -311,7 +311,7 @@ elements, return lst as it is."
(defun zero-convert-punctuation-basic (ch)
  "convert punctuation for *zero-punctuation-level-basic*
return ch's Chinese punctuation if ch is converted. return nil otherwise"
  (case ch
  (cl-case ch
    (?, ",")
    (?. "。")
    (?? "?")
@@ -323,7 +323,7 @@ return ch's Chinese punctuation if ch is converted. return nil otherwise"
(defun zero-convert-punctuation-full (ch)
  "convert punctuation for *zero-punctuation-level-full*
return ch's Chinese punctuation if ch is converted. return nil otherwise"
  (case ch
  (cl-case ch
    (?_ "——")
    (?< "《")
    (?> "》")
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
;;================

(require 'dbus)
(require 's)

(defun zero-panel-error-handler (event error)
  "handle dbus errors"
+20 −16
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
;;================

(require 'dbus)
(require 'cl-lib)

(defun zero-pinyin-service-error-handler (event error)
  "handle dbus errors"
@@ -75,7 +76,8 @@ fetch-size try to fetch this many candidates or more"
    ;; (push :signature result)
    ;; (push "(ii)" result)
    (dolist (pypair candidate_pinyin_indices)
      (push (list :struct :int32 (first pypair) :int32 (second pypair)) result))
      (push (list :struct :int32 (cl-first pypair) :int32 (cl-second pypair))
	    result))
    (reverse result)))

(ert-deftest zero-pinyin-candidate-pinyin-indices-to-dbus-format ()
@@ -107,27 +109,29 @@ fetch-size try to fetch this many candidates or more"
;; some app test
;;================

(require 'cl-macs)

(ert-deftest zero-pinyin-service-get-candidates ()
  (destructuring-bind (cs ls &rest rest)
  (cl-destructuring-bind (cs ls &rest rest)
      (zero-pinyin-service-get-candidates "liyifeng" 1)
    (should (equal (first cs) "李易峰"))
    (should (= (first ls) 8)))
  (destructuring-bind (cs ls &rest rest)
    (should (equal (car cs) "李易峰"))
    (should (= (car ls) 8)))
  (cl-destructuring-bind (cs ls &rest rest)
      (zero-pinyin-service-get-candidates "wenti" 1)
    (should (equal (first cs) "问题"))
    (should (= (first ls) 5)))
  (destructuring-bind (cs ls &rest rest)
    (should (equal (car cs) "问题"))
    (should (= (car ls) 5)))
  (cl-destructuring-bind (cs ls &rest rest)
      (zero-pinyin-service-get-candidates "meiyou" 1)
    (should (equal (first cs) "没有"))
    (should (= (first ls) 6)))
  (destructuring-bind (cs ls &rest rest)
    (should (equal (car cs) "没有"))
    (should (= (car ls) 6)))
  (cl-destructuring-bind (cs ls &rest rest)
      (zero-pinyin-service-get-candidates "shi" 1)
    (should (equal (first cs) "是"))
    (should (= (first ls) 3)))
  (destructuring-bind (cs ls &rest rest)
    (should (equal (car cs) "是"))
    (should (= (car ls) 3)))
  (cl-destructuring-bind (cs ls &rest rest)
      (zero-pinyin-service-get-candidates "de" 1)
    (should (equal (first cs) "的"))
    (should (= (first ls) 2))))
    (should (equal (car cs) "的"))
    (should (= (car ls) 2))))

(provide 'zero-pinyin-service)

+5 −4
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
(require 's)
(require 'zero-framework)
(require 'zero-pinyin-service)
(require 'cl-lib)

;;===============================
;; basic data and emacs facility
@@ -87,10 +88,10 @@
	(setq zero-fetch-size (max fetch-size (length zero-candidates))))
    (zero-debug "zero-pinyin building candidate list synchronously\n")
    (let ((result (zero-pinyin-service-get-candidates preedit-str fetch-size)))
      (setq zero-fetch-size (max fetch-size (length (first result))))
      (setq zero-pinyin-used-preedit-str-lengths (second result))
      (setq zero-pinyin-candidates-pinyin-indices (third result))
      (first result))))
      (setq zero-fetch-size (max fetch-size (length (cl-first result))))
      (setq zero-pinyin-used-preedit-str-lengths (cl-second result))
      (setq zero-pinyin-candidates-pinyin-indices (cl-third result))
      (cl-first result))))

(defun zero-pinyin-build-candidates-async (preedit-str fetch-size complete-func)
  "build candidate list, when done call complete-func on it"
Loading