From 7c5e30772c07bc8264b787c3d96572b6bae98eff Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Sat, 7 Dec 2019 09:35:48 +0800 Subject: [PATCH] Rename keybinding variable. --- README.md | 14 +++++------ docs/KEYBINDING.md | 6 ++--- eaf.el | 59 +++++++++++++++++++--------------------------- 3 files changed, 34 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 7564fec..6c10261 100644 --- a/README.md +++ b/README.md @@ -71,10 +71,10 @@ A `use-package` sample configuration :custom (eaf-find-alternate-file-in-dired t) :config - (eaf-bind-key scroll_up "RET" eaf-pdfviewer-keybinding) - (eaf-bind-key scroll_down_page "DEL" eaf-pdfviewer-keybinding) - (eaf-bind-key scroll_up "C-n" eaf-pdfviewer-keybinding) - (eaf-bind-key scroll_down "C-p" eaf-pdfviewer-keybinding) + (eaf-bind-key scroll_up "RET" eaf-pdf-viewer-keybinding) + (eaf-bind-key scroll_down_page "DEL" eaf-pdf-viewer-keybinding) + (eaf-bind-key scroll_up "C-n" eaf-pdf-viewer-keybinding) + (eaf-bind-key scroll_down "C-p" eaf-pdf-viewer-keybinding) (eaf-bind-key take_photo "p" eaf-camera-keybinding) (defun eaf-open-google () "Open Google using EAF." @@ -139,12 +139,12 @@ There are default keybindings for each EAF application provided by us. If you wa You can easily customize EAF keybindings, find the corresponding keybinding variable, and add the something like the following to `.emacs` ```Elisp -(eaf-bind-key scroll_up "C-n" eaf-pdfviewer-keybinding) -(eaf-bind-key scroll_down "C-p" eaf-pdfviewer-keybinding) +(eaf-bind-key scroll_up "C-n" eaf-pdf-viewer-keybinding) +(eaf-bind-key scroll_down "C-p" eaf-pdf-viewer-keybinding) (eaf-bind-key take_photo "p" eaf-camera-keybinding) ``` -Currently available keybinding variables are `eaf-browser-keybinding`, `eaf-pdfviewer-keybinding`, `eaf-videoplayer-keybinding`, `eaf-imageviewer-keybinding`, `eaf-camera-keybinding`, `eaf-terminal-keybinding`. +Currently available keybinding variables are `eaf-browser-keybinding`, `eaf-pdf-viewer-keybinding`, `eaf-video-player-keybinding`, `eaf-image-viewer-keybinding`, `eaf-camera-keybinding`, `eaf-terminal-keybinding`. ### Variable Customization There are certain variables will be shared across Emacs Lisp and Python. You can easily configure then with `eaf-setq`. diff --git a/docs/KEYBINDING.md b/docs/KEYBINDING.md index 9e241c5..0da1109 100644 --- a/docs/KEYBINDING.md +++ b/docs/KEYBINDING.md @@ -43,7 +43,7 @@ You can customize keys with option ```eaf-browser-keybinding``` or ```eaf-browse | i | Toggle inverted mode | | Double Click | Use sdcv translate word under point | -You can customize keys with option ```eaf-pdfviewer-keybinding``` +You can customize keys with option ```eaf-pdf-viewer-keybinding``` ### Video Player @@ -53,7 +53,7 @@ You can customize keys with option ```eaf-pdfviewer-keybinding``` | h | Seek backward | | l | Seek forward | -You can customize keys with option ```eaf-videoplayer-keybinding``` +You can customize keys with option ```eaf-video-player-keybinding``` ### Image Viewer @@ -62,7 +62,7 @@ You can customize keys with option ```eaf-videoplayer-keybinding``` | j | Load next image in current directory | | k | Load previous image in current directory | -You can customize keys with option ```eaf-imageviewer-keybinding``` +You can customize keys with option ```eaf-image-viewer-keybinding``` ### Terminal diff --git a/eaf.el b/eaf.el index edd5dd5..0e55d51 100644 --- a/eaf.el +++ b/eaf.el @@ -181,7 +181,7 @@ Try not to modify this alist directly. Use `eaf-setq' to modify instead." :type 'cons :group 'eaf) -(defcustom eaf-pdfviewer-keybinding +(defcustom eaf-pdf-viewer-keybinding '(("j" . "scroll_up") ("k" . "scroll_down") ("SPC" . "scroll_up_page") @@ -201,7 +201,7 @@ Try not to modify this alist directly. Use `eaf-setq' to modify instead." :type 'cons :group 'eaf) -(defcustom eaf-videoplayer-keybinding +(defcustom eaf-video-player-keybinding '(("SPC" . "toggle_play") ("h" . "play_backward") ("l" . "play_forward")) @@ -209,7 +209,7 @@ Try not to modify this alist directly. Use `eaf-setq' to modify instead." :type 'cons :group 'eaf) -(defcustom eaf-imageviewer-keybinding +(defcustom eaf-image-viewer-keybinding '(("j" . "load_next_image") ("k" . "load_prev_image")) "The keybinding of EAF Image Viewer." @@ -265,6 +265,18 @@ Try not to modify this alist directly. Use `eaf-setq' to modify instead." :type 'cons :group 'eaf) +(defvar eaf-app-binding-alist + '(("browser" . eaf-browser-keybinding) + ("pdf-viewer" . eaf-pdf-viewer-keybinding) + ("video-player" . eaf-video-player-keybinding) + ("image-viewer" . eaf-image-viewer-keybinding) + ("camera" . eaf-camera-keybinding) + ("terminal" . eaf-terminal-keybinding)) + "Mapping app names to keybinding variables. + +Any new app should add the its name and the corresponding +keybinding variable to this list.") + (defun eaf-call (method &rest args) (apply 'dbus-call-method :session ; use the session (not system) bus @@ -383,20 +395,13 @@ Please ONLY use `eaf-bind-key' to edit EAF keybindings!" do (eaf-dummy-function (intern fun)) (define-key map (kbd key) (intern fun))) map))) +(defun eaf-get-app-bindings (app-name) + (symbol-value + (cdr (assoc app-name eaf-app-binding-alist)))) + (defun eaf-create-buffer (input-content app-name) "Create an EAF buffer given INPUT-CONTENT and APP-NAME." - (cond ((equal app-name "browser") - (eaf-gen-keybinding-map eaf-browser-keybinding)) - ((equal app-name "pdf-viewer") - (eaf-gen-keybinding-map eaf-pdfviewer-keybinding)) - ((equal app-name "video-player") - (eaf-gen-keybinding-map eaf-videoplayer-keybinding)) - ((equal app-name "image-viewer") - (eaf-gen-keybinding-map eaf-imageviewer-keybinding)) - ((equal app-name "camera") - (eaf-gen-keybinding-map eaf-camera-keybinding)) - ((equal app-name "terminal") - (eaf-gen-keybinding-map eaf-terminal-keybinding))) + (eaf-gen-keybinding-map (eaf-get-app-bindings app-name)) (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)))) (with-current-buffer eaf-buffer @@ -405,18 +410,7 @@ Please ONLY use `eaf-bind-key' to edit EAF keybindings!" (defun eaf-identify-key-in-app (key-command app-name) "Given a KEY-COMMAND string, identify whether command is in EAF keybindings based on APP-NAME." - (cond ((equal app-name "browser") - (rassoc key-command eaf-browser-keybinding)) - ((equal app-name "pdf-viewer") - (rassoc key-command eaf-pdfviewer-keybinding)) - ((equal app-name "video-player") - (rassoc key-command eaf-videoplayer-keybinding)) - ((equal app-name "image-viewer") - (rassoc key-command eaf-imageviewer-keybinding)) - ((equal app-name "camera") - (rassoc key-command eaf-camera-keybinding)) - ((equal app-name "terminal") - (rassoc key-command eaf-terminal-keybinding)))) + (rassoc key-command (eaf-get-app-bindings app-name))) (defun eaf-is-support (url) (dbus-call-method @@ -535,14 +529,9 @@ Please ONLY use `eaf-bind-key' to edit EAF keybindings!" (let ((function-name-value (cdr (assoc key-desc eaf-browser-keybinding)))) (when function-name-value (eaf-call "execute_function" buffer-id function-name-value)))) - ((equal buffer-app-name "pdf-viewer") - (eaf-handle-app-key buffer-id key-desc eaf-pdfviewer-keybinding)) - ((equal buffer-app-name "video-player") - (eaf-handle-app-key buffer-id key-desc eaf-videoplayer-keybinding)) - ((equal buffer-app-name "image-viewer") - (eaf-handle-app-key buffer-id key-desc eaf-imageviewer-keybinding)) - ((equal buffer-app-name "camera") - (eaf-handle-app-key buffer-id key-desc eaf-camera-keybinding)) + ((assoc buffer-app-name eaf-app-binding-alist) + (eaf-handle-app-key buffer-id key-desc + (eaf-get-app-bindings buffer-app-name))) (t (eaf-call "send_key" buffer-id key-desc)))) ((or