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" ?ܬ))

2 Answers 2

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" ?ܬ))
5
  • 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, 2022 at 6: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.
    – user31220
    Sep 13, 2022 at 6:59
  • I edited the question accordingly.
    – Name
    Sep 13, 2022 at 7: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.
    – user31220
    Sep 13, 2022 at 7:16
  • Apropos 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?
    – user31220
    Sep 13, 2022 at 7: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).

7
  • 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, 2022 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, 2022 at 13:26
  • emacs.stackexchange.com/a/5683/454 might also be useful wrt extending the rules of an existing input method.
    – phils
    Sep 13, 2022 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, 2022 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, 2022 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.