Commit 1e3a14ff authored by Yuanle Song's avatar Yuanle Song
Browse files

only keep zero.el in pkg branch.

parent 72196558
VERSION := $(shell grep 'setq zero-version' zero-framework.el | cut -d'"' -f2)
default: dist
#===============
# multiple file
#===============
check:
emacs -Q --batch -l zero-reload-all.el -f zero-rebuild -l zero-table.el -l zero-table-test.el -f ert-run-tests-batch
zip:
git archive -o zero-el-$(VERSION).zip --prefix=zero/ HEAD
#==========================
# single file distribution
#==========================
dist: dist-check
build:
if [ ! -x ~/.local/bin/pytest ]; then python3 -m pip install --user pytest; fi
~/.local/bin/pytest build.py
./build.py
sed -i "s/PKG_VERSION/$(VERSION)/g" zero.el
dist-check: build
emacs -Q --batch -l ~/.emacs.d/elpa/s-1.11.0/s.el -l zero.el -l zero-panel-test.el -l zero-pinyin-service-test.el -l zero-framework-test.el -l zero-pinyin-test.el -l zero-table.el -l zero-table-test.el -f ert-run-tests-batch
#====================
# other make targets
#====================
install-git-hooks:
rsync -air git-hooks/ .git/hooks/
version:
@echo $(VERSION)
.PHONY: default check zip dist build dist-check install-git-hooks version
zero-el
Copyright (C) 2019 Yuanle Song <sylecn@gmail.com>
ibus-compute-pixel-position function in zero.el is copied from ibus.el.
zero--ibus-compute-pixel-position function in zero.el is copied from ibus.el.
This function is under GPLv3 license. Copyright (C) 2010-2012 S. Irie
......@@ -8,6 +8,11 @@ zero-el provides zero-pinyin, an Emacs pinyin input method for Chinese and
zero-framework, which is an emacs Chinese input method framework.
* File list
- zero.el
It's a generated file for one-file package distribution. Not used for
development.
- zero-framework.el
zero framework source code. This provides the framework and user interface
......
#!/usr/bin/env python3
# coding=utf-8
"""
build zero.el from zero.el.in and other el files
"""
import logging
logger = logging.getLogger(__name__)
def placeholder_for_file(fn):
"""return placeholder that should be used for filename.
"""
return "INCLUDE_" + fn.replace('-', '_').replace('.', '_').upper()
def test_placeholder_for_file():
assert placeholder_for_file("zero-panel.el") == "INCLUDE_ZERO_PANEL_EL"
assert placeholder_for_file("zero-pinyin-service.el") == (
"INCLUDE_ZERO_PINYIN_SERVICE_EL")
def get_el_file_body(fn):
rows = []
append = False
with open(fn) as f:
for line in f:
if append:
if '(require ' in line:
logger.debug("skipping require call: %s", line)
continue
rows.append(line)
if line.startswith('(provide'):
break
else:
if line.startswith(";;; Code:"):
rows.append(";; body of %s\n" % (fn,))
append = True
return "".join(rows)
def expand_placeholder_for_files(old_content, filenames):
"""replace INCLUDE_FOO_BAR_EL by body of foo-bar.el.
"""
result = old_content
for fn in filenames:
result = result.replace(placeholder_for_file(fn),
get_el_file_body(fn))
return result
def main():
logging.basicConfig(
format='%(asctime)s [%(module)s] %(levelname)-8s %(message)s',
level=logging.INFO)
with open("zero.el.in") as tpl:
content = tpl.read()
expanded_content = expand_placeholder_for_files(content, [
"zero-panel.el",
"zero-framework.el",
"zero-table.el",
"zero-pinyin-service.el",
"zero-pinyin.el",
])
with open('zero.el', 'w') as out:
out.write(expanded_content)
if __name__ == '__main__':
main()
#!/bin/sh
set -e
make dist-check
git add zero.el
* COMMENT -*- mode: org -*-
#+Date: 2019-10-08
Time-stamp: <2019-10-16>
#+STARTUP: content
* notes :entry:
** 2019-04-01 zero.el a Chinese IM framework in emacs; FSM :doc:
title was: how to write a modern im for emacs.
cd ~/lisp/elisp/zero/
- DONE can I implement it as a minor mode? yes.
- DONE can I use panel to show candidates? yes.
- zero minor mode FSM
implemented in zero.el
| Imp | state | action | next state | trigger action |
|-----+------------------+-----------------------------------------------------+------------------+---------------------------------------------------------------------------------------------------------|
| Y | IM_OFF | M-x zero-on or zero-toggle | IM_WAITING_INPUT | turn on minor mode |
| Y | IM_WAITING_INPUT | type M-x zero-off or zero-toggle | IM_OFF | turn off minor mode |
| Y | IM_WAITING_INPUT | type character that can start a sequence | IM_PREEDITING | update preedit str, show candidate list |
| Y | IM_WAITING_INPUT | type character that can not start a sequence | IM_WAITING_INPUT | insert character (full-width aware) |
| Y | IM_WAITING_INPUT | type [,.?!\] | IM_WAITING_INPUT | insert Chinese punctuation character (full-width aware) |
| Y | IM_PREEDITING | type character (that is not SPC, digit keys) | IM_PREEDITING | update preedit str, update and show candidate list |
| Y | IM_PREEDITING | type RET | IM_WAITING_INPUT | commit preedit str (full-width aware), hide candidate list, reset preedit str |
| Y | IM_PREEDITING | type SPC | IM_WAITING_INPUT | commit first candidate or preedit str (full-width aware), reset preedit str |
| Y | IM_PREEDITING | type digit keys | IM_WAITING_INPUT | commit nth candidate if it exists, otherwise, append to preedit str |
| | IM_PREEDITING | type C-g | IM_WAITING_INPUT | reset IM (reset preedit str, hide candidate list) |
| Y | IM_PREEDITING | type M-x zero-off or zero-toggle | IM_OFF | reset IM, turn off minor mode |
| Y | IM_PREEDITING | type <backspace>, when preedit str is longer than 1 | IM_PREEDITING | update preedit str, update and show candidate list |
| Y | IM_PREEDITING | type <backspace>, when preedit str is length 1 | IM_WAITING_INPUT | reset IM |
| Y | IM_PREEDITING | focus in | IM_PREEDITING | show candidat list |
| Y | IM_PREEDITING | focus out | IM_PREEDITING | hide panel |
| Y | IM_PREEDITING | type [,.?!\] | IM_WAITING_INPUT | commit first candidate or preedit str (full-width aware), insert Chinese punctuation (full-width aware) |
| Y | IM_PREEDITING | type -/= | IM_PREEDITING | candiate page up/down |
| | | | | |
in IM_OFF state, zero should not do any preedit try nor do punctuation
translate.
- DONE make zero-quickdial IM work in emacs.
see ~/lisp/elisp/zero/zero-quickdial.el
- DONE make zero-table IM work in emacs. with zero-panel.
see ~/lisp/elisp/zero/zero-table.el
- during development, press F8 to byte-compile and load the current el file.
this will also look for errors in the file.
press F9 to run ert tests.
- TODOs
- whenever a command moves point, IM should probably reset()
I can't remap every possible key/function.
- I need hook for buffer/window focus in/out.
currently, when user switch to another buffer, the panel will still show.
user can click mouse in another emacs window.
whenever focus is moved outside current buffer, I need a hook to run
zero-focus-out.
how to reproduce the problem
=============================
open emacs, split, top window show buffer with file t3, bottom window show
buffer with file t4.
in t3 buffer, press F1 to toggle zero on. type "a", candidate list will
show. now press C-x o to switch to t4 buffer. candidate list didn't go
away. because I can't find a hook for it.
the mouse case:
=================
open emacs, split, top window show buffer with file t3, bottom window show
buffer with file t4.
in t3 buffer, press F1 to toggle zero on. type "a", candidate list will
show. now click mouse on t4 buffer. candidate list didn't go away. because
I can't find a hook for it.
- how to check whether string contains character?
without converting char to string.
(zero-table-can-start-sequence) can use this.
** 2019-10-10 documents
- Using of D-Bus
https://www.gnu.org/software/emacs/manual/html_mono/dbus.html
* later :entry:
* current :entry:
**
** 2019-10-15 make package-lint happy on all el files.
- package-lint doesn't support multi-file package.
Need to add headers to make it happy.
Because it doesn't have concept on multi-file package, it insists all
functions in file start with file name prefix. I can't have zero-* utility
function in zero-panel.el
- M-x package-lint-current-buffer fail on zero.el file
this line:
(eval-when-compile (require 'cl-macs))
M-x package-lint-current-buffer fails on a fresh .el file with just that
line.
#+BEGIN_SRC sh
Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
package-lint--map-symbol-match("(\\s-*?require\\s-*?'cl-\\(?:macs\\|seq\\)\\_>" #f(compiled-function (_) #<bytecode 0x15e4cd9>))
package-lint--check-no-use-of-cl-lib-sublibraries()
package-lint--check-all()
package-lint-buffer()
package-lint-current-buffer()
funcall-interactively(package-lint-current-buffer)
call-interactively(package-lint-current-buffer record nil)
command-execute(package-lint-current-buffer record)
execute-extended-command(nil "package-lint-current-buffer" nil)
funcall-interactively(execute-extended-command nil "package-lint-current-buffer" nil)
call-interactively(execute-extended-command nil nil)
command-execute(execute-extended-command)
#+END_SRC
package-lint--check-no-use-of-cl-lib-sublibraries
'warning
"This file is not in the `cl-lib' ELPA compatibility package: require `cl-lib' instead."
says you should use cl-lib instead. may as well try that.
yes. that works.
- create a single file for distribution.
package-lint doesn't support multiple file pkg yet.
- create a single zero.el file for distribution.
rename current zero.el to zero-framework.el
create zero.el.in
- make build
should generate zero.el and run checks on it.
- insert content to zero.el.in
;;; Code:
;;; .*\.el ends here
- now package-lint should be fine.
- I should I put zero.el in a branch or a separate git repo?
separate git repo is better.
how to auto build and commit on source repo push?
use gocd CI, I can trigger a build. just run git add and git push there?
if run in the same repo, two branch is required.
- maybe just add zero.el in master branch and commit it anyway.
-
* done :entry:
** 2019-10-11 move tests to separated files.
otherwise (require 'zero-pinyin) will fail because (require 'ert) is not in
source code.
** 2019-10-09 release zero-el on melpa
melpa/CONTRIBUTING.org at master · melpa/melpa · GitHub
https://github.com/melpa/melpa/blob/master/CONTRIBUTING.org
Making your package ready for inclusion
https://github.com/melpa/melpa/blob/master/CONTRIBUTING.org#making-your-package-ready-for-inclusion
Packaging Basics - GNU Emacs Lisp Reference Manual
https://www.gnu.org/software/emacs/manual/html_node/elisp/Packaging-Basics.html#Packaging-Basics
name: zero
version: 1.2.2
brief: a Chinese input method framework
long: zero is a Chinese input method framework for Emacs, implemented
as an Emacs minor mode. A zero-pinyin input method is included with zero
distribution.
dependencies: s
progress:
Preparing a pull request to MELPA
https://github.com/melpa/melpa/blob/master/CONTRIBUTING.org#preparing-a-pull-request-to-melpa
- problems
- should I create two pkg, one for zero-framework and one for zero-pinyin?
does melpa require two repo for this?
- minimum s version?
I only use s-contains-p s-join.
checked github
tag 1.2.0 already include these functions.
https://github.com/magnars/s.el/blob/1.2.0/s.el
- Note that there is no way to control the order in which files are
byte-compiled.
// seems my pkg compile just fine.
- how to add autoload magic comments?
https://www.gnu.org/software/emacs/manual/html_node/elisp/Autoload.html
A magic autoload comment (often called an autoload cookie) consists of
‘;;;###autoload’, on a line by itself, just before the real definition of
the function in its autoloadable source file.
add this for some user commands.
zero-set-im
zero-set-default-im
zero-on
zero-toggle
- run package-lint
- Prefix function names with #’ (i.e., the special form function) instead of
just ’ (i.e., the special form quote) to tell the compiler this is a
function reference. E.g., (seq-filter #'evenp list).
I don't think this is necessary in my code.
- do I need to fix all checkdoc problems for my pkg to be accepted by melpa?
search: melpa checkdoc one liner functions docstring
yes. they require all checkdoc problem be fixed.
Add recipe for a.el by dotemacs · Pull Request #4830 · melpa/melpa
https://github.com/melpa/melpa/pull/4830
how to specify minimum emacs version?
;; Package-Requires: ((emacs "24"))
- DONE fix all checkdoc problems.
// except for zero-mode, which I don't know how to fix. all other problems
fixed.
- Disambiguate zero-mode by preceding w/ function,command,variable,option
or symbol. (C-h,f,e,n,p,q) [4 times]
this one is really confusing.
org-mode-map doesn't do this.
magit-mode-map doesn't do this.
- TODO how to add dbus as dependencies?
some emacs build may not have dbus.
(require 'dbus)
also how to only allow install on linux? when I test it dbus only worked
in linux.
what's the correct syntax for specifying dbus as dependency?
(dbus "1.0")
didn't work.
- search: package-install-file package--description-file: Wrong type argument: stringp, nil
search: emacs package-install-file install tar package--description-file: Wrong type argument: stringp, nil
install from dir is okay.
install from tar is not. Not sure what's wrong.
** 2019-10-08 support full-width characters and symbols.
全角 半角
- feature requests
- when zero-mode is on, and in full-width mode
- commit English character and symbol should commit full-width character
if there is a full-width character. This should happen before checking
punctuation mapping. if a map is found, punctuation mapping is ignored.
- type letters should still go into preedit str, only commit full-width
char when user press RET.
- when zero-mode is on, and in half-width mode (the default)
- do what it does now. punctuation mapping is checked.
- implementation
- Block Halfwidth and Fullwidth Forms – Codepoints
https://codepoints.net/halfwidth_and_fullwidth_forms
- how to support full width character and symbol in zero?
update fsm table.
add a zero-full-width-mode variable
add default binding shift+space, M-x zero-toggle-full-width-mode
use modeline LIGHTER to show full/half width mode.
when in full-width mode, show ZeroF.
FSM table:
move from gtk-im-module-zero operational file.
- updated FSM.
so it's only a few changes.
- when insert character that can't start a sequence, insert char should be
full-width aware.
zero-self-insert-command
DONE zero-commit-preedit-str
DONE zero-convert-punctuation
- when commit preedit str, insert should be full-width aware.
- when insert Chinese punctuation character, insert should be full-width aware.
- problems
- where is the GB standard file?
- docs
GB/T 15834―2011 标点符号用法 电子版
http://people.ubuntu.com/~happyaron/l10n/GB(T)15834-2011.html
doesn't have much about full width vs half width.
- indeed double quotation mark is different from fullwidth quotation mark.
LEFT DOUBLE QUOTATION MARK “”
FULLWIDTH QUOTATION MARK ""
- search U+FF02
U+FF02 FULLWIDTH QUOTATION MARK – Codepoints
https://codepoints.net/U+FF02
Block Halfwidth and Fullwidth Forms – Codepoints
https://codepoints.net/halfwidth_and_fullwidth_forms
- why bind S-SPC key in zero-mode-map didn't work.
global-set-key does work.
shift-space is always translated to space in minor mode?
shift is not registered as key prefix.
I will just use another key binding for this command.
try M-space. nope.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Keymaps-and-Minor-Modes.html#Keymaps-and-Minor-Modes
Minor modes may bind commands to key sequences consisting of C-c followed
by a punctuation character. However, sequences consisting of C-c followed
by one of {}<>:;, or a control character or digit, are reserved for major
modes. Also, C-c letter is reserved for users. See Key Binding
Conventions.
try use C-c , , and C-c , .
how to add C-c , as prefix key and add binding for those two commands?
it works.
- elisp how to convert unicode hex to char?
1. Non-ASCII Characters
https://ftp.gnu.org/old-gnu/Manuals/elisp-manual-21-2.8/html_chapter/elisp_33.html#SEC541
FF01 to FF65 only 65 chars. I will just type it.
"\uff01" !
char to code point:
(split-char ?\)(unicode 0 255 1)
# FF01
(split-char ?\!)(unicode 0 255 1)
(insert (make-char 'unicode 0 255 1))
(split-char ?\!)(ascii 33)
# FF5A
(split-char ?\z)(unicode 0 255 90)
(insert (make-char 'unicode 0 255 90))
(split-char ?\z)(ascii 122)
# FF65
(split-char ?\・)(unicode 0 255 101)
(insert (make-char 'unicode 0 255 101))
ascii [33, 122]
map to
unicode 0 255 [1, 101].
then pick a few others if they are of importance.
- commit preedit str in full-width mode didn't work.
it still commit half-width str.
is zero-commit-preedit-str called at all? there is no debug message.
that is for commit preedit-str when there is no candidate.
when I press RET, the code is in zero-return.
- type = will insert both full-width char and half-width char.
fixed.
* wontfix :entry:
;;; zero-framework-test.el --- tests for zero-framework.el -*- lexical-binding: t -*-
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
;;; Commentary:
;; tests for zero-framework.el
;;; Code:
(require 'zero-framework)
(require 'ert)
(ert-deftest zero-cycle-list ()
(should (= (zero-cycle-list '(1 2 3) 1) 2))
(should (eq (zero-cycle-list '(a b c) 'a) 'b))
(should (eq (zero-cycle-list '(a b c) 'b) 'c))
(should (eq (zero-cycle-list '(a b c) 'c) 'a))
(should (eq (zero-cycle-list '(a b c) 'd) nil)))
(ert-deftest zero-convert-ch-to-full-width ()
(should (= (zero-convert-ch-to-full-width ?\!) ?\!)))
(ert-deftest zero-convert-str-to-full-width ()
(should (string-equal "!" (zero-convert-str-to-full-width "!")))
(should (string-equal "(" (zero-convert-str-to-full-width "(")))
(should (string-equal "(:)" (zero-convert-str-to-full-width "(:)")))
(should (string-equal "ABab" (zero-convert-str-to-full-width "ABab")))
(should (string-equal "hehe" (zero-convert-str-to-full-width "hehe")))
(should (string-equal "(A)" (zero-convert-str-to-full-width "(A)"))))
(provide 'zero-framework-test)
;;; zero-framework-test.el ends here
This diff is collapsed.
;;; zero-panel-test.el --- tests for zero-panel.el -*- lexical-binding: t -*-
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
;;; Commentary:
;;
;;; Code:
(require 'ert)
(require 'zero-panel)
(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))))))
(provide 'zero-panel-test)
;;; zero-panel-test.el ends here
;;; zero-panel --- Provide emacs interface for zero-panel dbus service. -*- lexical-binding: t -*-
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
;;; Commentary:
;; use dbus to communicate with zero-panel service.
;;; Code:
;;================
;; implementation
;;================
(require 'dbus)
(require 's)
(defun zero-panel-error-handler (event error)
"Handle dbus errors.
EVENT and ERROR are error-handler arguments."
(when (or (string-equal "com.emacsos.zero.Panel"
(dbus-event-interface-name event))
(s-contains-p "com.emacsos.zero.Panel" (cadr error)))
(error "Zero-panel dbus failed: %S" (cadr error))))
(add-hook 'dbus-event-error-functions 'zero-panel-error-handler)
(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'.
ARGS optional extra args to pass to the wrapped function."
(apply 'dbus-call-method-asynchronously
: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.
HINTS should be an alist 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))))
;;============
;; public API
;;============