Invoke eaf-monitor-key-event from dummy command if needed

master
Clemens Radermacher 6 years ago
parent 96c4a7dbb1
commit f848556e6f
No known key found for this signature in database
GPG Key ID: ADEDCAC15E317EA0
  1. 24
      eaf.el

@ -392,20 +392,31 @@ We need calcuate render allocation to make sure no black border around render co
(random (expt 16 4))))
(defun eaf-dummy-function (sym)
(defun eaf-dummy-function (sym key)
"Define an alias from SYM to a dummy function that acts as a placeholder."
(defalias sym (lambda nil
"This Lisp function is a placeholder, the actual function will be handled on the Python side.
Use `eaf-execute-app-cmd' if you want to execute this command programmatically.
Please ONLY use `eaf-bind-key' to edit EAF keybindings!"
(interactive)
)))
;; ensure this is only called from eaf buffer
(unless (boundp 'buffer-id)
(error "%s command can only be called in eaf buffer" sym))
;; enable the command to be called by M-x or from lisp code in
;; the case that this command is invoked by key-sequence
;; `eaf-monitor-key-event' is already executed by
;; `pre-command-hook'
(when (and (eq this-command sym)
(not (equal (this-command-keys-vector) key)))
(eaf-monitor-key-event (symbol-name sym))))))
(defun eaf-gen-keybinding-map (keybinding)
"Configure the eaf-mode-map from KEYBINDING, one of the eaf-*-keybinding variables."
(setq eaf-mode-map
(let ((map (make-sparse-keymap)))
(cl-loop for (key . fun) in keybinding
do (eaf-dummy-function (intern fun))
do (eaf-dummy-function (intern fun) key)
(define-key map (kbd key) (intern fun))) map)))
(defun eaf-get-app-bindings (app-name)
@ -507,11 +518,12 @@ Please ONLY use `eaf-bind-key' to edit EAF keybindings!"
(eaf-call "update_buffer_with_url" "app.orgpreviewer.buffer" (buffer-file-name) "")
(message (format "export %s to html" (buffer-file-name))))))))
(defun eaf-monitor-key-event ()
(defun eaf-monitor-key-event (&optional cmd-name)
"Monitor key events during EAF process."
(ignore-errors
(let* ((key (this-command-keys-vector))
(key-command (symbol-name (key-binding key)))
(key-command (or cmd-name
(symbol-name (key-binding key))))
(key-desc (key-description key)))
;; Uncomment for debug.
@ -523,7 +535,9 @@ Please ONLY use `eaf-bind-key' to edit EAF keybindings!"
t)
;; Call function on the Python side if matched key in the keybinding.
((eaf-identify-key-in-app key-command buffer-app-name)
(eaf-call "execute_function" buffer-id (cdr (assoc key-desc (eaf-get-app-bindings buffer-app-name)))))
(eaf-call "execute_function" buffer-id
(or cmd-name
(cdr (assoc key-desc (eaf-get-app-bindings buffer-app-name))))))
;; Send key to Python side if key-command is single character key.
((or (equal key-command "self-insert-command")
(equal key-command "completion-select-if-within-overlay")

Loading…
Cancel
Save