From fadbfb321f469c21fbc465be023e0b4cf55d9fd7 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 13 May 2019 00:48:04 -0400 Subject: [PATCH] Add :input chinese module #1371 --- init.example.el | 5 ++- modules/input/chinese/README.org | 42 +++++++++++++++++++++ modules/input/chinese/config.el | 61 +++++++++++++++++++++++++++++++ modules/input/chinese/packages.el | 9 +++++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 modules/input/chinese/README.org create mode 100644 modules/input/chinese/config.el create mode 100644 modules/input/chinese/packages.el diff --git a/init.example.el b/init.example.el index 38bbcefac..ef8980298 100644 --- a/init.example.el +++ b/init.example.el @@ -8,7 +8,10 @@ ;; More information about these modules (and what flags they support) can be ;; found in modules/README.org. -(doom! :completion +(doom! :input + ;;chinese + + :completion company ; the ultimate code completion backend ;;helm ; the *other* search engine for love and life ;;ido ; the other *other* search engine... diff --git a/modules/input/chinese/README.org b/modules/input/chinese/README.org new file mode 100644 index 000000000..e63140473 --- /dev/null +++ b/modules/input/chinese/README.org @@ -0,0 +1,42 @@ +#+TITLE: input/chinese +#+DATE: May 13, 2019 +#+SINCE: 2.1 +#+STARTUP: inlineimages + +* Table of Contents :TOC_3:noexport: +- [[#description][Description]] + - [[#module-flags][Module Flags]] + - [[#plugins][Plugins]] + - [[#hacks][Hacks]] +- [[#prerequisites][Prerequisites]] +- [[#features][Features]] +- [[#configuration][Configuration]] +- [[#troubleshooting][Troubleshooting]] + +* Description +This module adds support for traditional Chinese script by introducing two input +methods: Pinyin and Wubi. + +#+begin_quote +Because I am unable to personally test this module, help to improve this module +would be greatly appreciated! Especially where performance is concerned. +#+end_quote + +** Module Flags ++ =+wubi= + +** Plugins ++ [[https://github.com/tumashu/pyim][pyim]] (unless =+wubi=) ++ [[https://github.com/zilongshanren/chinese-wbim][chinese-wbim]] (if =+wubi=) ++ [[https://github.com/cute-jumper/fcitx.el][fcitx]] ++ [[https://github.com/cute-jumper/ace-pinyin][ace-pinyin]] ++ [[https://github.com/coldnew/pangu-spacing][pangu-spacing]] + +** Hacks ++ ~org-html-paragraph~ has been modified to join consecutive Chinese lines into + a single long line without wanted spaced (when exporting org-mode to html). + +* TODO Prerequisites +* TODO Features +* TODO Configuration +* TODO Troubleshooting diff --git a/modules/input/chinese/config.el b/modules/input/chinese/config.el new file mode 100644 index 000000000..0d44c2561 --- /dev/null +++ b/modules/input/chinese/config.el @@ -0,0 +1,61 @@ +;;; input/chinese/config.el -*- lexical-binding: t; -*- + +(def-package! pyim + :unless (featurep! +wubi) + :config + (setq pyim-dcache-directory (concat doom-cache-dir "pyim/") + pyim-page-tooltip t + default-input-method "pyim")) + + +(def-package! chinese-wbim + :when (featurep! +wubi) + :init + (setq chinese-wbim-use-tooltip nil) ; tooptip isn't good enough + :config + (setq default-input-method 'chinese-wubi) + + (autoload 'chinese-wbim-use-package "chinese-wubi" + "Another emacs input method") + (register-input-method + "chinese-wubi" "euc-cn" 'chinese-wbim-use-package + "五笔" "汉字五笔输入法" "wb.txt") + (require 'chinese-wbim-extra) + (global-set-key ";" 'chinese-wbim-insert-ascii)) + + +(def-package! pangu-spacing + :hook (doom-after-init . global-pangu-spacing-mode) + :config + ;; Always insert `real' space in org-mode. + (setq-hook! 'org-mode-hook pangu-spacing-real-insert-separtor t)) + + +(def-package! fcitx + :when (executable-find "fcitx-remote") + :after evil + :config (fcitx-evil-turn-on)) + + +(def-package! ace-pinyin + :after (:or avy ace-window) + :config + (setq ace-pinyin-use-avy t) + (ace-pinyin-global-mode t)) + + +;; +;;; Hacks + +(defun +chinese*org-html-paragraph (paragraph contents info) + "Join consecutive Chinese lines into a single long line without unwanted space +when exporting org-mode to html." + (let* ((fix-regexp "[[:multibyte:]]") + (origin-contents contents) + (fixed-contents + (replace-regexp-in-string + (concat "\\(" fix-regexp "\\) *\n *\\(" fix-regexp "\\)") + "\\1\\2" + origin-contents))) + (list paragraph fixed-contents info))) +(advice-add #'org-html-paragraph :filter-args #'+chinese*org-html-paragraph) diff --git a/modules/input/chinese/packages.el b/modules/input/chinese/packages.el new file mode 100644 index 000000000..5addf5fe0 --- /dev/null +++ b/modules/input/chinese/packages.el @@ -0,0 +1,9 @@ +;; -*- no-byte-compile: t; -*- +;;; input/chinese/packages.el + +(if (featurep! +wubi) + (package! chinese-wbim) + (package! pyim)) +(package! fcitx) +(package! ace-pinyin) +(package! pangu-spacing)