1

I'm checking out quail (set-input-method) to write some LaTeX snippets (I felt it had some advantages over the others snippet options such as yas-snippets).

According to the manual:

quail-define-rules is an autoloaded Lisp macro in ‘quail.el’.

(quail-define-rules &rest RULES)

Define translation rules of the current Quail package. 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.


Problem; I cannot implement function on the TRANSLATION.

The following is my example script:

(require 'quail)

(quail-define-package
 "Test-Latex" "Test-Latex"  "tltx-" t
 "Test-Latex Keyboard Layout"
 nil t t t t nil nil nil nil nil t)

(quail-define-rules
 ("x"   "A" )                                     ;; <======== char works  
 ("a."  ["\\alpha"])                              ;; <======== string works
 ("al"  ["\\begin{align}\n\n\\end{align}"])       ;; <======== string works  
 ("eq"  ["\\begin{equation}\n\n\\end{equation}"]) ;; <======== string works
 ("Eq" (lambda ()                                 ;; <======== function NOT WORKS
     (interactive)
     (insert "\\begin{equation}\n\n\\end{equation}")
     (previous-line)
     ))
 )

Question; How to implement function on the TRANSLATION in quail-define-rules

0

2 Answers 2

1

If you keep reading...

If TRANSLATION is a Quail map or a function symbol which returns a Quail map, it is used to handle KEY.

You were passing a lambda form instead of a symbol. You need to define a named function and supply its symbol. Furthermore:

... a function symbol which returns a Quail map

Which isn't what your attempt is doing.

Below are my comments from https://emacs.stackexchange.com/a/73592/454 :


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.


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-hf 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!


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).

1
  • Thanks for directing into right part of code to seek. I think I've figured it out. THANKS !!
    – Garid
    Commented Apr 9, 2023 at 14:29
1

As @phils pointed out the list of files/function that used this functionality.

From them I used quail-japanese-switch-package in quail/japanese as my reference. And following function work somehow (TBH, not sure why it's working)

(require 'quail)

;;;;;;;;;;; this the new function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun quail-equation-test (key idx)    ; key=keyword, idx=length

  (quail-delete-region)                 ; these lines apparently needed   
  (setq quail-current-str nil           ; to remove key.
        quail-converting nil            ; (not sure why all 4 is needed)
        quail-conversion-str "")        ;


  (insert "\\begin{equation}\n\n\\end{equation}")
  (previous-line)

  (throw 'quail-tag nil)                ; this is need for finishing up?
  ) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(quail-define-package
 "Test-Latex" "Test-Latex"  "tltx-" t
 "Test-Latex Keyboard Layout"
 nil t t t t nil nil nil nil nil t)

(quail-define-rules
 ("x"   "A" )                                     ;; <======== char works  
 ("a."  ["\\alpha"])                              ;; <======== string works
 ("al"  ["\\begin{align}\n\n\\end{align}"])       ;; <======== string works  
 ("eq"  ["\\begin{equation}\n\n\\end{equation}"]) ;; <======== string works
 ("Eq"  quail-equation-test)                      ;; <======== function WORKS
 )

From my observations:

It seems first 4 lines in the function removes the keyword (in this case Eq)fully.

  (quail-delete-region)                 ; these lines apparently needed   
  (setq quail-current-str nil           ; to remove key.
        quail-converting nil            ; (not sure why all 4 is needed)
        quail-conversion-str "")        ;

Without last line, quail doesn't work correctly after the quail-equation-test executed. Perhaps, it's something related to finishing up the state of quail

  (throw 'quail-tag nil)                ; this is need for finishing up?

Your Answer

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

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