eaf-proxy-function instead of eaf-dummy-function by Stefan Monnier

Rename from eaf-dummy-function since it's not dummy any more.

    Reduce the number of parameters needed in eaf-proxy-function and
    eaf-gen-keybinding-map

    Clearer eaf-bind-key documentation
master
Matthew 6 years ago
parent dc94212344
commit b6493bd1bb
  1. 50
      eaf.el

@ -7,7 +7,7 @@
;; Copyright (C) 2018, Andy Stewart, all rights reserved. ;; Copyright (C) 2018, Andy Stewart, all rights reserved.
;; Created: 2018-06-15 14:10:12 ;; Created: 2018-06-15 14:10:12
;; Version: 0.5 ;; Version: 0.5
;; Last-Updated: Wed Dec 11 04:27:17 2019 (-0500) ;; Last-Updated: Fri Dec 13 22:57:38 2019 (-0500)
;; By: Mingde (Matthew) Zeng ;; By: Mingde (Matthew) Zeng
;; URL: http://www.emacswiki.org/emacs/download/eaf.el ;; URL: http://www.emacswiki.org/emacs/download/eaf.el
;; Keywords: ;; Keywords:
@ -501,39 +501,33 @@ buffer."
(call-interactively cmd)))) (call-interactively cmd))))
(defun eaf-dummy-function (sym fun key) (defun eaf-proxy-function (fun)
"Define elisp command SYM which can call python function FUN. "Define elisp command which can call python function FUN."
(let ((sym (intern (format "eaf--proxy-%s" fun))))
FUN is only called when command SYM is not invoked by KEY." (unless (fboundp sym)
(defalias sym (lambda nil (defalias sym
(lambda nil
(interactive) (interactive)
;; ensure this is only called from EAF buffer ;; Ensure this is only called from EAF buffer
(unless (boundp 'eaf--buffer-id) (unless eaf--buffer-id
(error "%s command can only be called in an EAF buffer" sym)) (error "%s command can only be called in an EAF buffer" sym))
;; Enable the command to be called by M-x or from lisp code in (eaf-call "execute_function" eaf--buffer-id fun))
;; 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" eaf--buffer-id fun)))
(format (format
"This Lisp function is a placeholder, the actual function will be handled on the Python side. "Proxy function to call \"%s\" on the Python side.
Use `eaf-execute-app-cmd' if you want to execute this command programmatically. Use `eaf-execute-app-cmd' if you want to execute this command programmatically.
Please ONLY use `eaf-bind-key' and use the unprefixed command name (`%s`) Please ONLY use `eaf-bind-key' and use the unprefixed command name (\"%s\")
to edit EAF keybindings!" fun))) to edit EAF keybindings!" fun fun)))
sym))
(defun eaf-gen-keybinding-map (keybinding app-name) (defun eaf-gen-keybinding-map (keybinding)
"Configure the `eaf-mode-map' from KEYBINDING, one of the eaf-*-keybinding variables." "Configure the `eaf-mode-map' from KEYBINDING, one of the eaf-.*-keybinding variables."
(setq eaf-mode-map (setq eaf-mode-map
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(set-keymap-parent map eaf-mode-map*) (set-keymap-parent map eaf-mode-map*)
(cl-loop for (key . fun) in keybinding (cl-loop for (key . fun) in keybinding
do (if (symbolp fun) do (define-key map (kbd key)
(define-key map (kbd key) fun) (if (symbolp fun) fun (eaf-proxy-function fun)))
(let ((dummy (intern
(format "eaf-%s-%s" app-name fun))))
(eaf-dummy-function dummy fun key)
(define-key map (kbd key) dummy)))
finally return map)))) finally return map))))
(defun eaf-get-app-bindings (app-name) (defun eaf-get-app-bindings (app-name)
@ -542,7 +536,7 @@ to edit EAF keybindings!" fun)))
(defun eaf-create-buffer (input-content app-name) (defun eaf-create-buffer (input-content app-name)
"Create an EAF buffer given INPUT-CONTENT and APP-NAME." "Create an EAF buffer given INPUT-CONTENT and APP-NAME."
(eaf-gen-keybinding-map (eaf-get-app-bindings app-name) app-name) (eaf-gen-keybinding-map (eaf-get-app-bindings app-name))
(let* ((file-or-command-name (substring input-content (string-match "[^/]*/?$" input-content))) (let* ((file-or-command-name (substring input-content (string-match "[^/]*/?$" input-content)))
(eaf-buffer (generate-new-buffer (truncate-string-to-width file-or-command-name eaf-title-length)))) (eaf-buffer (generate-new-buffer (truncate-string-to-width file-or-command-name eaf-title-length))))
(with-current-buffer eaf-buffer (with-current-buffer eaf-buffer
@ -653,6 +647,12 @@ Use it as (eaf-setq var val)"
(defmacro eaf-bind-key (command key eaf-app-keybinding) (defmacro eaf-bind-key (command key eaf-app-keybinding)
"This function binds COMMAND to KEY in EAF-APP-KEYBINDING list. "This function binds COMMAND to KEY in EAF-APP-KEYBINDING list.
COMMAND is a command with `eaf--proxy-' prefix found by calling
`eaf-describe-bindings' in an EAF buffer, but dropping the prefix.
KEY is a string representing a sequence of keystrokes and events.
EAF-APP-KEYBINDING is one of the eaf-.*-keybinding variables. EAF-APP-KEYBINDING is one of the eaf-.*-keybinding variables.
This is used to bind key to EAF Python applications." This is used to bind key to EAF Python applications."

Loading…
Cancel
Save