From 5b9612f57e7f3e44402ddc19912d95328120ee01 Mon Sep 17 00:00:00 2001 From: Daniel Nicolai Date: Mon, 11 Jan 2021 20:15:51 +0100 Subject: [PATCH] Add Emacs Application Framework (EAF) layer --- CHANGELOG.develop | 1 + layers/+tools/eaf/README.org | 92 ++++++++++++++ layers/+tools/eaf/funcs.el | 37 ++++++ layers/+tools/eaf/packages.el | 232 ++++++++++++++++++++++++++++++++++ layers/LAYERS.org | 11 ++ private/README.md | 21 --- private/local/README.md | 35 ----- private/snippets/README.md | 6 - private/templates/README.md | 6 - 9 files changed, 373 insertions(+), 68 deletions(-) create mode 100644 layers/+tools/eaf/README.org create mode 100644 layers/+tools/eaf/funcs.el create mode 100644 layers/+tools/eaf/packages.el delete mode 100644 private/README.md delete mode 100644 private/local/README.md delete mode 100644 private/snippets/README.md delete mode 100644 private/templates/README.md diff --git a/CHANGELOG.develop b/CHANGELOG.develop index 4d8ff2ea0..e6d05439d 100644 --- a/CHANGELOG.develop +++ b/CHANGELOG.develop @@ -428,6 +428,7 @@ In org-agenda-mode - dap (thanks to Ivan Yonchovski) - debug (thanks to Hodge Shen, Troy Hinckley, and Sylvain Benner) - dotnet (thanks to Jordan Kaye) +- eaf (thanks to Daniel Nicolai) - import-js (thanks to Thanh Vuong and Seong Yong-ju) - kubernetes with tramp support (thanks to Matt Bray and Maximilian Wolff) - languagetool (thanks to Robbert van der Helm) diff --git a/layers/+tools/eaf/README.org b/layers/+tools/eaf/README.org new file mode 100644 index 000000000..2200478b4 --- /dev/null +++ b/layers/+tools/eaf/README.org @@ -0,0 +1,92 @@ +#+TITLE: eaf layer + +#+TAGS: layer|web service + +# The maximum height of the logo should be 200 pixels. +# [[img/eaf.png]] + +* Table of Contents :TOC_4_gh:noexport: +- [[#description][Description]] + - [[#features][Features:]] +- [[#install][Install]] +- [[#usage][Usage]] + - [[#configuring-keybindings][Configuring keybindings]] +- [[#key-bindings][Key bindings]] + - [[#global][Global]] + - [[#all-eaf-applications][All EAF-applications]] + - [[#browser][Browser]] + - [[#local][Local]] + - [[#all-eaf-applications-1][All EAF-applications]] + - [[#browser-1][Browser]] + - [[#pdf-viewer][PDF-viewer]] + - [[#pdf-view-mode-pdf-tools][pdf-view-mode (pdf-tools)]] + +* Description + This layer adds support for the [[https://github.com/manateelazycat/emacs-application-framework][Emacs Application Framework (EAF)]]. + +** Features: + - Browse using a full-fledged browser within Emacs + - PDF viewer (with continuous scroll) + - Video player + - Image viewer + - See [[https://github.com/manateelazycat/emacs-application-framework#launch-eaf-applications][EAF documentation]] for many more features + +* Install + To use this configuration layer, add it to your =~/.spacemacs=. You will need to + add =eaf= to the existing =dotspacemacs-configuration-layers= list in this + file. + + Subsequently install the required dependencies with =SPC SPC + eaf-install-dependencies=. This command only works for Ubuntu and Fedora based + distributions. Users of Arch (based) distributions can run the script manually + in their terminal. If the script does not work for you then [[https://github.com/manateelazycat/emacs-application-framework#dependency-list][install the + required dependencies manually]]. + +* Usage + +** Configuring keybindings + Configuration of EAF keybindings works in a different way than normally in Spacemacs. + + Also EAF, and additionally this layer, implement some tricks that are + required to make leader keys in EAF buffers behave as expected in Spacemacs. + Therefore it is recommended to keep these default (major-mode-)leader + keybindings. + + For information about configuration of other key bindings for EAF, see [[https://github.com/manateelazycat/emacs-application-framework/wiki/Keybindings][here]]. + + If you do want to modify the leader keys, then information about the tricks + implemented in this layer can be found [[https://github.com/manateelazycat/emacs-application-framework/issues/498][here]] and [[https://github.com/manateelazycat/emacs-application-framework/pull/500][here]]. + +* Key bindings + +** Global +*** All EAF-applications +| Key Binding | Description | +|-------------+-----------------------------------------------------------------------| +| ~SPC a a f~ | EAF open file ([[https://github.com/manateelazycat/emacs-application-framework#launch-eaf-applications][see EAF doc for suppoted file types]]) | +| ~SPC t k m~ | Show available key commands in which-key (read [[https://develop.spacemacs.org/doc/DOCUMENTATION.html#which-key][here]] for more details) | +| ~, d~ | toggle dark-mode (in pdf-viewer just press ~d~) | +*** Browser +| ~SPC a a b o~ | Open url in new buffer | +| ~SPC a a b s~ | Search with [[https://github.com/manateelazycat/emacs-application-framework/wiki/Customization#default-search-engine][your favorite search engine]]. Defaults to symbol at point or region string | +| ~SPC a a b b~ | Open bookmark in new buffer | +| ~SPC a a b h~ | Search and open buffer from history | +** Local +*** All EAF-applications +| ~j/k~ | Scroll up/down | +*** Browser +|-------+----------------------------------------------------------------| +| ~J/K~ | Scroll (half) page up/down | +| ~e~ | Edit url | +| ~m~ | Bookmark page | +| ~C-s~ | Search/search find next (to enter new search prefix with ~C-g~ | +| ~C-r~ | Search find previous | +| ~, h~ | Open new buffer from history | +| ~, s~ | Search web with [[https://github.com/manateelazycat/emacs-application-framework/wiki/Customization#default-search-engine][favorite search engine]] | +*** PDF-viewer +| ~d~ | toggle dark-mode | +*** pdf-view-mode (pdf-tools) +| ~, e~ | open in eaf pdf-viewer | + +There are many more keybindings. Use ~SPC t k m~ to [[https://develop.spacemacs.org/doc/DOCUMENTATION.html#which-key-persistent][show them persistently in +which-key]], or use ~SPC h d k~ to show the `eaf-mode-map` in a separate buffer. diff --git a/layers/+tools/eaf/funcs.el b/layers/+tools/eaf/funcs.el new file mode 100644 index 000000000..d97b506b8 --- /dev/null +++ b/layers/+tools/eaf/funcs.el @@ -0,0 +1,37 @@ +(defun duckduckgo () + (interactive) + (eaf-open-browser "www.duckduckgo.com")) +(defun wikipedia () + (interactive) + (eaf-open-browser "www.wikipedia.com")) +(defun youtube () + (interactive) + (eaf-open-browser "www.youtube.com")) + +(defun eaf-toggle-dark-mode () + (interactive) + (if (not (eq major-mode 'eaf-mode)) + (message "Not in eaf-mode buffer") + (let* ((app-name eaf--buffer-app-name) + (app-dark-mode + (intern + (format "eaf-%s-dark-mode" + (if (string= app-name "pdf-viewer") + "pdf" + app-name)))) + (current-state (cdr (assoc app-dark-mode eaf-var-list)))) + (let ((browser (string= app-name "browser"))) + (cond ((member current-state '("true" "follow" "ignore")) + (eaf-set app-dark-mode "false") + (when browser + (eaf-proxy-refresh_page))) + (t + (eaf-set app-dark-mode "true") + (when browser + (eaf-proxy-insert_or_dark_mode)))) + (when (not browser) + (eaf-restart-process)))))) + +(defun spacemacs/open-with-eaf () + (interactive) + (eaf-open (buffer-file-name))) diff --git a/layers/+tools/eaf/packages.el b/layers/+tools/eaf/packages.el new file mode 100644 index 000000000..4b09c5179 --- /dev/null +++ b/layers/+tools/eaf/packages.el @@ -0,0 +1,232 @@ +;;; packages.el --- eaf layer packages file for Spacemacs. +;; +;; Copyright (c) 2012-2020 Sylvain Benner & Contributors +;; +;; Author: Daniel Nicolai +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + +(defconst eaf-packages + '((eaf :location (recipe + :fetcher github + :repo "manateelazycat/emacs-application-framework" + :files ("*"))))) + +(defun eaf/init-eaf () + (use-package eaf + :defer t + + :init + (spacemacs/declare-prefix "aa" "application-framework") + (spacemacs/set-leader-keys "aac" 'eaf-camera) + (spacemacs/set-leader-keys "aaf" 'eaf-open) + (spacemacs/set-leader-keys "aaf" 'eaf-open) + (spacemacs/set-leader-keys "aaj" 'eaf-open-jupyter) + (spacemacs/set-leader-keys "aao" 'eaf-open-office) + (spacemacs/set-leader-keys "aat" 'eaf-open-terminal) + + (spacemacs/declare-prefix "aab" "browser") + (spacemacs/set-leader-keys "aabo" 'eaf-open-browser) + (spacemacs/set-leader-keys "aabs" 'eaf-search-it) + (spacemacs/set-leader-keys "aabb" 'eaf-open-bookmark) + (spacemacs/set-leader-keys "aabh" 'eaf-open-browser-with-history) + + (spacemacs/declare-prefix "aabq" "quick-launch-website") + (spacemacs/set-leader-keys "aabqd" 'duckduckgo) + (spacemacs/set-leader-keys "aabqw" 'wikipedia) + (spacemacs/set-leader-keys "aabqy" 'youtube) + + (spacemacs/declare-prefix "aam" "mindmap") + (spacemacs/set-leader-keys "aamc" 'eaf-create-mindmap) + (spacemacs/set-leader-keys "aamm" 'eaf-open-mindmap) + + (setq eaf-browser-keybinding + '(("C--" . "zoom_out") + ("C-=" . "zoom_in") + ("C-0" . "zoom_reset") + ("C-s" . "search_text_forward") + ("C-r" . "search_text_backward") + ("C-n" . "scroll_up") + ("C-p" . "scroll_down") + ("C-f" . "scroll_right") + ("C-b" . "scroll_left") + ("C-v" . "scroll_up_page") + ("C-y" . "yank_text") + ("C-w" . "kill_text") + ("M-e" . "atomic_edit") + ("M-c" . "caret_toggle_browsing") + ("M-D" . "select_text") + ("M-s" . "open_link") + ("M-S" . "open_link_new_buffer") + ("M-d" . "open_link_background_buffer") + ("C-/" . "undo_action") + ("M-_" . "redo_action") + ("M-w" . "copy_text") + ("M-f" . "history_forward") + ("M-b" . "history_backward") + ("M-q" . "clear_cookies") + ("C-t" . "toggle_password_autofill") + ("C-d" . "save_page_password") + ("M-a" . "toggle_adblocker") + ("C-M-q" . "clear_history") + ("C-M-i" . "import_chrome_history") + ("M-v" . "scroll_down_page") + ("M-<" . "scroll_to_begin") + ("M->" . "scroll_to_bottom") + ("M-p" . "duplicate_page") + ("M-t" . "new_blank_page") + ("<" . "insert_or_select_left_tab") + (">" . "insert_or_select_right_tab") + ("j" . "insert_or_scroll_up") + ("k" . "insert_or_scroll_down") + ("h" . "insert_or_scroll_left") + ("l" . "insert_or_scroll_right") + ("f" . "insert_or_open_link") + ("F" . "insert_or_open_link_new_buffer") + ("B" . "insert_or_open_link_background_buffer") + ("c" . "insert_or_caret_at_line") + ("J" . "insert_or_scroll_up_page") + ("K" . "insert_or_scroll_down_page") + ("H" . "insert_or_history_backward") + ("L" . "insert_or_history_forward") + ("t" . "insert_or_new_blank_page") + ("T" . "insert_or_recover_prev_close_page") + ("i" . "insert_or_focus_input") + ("I" . "insert_or_open_downloads_setting") + ("r" . "insert_or_refresh_page") + ("g" . "insert_or_scroll_to_begin") + ("x" . "insert_or_close_buffer") + ("G" . "insert_or_scroll_to_bottom") + ("-" . "insert_or_zoom_out") + ("=" . "insert_or_zoom_in") + ("0" . "insert_or_zoom_reset") + ("d" . "insert_or_dark_mode") + ("m" . "insert_or_save_as_bookmark") + ("o" . "insert_or_open_browser") + ;; ("y" . "insert_or_download_youtube_video") + ("y" . "insert_or_copy_text") + ("Y" . "insert_or_download_youtube_audio") + ("p" . "insert_or_toggle_device") + ("P" . "insert_or_duplicate_page") + ("1" . "insert_or_save_as_pdf") + ("2" . "insert_or_save_as_single_file") + ("v" . "insert_or_view_source") + ("e" . "insert_or_edit_url") + ("M-C" . "copy_code") + ("C-M-f" . "copy_link") + ("C-a" . "select_all_or_input_text") + ("M-u" . "clear_focus") + ("C-j" . "open_downloads_setting") + ("M-o" . "eval_js") + ("M-O" . "eval_js_file") + ("" . "eaf-browser-send-esc-or-exit-fullscreen") + ("M-," . "eaf-send-down-key") + ("M-." . "eaf-send-up-key") + ("M-m" . "eaf-send-return-key") + ("" . "refresh_page") + ("" . "open_devtools") + ("" . "eaf-send-ctrl-return-sequence") + )) + + (setq eaf-pdf-viewer-keybinding + '(("j" . "scroll_up") + ("" . "scroll_up") + ("C-n" . "scroll_up") + ("k" . "scroll_down") + ("" . "scroll_down") + ("C-p" . "scroll_down") + ("h" . "scroll_left") + ("" . "scroll_left") + ("C-b" . "scroll_left") + ("l" . "scroll_right") + ("" . "scroll_right") + ("C-f" . "scroll_right") + ("J" . "scroll_up_page") + ("K" . "scroll_down_page") + ("C-v" . "scroll_up_page") + ("M-v" . "scroll_down_page") + ("t" . "toggle_read_mode") + ("0" . "zoom_reset") + ("=" . "zoom_in") + ("-" . "zoom_out") + ("g" . "scroll_to_begin") + ("G" . "scroll_to_end") + ("p" . "jump_to_page") + ("P" . "jump_to_percent") + ("[" . "save_current_pos") + ("]" . "jump_to_saved_pos") + ("i" . "toggle_inverted_mode") + ("m" . "toggle_mark_link") + ("f" . "jump_to_link") + ("d" . "toggle_inverted_mode") + ("M-w" . "copy_select") + ("C-s" . "search_text_forward") + ("C-r" . "search_text_backward") + ("x" . "close_buffer") + ("C-" . "rotate_clockwise") + ("C-" . "rotate_counterclockwise") + ("M-h" . "add_annot_highlight") + ("M-u" . "add_annot_underline") + ("M-s" . "add_annot_squiggly") + ("M-d" . "add_annot_strikeout_or_delete_annot") + ("M-e" . "add_annot_text_or_edit_annot") + ("M-p" . "toggle_presentation_mode") + ("o" . "eaf-pdf-outline") + ;; switch tab only works with awesome-tab package + ;; ("" . "select_left_tab") + ;; ("" . "select_right_tab") + )) + + + :config + (setq browse-url-browser-function 'eaf-open-browser) + (eaf-setq eaf-browser-enable-adblocker "true") + + (define-key eaf-mode-map* (kbd "C-SPC C-SPC") 'counsel-M-x) + + (spacemacs/set-leader-keys-for-major-mode 'pdf-view-mode "E" 'spacemacs/open-with-eaf) + (add-to-list 'evil-evilified-state-modes 'eaf-pdf-outline-mode)) + +; remove compiled file necessary to suppress clear_focus variable non-existent +; error (eaf is not yet meant to be installed with quelpa, see +; `https://github.com/manateelazycat/emacs-application-framework#install') + +; Alternative way to delete compiled file +;; (when (locate-library "eaf-evil.elc") +;; (delete-file)) + + (use-package eaf-evil + :after eaf + :config + (setq eaf-evil-leader-keymap spacemacs-cmds) + + (define-key key-translation-map (kbd "SPC") + (lambda (prompt) + (if (derived-mode-p 'eaf-mode) + (if (and (string= eaf--buffer-app-name "browser") + (eaf-call "call_function" eaf--buffer-id "is_focus")) + (kbd "SPC") + (kbd "C-SPC"))))) + + (setq eaf-evil-leader-for-major-keymap (make-sparse-keymap)) + (define-key eaf-evil-leader-for-major-keymap (kbd "h") 'eaf-open-browser-with-history) + (define-key eaf-evil-leader-for-major-keymap (kbd "d") 'eaf-toggle-dark-mode) + (define-key eaf-evil-leader-for-major-keymap (kbd "s") 'eaf-search-it) + (add-hook 'evil-normal-state-entry-hook + (lambda () + (when (derived-mode-p 'eaf-mode) + (define-key eaf-mode-map (kbd "C-,") eaf-evil-leader-for-major-keymap) + ;; (setq emulation-mode-map-alists + ;; (delq 'evil-mode-map-alist emulation-mode-map-alists)) + ))) + + (define-key key-translation-map (kbd ",") + (lambda (prompt) + (if (derived-mode-p 'eaf-mode) + (if (and (string= eaf--buffer-app-name "browser") + (eaf-call "call_function" eaf--buffer-id "is_focus")) + (kbd ",") + (kbd "C-,"))))))) diff --git a/layers/LAYERS.org b/layers/LAYERS.org index 45a7ed4b9..5461d047e 100644 --- a/layers/LAYERS.org +++ b/layers/LAYERS.org @@ -214,6 +214,7 @@ - [[#dap][DAP]] - [[#debug][Debug]] - [[#docker][Docker]] + - [[#eaf-emacs-application-layer][EAF (Emacs Application Layer)]] - [[#fasd][Fasd]] - [[#finance][Finance]] - [[#geolocation][Geolocation]] @@ -2773,6 +2774,16 @@ Features: - Syntax checking via [[https://github.com/hadolint/hadolint][hadolint]] - Code-Completion via =lsp= +** EAF (Emacs Application Layer) +[[file:+tools/eaf/README.org][+tools/eaf/README.org]] + +This layer integrates the [[https://github.com/clvv/fasd][fasd]] command line tool into Spacemacs. + +Features: +- Adds easy shortcuts to reference recent files and directories. +- Provides =fasd= with recent open file lists from Emacs. +- Allows to filter =fasd= results with =helm= or =ivy=. + ** Fasd [[file:+tools/fasd/README.org][+tools/fasd/README.org]] diff --git a/private/README.md b/private/README.md deleted file mode 100644 index f6aaf9940..000000000 --- a/private/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Private directory - -The content of this directory is ignored by Git. This is the default place -where to store your private configuration layers. - -To create a new configuration layer: - - SPC SPC configuration-layer/create-layer RET - -Then enter the name of your configuration in the prompt. - -A directory named after the created configuration layer will be created here -along with template files within it (packages.el and extensions.el, more info -on the meaning of those files can be found in the [documentation][conf_layers]). - -Each created file has further guidance written in them. - -Once the configuration is done, restart Emacs to load, install and configure -your layer. - -[conf_layers]: https://github.com/syl20bnr/spacemacs/blob/master/doc/DOCUMENTATION.org#extensions-and-packages diff --git a/private/local/README.md b/private/local/README.md deleted file mode 100644 index 87dc0e8f6..000000000 --- a/private/local/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Private directory for local packages - -The content of this directory is ignored by Git. - -This is the place to store the local packages that you define in the -`dotspacemacs-additional-packages` variable of your dotfile. - -Additional packages can be added using the same recipe as for [adding packages -to layers](https://develop.spacemacs.org/doc/LAYERS.html#packagesel) i.e.: - -- For a local package: - - Load the file explicitly, using the full path to the file, by placing a - `(load "~/.emacs.d/private/local/package-name")` within the body of the - `dotspacemacs/user-config` function of your dotspacemacs file. - - Alternatively create a directory with the name of the package in the - `.emacs.d/private/local` directory, and add that directory to the load-path - variable by adding `(some-package :location local)` to the list - `dotspacemacs-additional-packages` within the `dotspacemacs/layers` function - of your dotspacemacs file. After placing your package file into this - package-directory the file can be loaded, without requiring the full path, by - placing a `(require 'package-name)` within the body of the - `dotspacemacs/user-config` function of your dotspacemacs file. - -- If the package is on (M)ELPA simply add the package name to the list - `dotspacemacs-additional-packages` in your dotspacemacs file - -- For a package hosted on github the recipe for github packages can be used i.e. add - -``` -(some-package :location (recipe - :fetcher github - :repo "some/repo")) -``` - -to the list `dotspacemacs-additional-packages` in your dotspacemacs file. diff --git a/private/snippets/README.md b/private/snippets/README.md deleted file mode 100644 index ac70b84fb..000000000 --- a/private/snippets/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Private directory for Yasnippets snippets - -The content of this directory is ignored by Git. This is the default place -where to store your private yasnippets. - -This path will be loaded automatically and used whenever Yasnippets loads. diff --git a/private/templates/README.md b/private/templates/README.md deleted file mode 100644 index 8e27a15bc..000000000 --- a/private/templates/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Private directory for Yatemplate templates - -The content of this directory is ignored by Git. This is the default place -where to store your private templates. - -This path will be loaded automatically and used whenever Yatemplate loads.