* 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 , when preedit str is longer than 1 | IM_PREEDITING | update preedit str, update and show candidate list | | Y | IM_PREEDITING | type , 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 (_) #)) 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: