progfolio / doct

DOCT: Declarative Org Capture Templates for Emacs
GNU General Public License v3.0
380 stars 8 forks source link

auto switch input method #19

Closed driftcrow closed 4 years ago

driftcrow commented 4 years ago

support auto switch input method in some field like Chinese name

progfolio commented 4 years ago

I'm not sure what you're asking for. Please provide more detail and an example.

driftcrow commented 4 years ago

An example template for ledeger like: "%(org-read-date) * recieve %^{Received From} %^{For why} Assets:%^{Account|Personal|Home} %^{Amount} %^{Currency|CNY|USD|JPY} Income:Gifts "

these are multi field for input ,so I want when the cursor in some field the input switch to English, and in some fields as For why, from then switch the input method to Chinese for input Chinese word.

progfolio commented 4 years ago

Thank you for the example. I understand what you're trying to achieve now. This use-case isn't general enough to integrate into doct, but it shouldn't be too hard to configure something.

You could add a function to minibuffer-setup-hook which checks the prompt and conditionally enables an input method. e.g.:

(defun +minibuffer-polyglot ()
  "Switch input method if minibuffer prompt starts with \"!\"."
  (if (string-prefix-p "!" (minibuffer-prompt))
      (set-input-method "chinese-b5-quick")
    (deactivate-input-method)))

(add-hook 'minibuffer-setup-hook #'+minibuffer-polyglot t)

Here the prompt for !one should use the chinese-b5-quick input method, and two should use the default input method:

(let ((org-capture-templates
       (doct '("polyglot test" :keys "p"
               :file "/tmp/polyglot.org"
               :type plain
               :template "%^{!one} %^{two}"))))
       (org-capture nil "p"))

Note this solution will work with any minibuffer prompt, which may be more than you want. In that case I would look into temporarily adding the hook only during org-capture-mode, or making use of minibuffer-with-setup-hook if you're calling your own read function. You can obviously also change the condition and input-method in +minibuffer-polyglot to whatever suits your needs.

Does that help?

driftcrow commented 4 years ago

Most sincere thanks for your response my request , I'll try it .