Unverified Commit 52cb4783 authored by Andy Stewart's avatar Andy Stewart Committed by GitHub
Browse files

Merge pull request #115 from clemera/use-prefix-for-eaf-dummy-commands

Use prefix for eaf dummy commands
parents c3ad50ad 95f03e7f
Loading
Loading
Loading
Loading
+20 −14
Original line number Diff line number Diff line
@@ -402,8 +402,12 @@ buffer."
      (call-interactively cmd))))


(defun eaf-dummy-function (sym key)
  "Define an alias from SYM to a dummy function that acts as a placeholder."
(defun eaf-dummy-function (sym fun key)
  "Define elisp command SYM which can call python function FUN.

FUN is only called when command SYM is not invoked by KEY, thus
this command does nothing when `eaf-monitor-key-event' has
already handled it."
  (defalias sym (lambda nil
                   "This Lisp function is a placeholder, the actual function will be handled on the Python side.

@@ -414,18 +418,20 @@ Please ONLY use `eaf-bind-key' to edit EAF keybindings!"
                   (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.
                   ;; the case that this command isn't invoked by key-sequence.
                   (when (and (eq this-command sym)
                              (not (equal (this-command-keys-vector) key)))
                    (eaf-call "execute_function" buffer-id (symbol-name sym))))))
                     (eaf-call "execute_function" buffer-id fun)))))

(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) key)
                      (define-key map (kbd key) (intern fun))) map)))
                   do (let ((dummy (intern (format "eaf-%s" fun))))
                        (eaf-dummy-function dummy fun key)
                        (define-key map (kbd key) dummy))
                   finally return map))))

(defun eaf-get-app-bindings (app-name)
  (symbol-value