auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX-devel] non latin alphabet based languages input method and l


From: Ikumi Keita
Subject: Re: [AUCTeX-devel] non latin alphabet based languages input method and latex
Date: Fri, 10 Nov 2017 03:12:26 +0900

> I tried the following
> (defvar keyboard-maniac-fill-mode nil)
> (make-variable-buffer-local 'keyboard-maniac-fill-mode) 

> (defun my-test-hebrew ()
>   (interactive)
>   (if (texmathp)
>       (toggle-input-method nil 1)
>       (message "We are in math toogle input method")))

> (defun my-test-nohbrew ()
> (interactive)
>  (if (not (texmathp))
>      (set-input-method "hebrew-phonetic-qwerty" t)
>          (message "Switched from default to hebrew keyboard")))



> ;; Call keyboard-maniac fill after each command.
> (add-hook 'post-command-hook 'my-test-hebrew)
> (add-hook 'post-command-hook 'my-test-nohebrew)
> ;; (remove-hook 'post-command-hook 'my-test-nohebrew)
> ;; (remove-hook 'post-command-hook 'my-test-hebrew)

> ;; Add to mode line.
> (or (assq 'keyboard-maniac-fill-mode minor-mode-alist)
>     (setq minor-mode-alist
>         (cons '(keyboard-maniac-fill-mode (" Keyb-Maniac"))
>               minor-mode-alist)))

> ;;;###autoload
> (defun keyboard-maniac-fill-mode (&optional arg)
>   "Toggle keyboard-maniac fill mode.
> With prefix arg, turn keyboard-maniac fill mode on iff arg is positive.

> When keyboard-maniac fill mode is on, the current paragraph will be formatted
> after each command."
>   (interactive "P")
>   (setq keyboard-maniac-fill-mode (not (or (and (null arg) 
> keyboard-maniac-fill-mode)
>                                 (<= (prefix-numeric-value arg) 0))))
>   (set-buffer-modified-p (buffer-modified-p)))

> (provide 'keyboard-maniac)

> ;;; keyboard-maniac.el ends here


> Based on an old code from Peer Abrahamsen,
> the hook 
> (add-hook 'post-command-hook 'my-test-hebrew)
> is very problematic.

Of course it is.  The function `toggle-input-method', as its name
manifests, turns on and off the input method alternatively each time it
is called.  Since your function `my-test-hebrew' calls
`toggle-input-method' outside math formula, `post-command-hook' toggles
on and off the input method every time you type a key if you do
(add-hook 'post-command-hook 'my-test-hebrew)
.

Part of what you want to do will be achieved by arranging the variable
`TeX-math-input-method-off-regexp' to hold a regexp matching
"hebrew-phonetic-qwerty" or whatever the name of the input method you
are going to use.  Then typing "$" at position of non-math formula or
inserting math environment such as "equation" via C-c C-e will turns off
the input method.

The prescription described above only works when you enter a "new" math
expression with "$" or C-c C-e.  If you adhere to the idea that the
input method is arranged always according to the value that `(texmathp)'
returns, then `my-test-hebrew' and `my-test-nohbrew' should be defined
as
(defun my-test-hebrew ()
  (interactive)
  (when (texmathp)
    (deactivate-input-method)
    (message "We are in math toogle input method")))

(defun my-test-nohbrew ()
  (interactive)
  (when (not (texmathp))
    (set-input-method "hebrew-phonetic-qwerty" t)
    (message "Switched from default to hebrew keyboard")))
, respectively.  (Notice also that `if' is replaced with `when' because
the syntax of `if' is:
(if CONDITION
    WHAT-TO-BE-DONE-IF-CONDITION-IS-TRUE
  WHAT-TO-BE-DONE-IF-CONDITION-IS-FALSE)
.  With your definition, `message' is called when the respective
condition is NOT met.)

It seems that these functions have nothing to do with
`keyboard-maniac-fill-mode', but that's a different story.

Best,
Ikumi Keita



reply via email to

[Prev in Thread] Current Thread [Next in Thread]