emacsorphanage / key-chord

Map pairs of simultaneously pressed keys to commands
http://emacswiki.org/emacs/download/key-chord.el
116 stars 23 forks source link

Keyboard layout tolerance #4

Open Tyrn opened 1 year ago

Tyrn commented 1 year ago

Hi,

I've been trying to define some chords which should work across different keyboard layouts, something like that:

(key-chord-mode 1)
(key-chord-define-global "LL" "---~")

The above chord works on the English layout only.

(key-chord-mode 1)
(key-chord-define-global "LL" "---~")
(key-chord-define-global "ДД" "---~")

This additional chord uses the same key in Russian; doesn't appear to work, though.

I also use the "localization" package:

;; Shortcuts translation.
(use-package reverse-im
  :ensure t
  :custom
  (reverse-im-input-methods '("russian-computer"))
  :config
  (reverse-im-mode t))

I tried to comment it out experimentally, nothing apparently changed. Is there a way to make my chords "layout tolerant"?

Tyrn commented 1 year ago

Oh, I see.

;; ########   Limitations   ########################################
...
;; Emacs will not call input-method-function for keys that have non numeric
;; codes or whos code is outside the range 32..126. Thus you cannot define
;; key chords involving function keys, control keys, or even your non-english
;; letters (on national keyboards) that otherwise are well positioned for
;; chording on your keyboard.
...

No workaround whatsoever?

bravosierrasierra commented 11 months ago

i have found workaround to nonlatin layouts users

(with-eval-after-load "evil"

  (make-local-variable 'bss/move-from-insert-last-char)
  (setq-default bss/move-from-insert-last-char ??)

  (defun bss/move-from-insert (key &optional rest)
    (interactive)

    (let* (
           (line-move-visual t)
           (mycmd (format "(lambda nil (interactive) (bss/move-from-insert %s))" key))
           (prevcmd (format "%s" last-command))
           (multiplier 3)
           )
      (cond
       ((and
         (string-equal prevcmd mycmd)
         (eq bss/move-from-insert-last-char key)
         (looking-back (make-string (1- multiplier) key))
         )

        (setq this-command nil)
        (delete-backward-char (1- multiplier))
        (evil-normal-state)
        (cond
         ((member key '(?j ?о))
          (next-line multiplier))
         ((member key '(?k ?л))
          (previous-line multiplier))
         ((member key '(?l ?д))
          (forward-char multiplier))
         ((member key '(?h ?р))
          (backward-char multiplier))
         )
        )
       (t
        ;; (message "key: %s, last char: %s, last command: %s, my command: %s" key bss/move-from-insert-last-char prevcmd mycmd) 
        (insert key)
        (setq bss/move-from-insert-last-char key))
       )
      )
    )

  (define-key evil-insert-state-map (kbd "j") '(lambda () (interactive)(bss/move-from-insert ?j)))
  (define-key evil-insert-state-map (kbd "о") '(lambda () (interactive)(bss/move-from-insert ?о)))
  (define-key evil-insert-state-map (kbd "k") '(lambda () (interactive)(bss/move-from-insert ?k)))
  (define-key evil-insert-state-map (kbd "л") '(lambda () (interactive)(bss/move-from-insert ?л)))
  (define-key evil-insert-state-map (kbd "h") '(lambda () (interactive)(bss/move-from-insert ?h)))
  (define-key evil-insert-state-map (kbd "р") '(lambda () (interactive)(bss/move-from-insert ?р)))
  (define-key evil-insert-state-map (kbd "l") '(lambda () (interactive)(bss/move-from-insert ?l)))
  (define-key evil-insert-state-map (kbd "д") '(lambda () (interactive)(bss/move-from-insert ?д)))
)