diff --git a/zero-framework.el b/zero-framework.el index 60cb33c7e6b12e8e2fa1ab9b7375c621e2f3e7fa..e198262bc06f0c219c6433fe20a37e173e0234e9 100644 --- a/zero-framework.el +++ b/zero-framework.el @@ -191,7 +191,13 @@ if t, `zero-debug' will output debug msg in *zero-debug* buffer") zero-candidates)))) (zero-panel-show-candidates (funcall zero-get-preedit-str-for-panel-func) - (length candidates-on-page) candidates-on-page) + (length candidates-on-page) + candidates-on-page + `(("in_emacs" t) + ("filename" ,(or (buffer-file-name) "")) + ("page_number" ,zero-current-page) + ("has_next_page" ,(or (> (length (or candidates zero-candidates)) (* zero-candidates-per-page (1+ zero-current-page))) (< zero-fetch-size (* zero-candidates-per-page (+ 2 zero-current-page))))) + ("has_previous_page" ,(> zero-current-page 0)))) (zero-debug "candidates:\n %s\n " (s-join "\n " candidates-on-page)) (destructuring-bind (x y) (zero-get-point-position) (zero-panel-move x y)))) @@ -202,7 +208,7 @@ if t, `zero-debug' will output debug msg in *zero-debug* buffer") (unless (functionp zero-build-candidates-func) (signal 'wrong-type-argument (list 'functionp zero-build-candidates-func))) (prog1 (funcall zero-build-candidates-func preedit-str fetch-size) - (setq zero-fetch-size fetch-size))) + (setq zero-fetch-size (max fetch-size (length zero-candidates))))) (defun zero-build-candidates-complete (candidates) "called when `zero-build-candidates-async' returns" @@ -300,7 +306,8 @@ return ch's Chinese punctuation if ch is converted. return nil otherwise" new-fetch-size (lambda (candidates) (zero-build-candidates-complete candidates) - (setq zero-fetch-size new-fetch-size) + (setq zero-fetch-size (max new-fetch-size + (length candidates))) (zero-just-page-down))) (zero-just-page-down)))) diff --git a/zero-panel.el b/zero-panel.el index 741e060a92fe7cf7dc6116524b2f7f1f364ecfdf..abb007bf1a1d597fd4d5d87aecd42a7947acfe77 100644 --- a/zero-panel.el +++ b/zero-panel.el @@ -19,11 +19,45 @@ (defun zero-panel-async-call (method _handler &rest args) "call Method on zero-panel service asynchronously. This is a wrapper around `dbus-call-method-asynchronously'" (apply 'dbus-call-method-asynchronously - :session "com.emacsos.zero.Panel" - "/com/emacsos/zero/Panel" - "com.emacsos.zero.Panel" + :session + "com.emacsos.zero.Panel1" ; well known name + "/com/emacsos/zero/Panel1" ; object path + "com.emacsos.zero.Panel1.PanelInterface" ; interface name method nil :timeout 500 args)) +;;========================= +;; public utility function +;;========================= + +(defun zero-alist-to-asv (hints) + "convert lisp alist to dbus a{sv} data structure. +alist should be of form '((k1 [v1type] v1) (k2 [v2type] v2)). + +For example, +(zero-alist-to-asv + '((\"name\" \"foo\") + (\"timeout\" :int32 10))) +=> +'(:array + (:dict-entry \"name\" (:variant \"foo\")) + (:dict-entry \"timeout\" (:variant :int32 10))) +" + (if (null hints) + '(:array :signature "{sv}") + (let ((result '(:array))) + (dolist (item hints) + (push (list :dict-entry (car item) (cons :variant (cdr item))) result)) + (reverse result)))) + +(ert-deftest zero-alist-to-asv () + (should (equal (zero-alist-to-asv nil) '(:array :signature "{sv}"))) + (should (equal (zero-alist-to-asv + '(("name" "foo") + ("timeout" :int32 10))) + '(:array + (:dict-entry "name" (:variant "foo")) + (:dict-entry "timeout" (:variant :int32 10)))))) + ;;============ ;; public API ;;============ @@ -33,12 +67,13 @@ (x, y) are coordinates, (0, 0) is at screen top left corner" (zero-panel-async-call "Move" nil :int32 x :int32 y)) -(defun zero-panel-show-candidates (preedit_str candidate_length candidates) +(defun zero-panel-show-candidates (preedit_str candidate_length candidates &optional hints) "show candidates" (zero-panel-async-call "ShowCandidates" nil :string preedit_str :int32 candidate_length - (or candidates '(:array)))) + (or candidates '(:array)) + (zero-alist-to-asv hints))) (defun zero-panel-show () "show panel" @@ -50,6 +85,7 @@ (defun zero-panel-quit () "quit panel application" + (interactive) (zero-panel-async-call "Quit" nil)) (provide 'zero-panel) diff --git a/zero-pinyin.el b/zero-pinyin.el index 72b128e6544bd404aeb0a667814c79804124ab57..ba817eed8909d3290551f6b5dc9e205ac5b4ba5e 100644 --- a/zero-pinyin.el +++ b/zero-pinyin.el @@ -47,10 +47,10 @@ (if zero-pinyin--build-candidates-use-test-data (progn (zero-pinyin-build-candidates-test preedit-str) - (setq zero-fetch-size fetch-size)) + (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 fetch-size) + (setq zero-fetch-size (max fetch-size (length (first result)))) (setq zero-pinyin-used-preedit-str-lengths (second result)) (first result)))) @@ -62,7 +62,7 @@ fetch-size (lambda (candidates matched_preedit_str_lengths) (setq zero-pinyin-used-preedit-str-lengths matched_preedit_str_lengths) - (setq zero-fetch-size fetch-size) + (setq zero-fetch-size (max fetch-size (length candidates))) ;; Note: with dynamic binding, this command result in (void-variable ;; complete-func) error. (funcall complete-func candidates))))