0

Is there a way to put some extra conditions on the translation rules of an input method (quail defining rules)?

For example consider the following input method of the answer https://emacs.stackexchange.com/a/61882/

For example, I want put some condition on the rule ("b" ?ܒ).

For example something like below (which unfortunately does not work):

(if (eq (char-before) ?1) ("b" ?ܒ) ("b" ?x)) instead of ("b" ?ܒ).

Edit: The condition (eq (char-before) ?1) that I provided is just for an example, the condition could be unrelated to the preceding character. The condition could be very general. For example the condition could be any of:

  • (not (eq (char-before) ?1))
  • (bobp)
  • (equal (get-last-key) "<home>")
  • (equal (char-after) ?i)
  • (texmathp)
  • (region-active-p)
  • (eolp)
  • org-mode

etc...

Some related questions:

(quail-define-package
 "Syriac-trans" "Ar-trans" "S>" t
 "Input method for Syriac transcription."
 nil t nil nil nil nil nil nil nil nil t)

(quail-define-rules
 ("'" ?ܐ)
 ("b" ?ܒ)
 ("g" ?ܓ)
 ("d" ?ܕ)
 ("h" ?ܗ)
 ("w" ?ܘ)
 ("z" ?ܙ)
 ("x" ?ܚ)
 ("t." ?ܛ)
 ("y" ?ܝ)
 ("k" ?ܟ)
 ("l" ?ܠ)
 ("m" ?ܡ)
 ("n" ?ܢ)
 ("s" ?ܣ)
 ("`" ?ܥ)
 ("p" ?ܦ)
 ("s." ?ܨ)
 ("q" ?ܩ)
 ("r" ?ܪ)
 ("sh" ?ܫ)
 ("t" ?ܬ))
phils
  • 48,657
  • 3
  • 76
  • 115
Name
  • 7,689
  • 4
  • 38
  • 84

2 Answers2

0

Try the snippet below ...

I have copy pasted your snippet and added an entry for 1b.

(quail-define-package
 "Syriac-trans" "Ar-trans" "S>" t
 "Input method for Syriac transcription."
 nil t nil nil nil nil nil nil nil nil t)

(quail-define-rules
 ("'" ?ܐ)
 ("b" ?x)
 ("1b" ?ܒ)
 ("g" ?ܓ)
 ("d" ?ܕ)
 ("h" ?ܗ)
 ("w" ?ܘ)
 ("z" ?ܙ)
 ("x" ?ܚ)
 ("t." ?ܛ)
 ("y" ?ܝ)
 ("k" ?ܟ)
 ("l" ?ܠ)
 ("m" ?ܡ)
 ("n" ?ܢ)
 ("s" ?ܣ)
 ("`" ?ܥ)
 ("p" ?ܦ)
 ("s." ?ܨ)
 ("q" ?ܩ)
 ("r" ?ܪ)
 ("sh" ?ܫ)
 ("t" ?ܬ))
  • Thank you for your answer, the condition `(eq (char-before) ?1)` that I provided was just for an example, the condition could be unrelated to the preceding character. Hence the question still stands. – Name Sep 13 '22 at 06:55
  • Update the question with what the "condition" is ... Consider how ***vague*** your question is. If, for example if the "condition" is "if it is raining outside" , then quail or emacs lisp cannot handle that. Tell us "precisely" what the nature of "condition" is. –  Sep 13 '22 at 06:59
  • I edited the question accordingly. – Name Sep 13 '22 at 07:09
  • The description is not very helpful ... Put it in a human language. You say "I am trying to do this ...". Don't assume that your solution involves use of quail. May be the problem could be solved by yasnippet or tempo etc. –  Sep 13 '22 at 07:16
  • Apropos https://emacs.stackexchange.com/a/51927/31220 --- When the condition is met, what do you want to happen? Not insert syriac characters at all? Insert a different set of syriac characters? ***Your question is stil vague ... You agree that syriac language itself doesn't change whether or not you are in the beginning of buffer, editing texmath or in org-mode etc ...*** What are you trying to do? Why do you think that the syriac method as defined by you is insufficient? –  Sep 13 '22 at 07:35
0

Yes, from my reading you can do this with the quail systems if you wish.

(quail-define-rules &rest RULES)
...
Each argument is a list of KEY and TRANSLATION.
KEY is a string meaning a sequence of keystrokes to be translated.
TRANSLATION is a character, a string, a vector, a Quail map, or a function.
...
If TRANSLATION is a Quail map or a function symbol which returns a Quail map,
it is used to handle KEY.
...

Hence your function could perform any logic you wish, and return a map with any translation you want (which could be the original keystrokes if you chose not to translate them to anything else).

phils
  • 48,657
  • 3
  • 76
  • 115
  • Phils, thank you very much, this is exactly what I am looking for. Could you please elaborate more how to put a *function symbol which returns a Quail map* instead of a `quail map`? I found very little information about this on the web. How looks like a function which returns a Quail map? I would be very helpful to the reader if you could provide an example. Assume the name of that function is `myfunction`, should I put something like `("b" 'myfunction)`? Any help is appreciated. – Name Sep 13 '22 at 10:47
  • `quail-define-rules` is a macro, so I would *expect* it'd just be `("b" myfunction)` without the quote (as macro arguments are not evaluated), but this isn't something I've tried, so I don't know for sure how that argument gets processed within the macro body. You'll have to experiment and report back. – phils Sep 13 '22 at 13:26
  • https://emacs.stackexchange.com/a/5683/454 might also be useful wrt extending the rules of an existing input method. – phils Sep 13 '22 at 14:24
  • When I put with quote `'myfunction` I get the error `Invalid object in Quail map: quote`. If I put without quote I get the error `Wrong number of arguments: (lambda nil ...`. (I guess this is because `myfunction` is not properly defined). Hence your guess is true and the function should written without quote. – Name Sep 13 '22 at 15:21
  • Hence the real question is *what is a valid function which returns a Quail map?* *How does it look like?* – Name Sep 13 '22 at 15:23
  • Documentation is limited. You will have to read and experiment. You will find information on quail maps in `M-x find-library RET quail` (see also `C-h f quail-map-p`) and you can find what I think may be the *only* examples of a function value in `M-x find-library RET quail/japanese`. The function must accept two arguments `(key idx)` where KEY is the input string to be translated, and IDX is... unclear at first glance, but related to the key length. The examples in the quail/japanese library seem non-trivial. Have fun! – phils Sep 14 '22 at 11:04
  • After a more general search, `indian-mlm-mozhi-underscore` in quail/indian, and `ipa-x-sampa-underscore-implosive` in quail/ipa seems to be the other places where this feature is used. (I.e. In addition to `quail-japanese-switch-package` and `quail-japanese-self-insert-and-switch-to-alpha` in quail/japanese). – phils Sep 14 '22 at 13:16