From 5647052b8e398f2729181989c7ae6b85df566fe2 Mon Sep 17 00:00:00 2001
From: Yuanle Song <sylecn@gmail.com>
Date: Sun, 1 Sep 2019 22:32:13 +0800
Subject: [PATCH] v1.0.1 fix all byte-compile warnings

added "make compile" to byte-compile and run tests in emacs batch mode.
---
 Makefile               |  4 +-
 zero-framework.el      | 98 +++++++++++++++++++++---------------------
 zero-panel.el          |  1 +
 zero-pinyin-service.el | 36 +++++++++-------
 zero-pinyin.el         |  9 ++--
 zero-reload-all.el     | 15 ++++++-
 6 files changed, 92 insertions(+), 71 deletions(-)

diff --git a/Makefile b/Makefile
index 88b53b6..178c8af 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+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
diff --git a/zero-framework.el b/zero-framework.el
index 3ce52f3..1c0cef0 100644
--- a/zero-framework.el
+++ b/zero-framework.el
@@ -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,21 +252,21 @@ 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
-	   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
-	   for lst* = lst then (cdr lst*)
-	   for n* = n then (1- n*)
-	   until (or (zerop n*) (null lst*))
-	   finally (return lst*))))
+  (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"
+	       (cl-loop
+		for lst* = lst then (cdr lst*)
+		for n* = n then (1- n*)
+		until (or (zerop n*) (null lst*))
+		finally (return lst*))))
     (take zero-candidates-per-page
 	  (drop (* zero-candidates-per-page zero-current-page) candidates))))
 
@@ -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
     (?_ "——")
     (?< "《")
     (?> "》")
diff --git a/zero-panel.el b/zero-panel.el
index 0e170a5..a83c486 100644
--- a/zero-panel.el
+++ b/zero-panel.el
@@ -24,6 +24,7 @@
 ;;================
 
 (require 'dbus)
+(require 's)
 
 (defun zero-panel-error-handler (event error)
   "handle dbus errors"
diff --git a/zero-pinyin-service.el b/zero-pinyin-service.el
index 0429502..9f0b2ce 100644
--- a/zero-pinyin-service.el
+++ b/zero-pinyin-service.el
@@ -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)
 
diff --git a/zero-pinyin.el b/zero-pinyin.el
index cc3540e..aebb73f 100644
--- a/zero-pinyin.el
+++ b/zero-pinyin.el
@@ -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"
diff --git a/zero-reload-all.el b/zero-reload-all.el
index 4c80ffb..c31137c 100644
--- a/zero-reload-all.el
+++ b/zero-reload-all.el
@@ -19,13 +19,26 @@
 
 ;;; Code:
 
+(defun zero-rebuild (&optional source-dir)
+  "rebuild zero-el"
+  (interactive)
+  ;; for loading s
+  (package-initialize)
+  (let ((source-dir (or source-dir "~/lisp/elisp/zero/")))
+    (dolist (f '("zero-quickdial.el"
+		 "zero-panel.el"
+		 "zero-framework.el"
+		 "zero-pinyin-service.el"
+		 "zero-pinyin.el"))
+      (byte-compile-file (concat source-dir f) t))))
+
 (defun zero-reload-all ()
   (interactive)
   (byte-recompile-directory "~/lisp/elisp/zero/" 0)
   (dolist (f '("zero-quickdial.elc"
 	       "zero-panel.elc"
 	       "zero-framework.elc"
-	       "zero-table.elc"
+	       "zero-table.el"
 	       "zero-pinyin-service.elc"
 	       "zero-pinyin.elc"))
     (load-file f)))
-- 
GitLab