[eww] Specific changes from dalanicolai/eww-layer

This commit combines all changes from the above
mentioned fork from the original author.

All praise goes to dalanicolai.
This commit is contained in:
Maximilian Wolff 2021-04-15 21:25:18 +00:00
parent 313f975a2f
commit f5ae720645
3 changed files with 277 additions and 163 deletions

View file

@ -5,74 +5,97 @@
# TOC links should be GitHub style anchors. # TOC links should be GitHub style anchors.
* Table of Contents :TOC_4_gh:noexport: * Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]] - [[#description][Description]]
- [[#install][Install]] - [[#install][Install]]
- [[#key-bindings][Key bindings]] - [[#key-bindings][Key bindings]]
- [[#eww][Eww]] - [[#eww][Eww]]
- [[#eww-history][Eww History]] - [[#eww-history][Eww History]]
- [[#eww-bookmarks][Eww Bookmarks]] - [[#eww-bookmarks][Eww Bookmarks]]
- [[#eww-buffers][Eww Buffers]] - [[#eww-buffers][Eww Buffers]]
* Description * Description
This layer does wonderful things: This layer does wonderful things:
- Adds evil keybindings support to eww-mode (including - Adds evil keybindings support to eww-mode (including
eww-buffers/bookmarks/history-mode) eww-buffers/bookmarks/history-mode)
- Adds spacemacs functionality to eww-mode - Adds spacemacs functionality to eww-mode
- Adds ability to easily navigate eww buffers - Adds ability to easily navigate eww buffers
* Install * Install
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =eww= to the existing =dotspacemacs-configuration-layers= list in this Because this layer is not officially apart of spacemacs, first clone the git
file. repository somewhere and add it as a private layer in spacemacs:
#+BEGIN_SRC bash
git clone https://github.com/coljamkop/eww-layer.git /path/to/dotspacemacs-configuration-layer-path/eww
#+END_SRC
OR
#+BEGIN_SRC bash
git clone https://github.com/coljamkop/eww-layer.git
ln -s "`pwd`/eww-layer" ~/.emacs.d/private/eww
#+END_SRC
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =eww= to the existing =dotspacemacs-configuration-layers= list in this
file.
* Key bindings * Key bindings
| Key Binding | Description | Function |
|-------------+------------------+------------------|
| ~SPC a w e~ | Start eww | eww |
| ~SPC a w w~ | List eww buffers | eww-list-buffers |
** Eww ** Eww
| Key Binding | Description | Function | | ~SPC m .~ | Eww Transient state | |
|-------------+--------------------------+----------------------------------| | ~SPC m s~ | Search | helm-google-suggest |
| ~SPC m s~ | Search | helm-google-suggest | | ~SPC m S~ | Search (alt) | browse-web |
| ~SPC m S~ | Search (alt) | browse-web | | ~SPC m r~ | Reload | eww-reload |
| ~SPC m r~ | Reload | eww-reload | | ~SPC m p~ | Previous URL | eww-previous-url |
| ~SPC m p~ | Previous URL | eww-previous-url | | ~SPC m n~ | Next URL | eww-next-url |
| ~SPC m n~ | Next URL | eww-next-url | | ~SPC m h~ | History | eww-list-histories |
| ~SPC m h~ | History | eww-list-histories | | ~SPC m d~ | Download | eww-download |
| ~SPC m d~ | Download | eww-download | | ~SPC m a~ | Add Bookmark | eww-add-bookmark |
| ~SPC m a~ | Add Bookmark | eww-add-bookmark | | ~SPC m l o~ | List Bookmarks | eww-list-bookmarks |
| ~SPC m l o~ | List Bookmarks | eww-list-bookmarks | | ~SPC m l b~ | List Eww Buffers | eww-list-buffers |
| ~SPC m l b~ | List Eww Buffers | eww-list-buffers | | ~SPC m v x~ | View in External Browser | eww-browse-with-external-browser |
| ~SPC m v x~ | View in External Browser | eww-browse-with-external-browser | | ~SPC m v f~ | Toggle Fancy Fonts | eww-toggle-fonts |
| ~SPC m v f~ | Toggle Fancy Fonts | eww-toggle-fonts | | ~SPC m v r~ | Reader View | eww-readable |
| ~SPC m v r~ | Reader View | eww-readable | | ~[~ | Previous URL | eww-previous-url |
| ~H~ | Previous URL | eww-previous-url | | ~]~ | Next URL | eww-next-url |
| ~L~ | Next URL | eww-next-url | | ~H~ | Next Eww Buffer | eww-jump-next-buffer |
| ~J~ | Next Eww Buffer | eww-jump-next-buffer | | ~L~ | Previous Eww Buffer | eww-jump-previous-buffer |
| ~K~ | Previous Eww Buffer | eww-jump-previous-buffer | | ~C-o/<~ | History back | eww-back-url |
| ~C-j~ | Next Link | shr-next-link | | ~C-i/>~ | History forward | eww-forward-url |
| ~C-k~ | Previous Link | shr-previous-link | | ~C-j~ | Next Link | shr-next-link |
| ~f~ | Follow Link | eww-follow-link | | ~C-k~ | Previous Link | shr-previous-link |
| ~F~ | Follow Link New Buffer | eww-follow-link | | ~f~ | Follow Link | eww-follow-link |
| ~o~ | Follow Link (avy/ace) | eww-follow-link | | ~F~ | Follow Link New Buffer | eww-follow-link |
| ~o~ | Follow Link (avy/ace) | eww-follow-link |
| ~+/-~ | zoom in/out | zoom-frm-in/out |
| ~=~ | unzoom | zoom-frm-unzoom |
** Eww History ** Eww History
| ~SPC m f~ | Open History | eww-history-browse | | ~SPC m f~ | Open History | eww-history-browse |
| ~f~ | Open History | eww-history-browse | | ~f~ | Open History | eww-history-browse |
** Eww Bookmarks ** Eww Bookmarks
| ~SPC m f~ | Open Bookmark | eww-bookmark-browse | | ~SPC m f~ | Open Bookmark | eww-bookmark-browse |
| ~SPC m d~ | Delete Bookmark | eww-bookmark-kill | | ~SPC m d~ | Delete Bookmark | eww-bookmark-kill |
| ~SPC m y~ | Yank Bookmark | eww-yank-bookmark | | ~SPC m y~ | Yank Bookmark | eww-yank-bookmark |
| ~f~ | Open Bookmark | eww-bookmark-browse | | ~f~ | Open Bookmark | eww-bookmark-browse |
| ~d~ | Delete Bookmark | eww-bookmark-kill | | ~d~ | Delete Bookmark | eww-bookmark-kill |
| ~y~ | Yank Bookmark | eww-yank-bookmark | | ~y~ | Yank Bookmark | eww-yank-bookmark |
** Eww Buffers ** Eww Buffers
| ~SPC m f~ | Open Buffer | eww-buffer-select | | ~SPC m f~ | Open Buffer | eww-buffer-select |
| ~SPC m d~ | Delete Buffer | eww-buffer-kill | | ~SPC m d~ | Delete Buffer | eww-buffer-kill |
| ~SPC m n~ | Next Buffer | eww-buffer-show-next | | ~SPC m n~ | Next Buffer | eww-buffer-show-next |
| ~SPC m p~ | Previous Buffer | eww-buffer-show-previous | | ~SPC m p~ | Previous Buffer | eww-buffer-show-previous |
| ~f~ | Open Buffer | eww-buffer-select | | ~f~ | Open Buffer | eww-buffer-select |
| ~d~ | Delete Buffer | eww-buffer-kill | | ~d~ | Delete Buffer | eww-buffer-kill |
| ~n~ | Next Buffer | eww-buffer-show-next | | ~n~ | Next Buffer | eww-buffer-show-next |
| ~p~ | Previous Buffer | eww-buffer-show-previous | | ~p~ | Previous Buffer | eww-buffer-show-previous |
# Use GitHub URLs if you wish to link a Spacemacs documentation file or its heading. # Use GitHub URLs if you wish to link a Spacemacs documentation file or its heading.
# Examples: # Examples:
# [[https://github.com/syl20bnr/spacemacs/blob/master/doc/VIMUSERS.org#sessions]] # [[https://github.com/syl20bnr/spacemacs/blob/master/doc/VIMUSERS.org#sessions]]
# [[https://github.com/syl20bnr/spacemacs/blob/master/layers/%2Bfun/emoji/README.org][Link to Emoji layer README.org]] # [[https://github.com/syl20bnr/spacemacs/blob/master/layers/%2Bfun/emoji/README.org][Link to Emoji layer README.org]]
# If space-doc-mode is enabled, Spacemacs will open a local copy of the linked file. # If space-doc-mode is enabled, Spacemacs will open a local copy of the linked file.

View file

@ -1,16 +1,118 @@
;;; funcs.el --- eww layer packages file for Spacemacs. ;;; funcs.el --- EWW Layer funcs File for Spacemacs
;; ;;
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors ;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
;; ;;
;; Author: Colton Kopsa <coljamkop@gmail.com> ;; Author: Colton Kopsa <coljamkop@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs ;; URL: https://github.com/syl20bnr/spacemacs
;; ;;
;; This file is not part of GNU Emacs. ;; This file is not part of GNU Emacs.
;; ;;
;;; License: GPLv3 ;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(defvar spacemacs--eww-buffers nil) (defvar spacemacs--eww-buffers nil)
(defun spacemacs/eww-render-latex ()
(interactive)
(call-interactively #'texfrag-mode)
(when texfrag-mode
(eww-reload)))
(defun spacemacs//eww-setup-transient-state ()
"Setup eww transient state with toggleable help hint.
Beware: due to transient state's implementation details this
function must be called in the :init section of `use-package' or
full hint text will not show up!"
(defvar spacemacs--eww-ts-full-hint-toggle t
"Toggle the state of the eww transient state documentation.")
(defvar spacemacs--eww-ts-full-hint nil
"Display full pdf transient state documentation.")
(defvar spacemacs--eww-ts-minified-hint nil
"Display minified pdf transient state documentation.")
(defun spacemacs//eww-ts-toggle-hint ()
"Toggle the full hint docstring for the eww transient state."
(interactive)
(setq spacemacs--eww-ts-full-hint-toggle
(not spacemacs--eww-ts-full-hint-toggle)))
(defun spacemacs//eww-ts-hint ()
"Return a condensed/full hint for the eww transient state"
(concat
" "
(if spacemacs--eww-ts-full-hint-toggle
spacemacs--eww-ts-full-hint
(concat "[" (propertize "?" 'face 'hydra-face-red) "] help"))))
(spacemacs|transient-state-format-hint eww
spacemacs--eww-ts-full-hint
(format "\n[_?_] toggle help
Navigation^^^^^^^^ Layout/Appearance^^ Zoom^^ List/view^^ Other^^
----------^^^^^^^^--------------- ---------^^------------------ -----------^^------ -------^^----------- -----^^-----------------------
[_h_/_j_/_k_/_l_] scroll l/d/u/r [_v_] toggle visual-line-mode [_+_] zoom-in [_W_] list buffers [_r_] reload page
[_H_/_L_] prev/next eww-buff^^^^ [_w_] toggle writeroom-mode [_-_] zoom-out [_S_] list histories [_x_] view in external browser
[_<_/_>_] history back/forw^^^^ [_c_] toggle colors [_=_] unzoom [_B_] list bookmarks [_d_] download
[_[_/_]_] page previous/next^^^^ [_t_] toggle latex ^^ [_V_] view source [_B_] add bookmark
[_u_] page up^^^^^^ [_C_] cycle theme ^^ ^^ [_q_] quit
[_t_] top url^^^^^^"))
(spacemacs|define-transient-state eww
:title "Eww Transient State"
:hint-is-doc t
:dynamic-hint (spacemacs//eww-ts-hint)
:on-enter (setq which-key-inhibit t)
:on-exit (setq which-key-inhibit nil)
:evil-leader-for-mode (eww-mode . ".")
:bindings
("?" spacemacs//eww-ts-toggle-hint)
;; Navigation
("j" evil-next-line)
("k" evil-previous-line)
("h" evil-backward-char)
("l" evil-forward-char)
("<" eww-back-url)
(">" eww-forward-url)
("[" eww-previous-url)
("]" eww-next-url)
("H" spacemacs/eww-jump-previous-buffer)
("L" spacemacs/eww-jump-next-buffer)
("u" eww-up-url)
("t" eww-top-url)
;; Layout/Appearance
("w" writeroom-mode)
("v" visual-line-mode)
("c" eww-toggle-colors)
("t" spacemacs/eww-render-latex)
("C" spacemacs/cycle-spacemacs-theme)
;; Zoom
("+" zoom-frm-in)
("-" zoom-frm-out)
("=" zoom-frm-unzoom)
;; Lit/view
("W" eww-list-buffers)
("S" eww-list-histories)
("B" eww-list-bookmarks)
("V" eww-view-source)
;; Other
("r" eww-reload)
("x" eww-browse-with-external-browser :exit t)
("d" eww-download)
("B" eww-add-bookmark)
("q" nil :exit t)))
(defun spacemacs//eww-get-buffers () (defun spacemacs//eww-get-buffers ()
(dolist (buffer (buffer-list)) (dolist (buffer (buffer-list))
(with-current-buffer buffer (with-current-buffer buffer

View file

@ -1,31 +1,24 @@
;;; packages.el --- eww layer packages file for Spacemacs. ;;; packages.el --- EWW Layer packages File for Spacemacs
;; ;;
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors ;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
;; ;;
;; Author: Colton Kopsa <coljamkop@gmail.com> ;; Author: Colton Kopsa <coljamkop@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs ;; URL: https://github.com/syl20bnr/spacemacs
;; ;;
;; This file is not part of GNU Emacs. ;; This file is not part of GNU Emacs.
;; ;;
;;; License: GPLv3 ;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;;; Commentary: ;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; See the Spacemacs documentation and FAQs for instructions on how to implement
;; a new layer:
;; ;;
;; SPC h SPC layers RET ;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; ;;
;; ;; You should have received a copy of the GNU General Public License
;; Briefly, each package to be installed or configured by this layer should be ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; added to `eww-packages'. Then, for each package PACKAGE:
;;
;; - If PACKAGE is not referenced by any other Spacemacs layer, define a
;; function `eww/init-PACKAGE' to load and initialize the package.
;; - Otherwise, PACKAGE is already referenced by another Spacemacs layer, so
;; define the functions `eww/pre-init-PACKAGE' and/or
;; `eww/post-init-PACKAGE' to customize the package as it is loaded.
;;; Code: ;;; Code:
@ -33,93 +26,89 @@
'( '(
;; A local package ;; A local package
(eww :location built-in) (eww :location built-in)
texfrag
;; (ace-link :location elpa) ;; (ace-link :location elpa)
;; (helm-net :location elpa) ;; (helm-net :location elpa)
) ))
"The list of Lisp packages required by the eww layer.
Each entry is either:
1. A symbol, which is interpreted as a package to be installed, or
2. A list of the form (PACKAGE KEYS...), where PACKAGE is the
name of the package to be installed or loaded, and KEYS are
any number of keyword-value-pairs.
The following keys are accepted:
- :excluded (t or nil): Prevent the package from being loaded
if value is non-nil
- :location: Specify a custom installation location.
The following values are legal:
- The symbol `elpa' (default) means PACKAGE will be
installed using the Emacs package manager.
- The symbol `local' directs Spacemacs to load the file at
`./local/PACKAGE/PACKAGE.el'
- A list beginning with the symbol `recipe' is a melpa
recipe. See: https://github.com/milkypostman/melpa#recipe-format")
(defun eww/init-eww () (defun eww/init-eww ()
(progn (use-package eww
(dolist (mode '(eww-mode)) :defer t
(eval-after-load "eww" :init
'(progn (spacemacs//eww-setup-transient-state)
(define-key eww-link-keymap "f" 'eww-follow-link) (spacemacs/set-leader-keys "awe" 'eww)
(define-key eww-link-keymap "F" (lambda () (interactive) (eww-follow-link 2))))) (spacemacs/set-leader-keys "aww" 'eww-switch-to-buffer)
(spacemacs/declare-prefix-for-mode mode "mv" "view") :config
(spacemacs/declare-prefix-for-mode mode "ml" "list") (progn
(spacemacs/set-leader-keys-for-major-mode mode (define-key eww-link-keymap "f" 'eww-follow-link)
"s" 'helm-google-suggest (define-key eww-link-keymap "F" (lambda () (interactive) (eww-follow-link 2)))
"S" 'browse-web
"r" 'eww-reload (let ((mode 'eww-mode))
"p" 'eww-previous-url (spacemacs/declare-prefix-for-mode mode "mv" "view")
"n" 'eww-next-url (spacemacs/declare-prefix-for-mode mode "ml" "list")
"h" 'eww-list-histories (spacemacs/set-leader-keys-for-major-mode mode
"d" 'eww-download "s" 'helm-google-suggest
"a" 'eww-add-bookmark "S" 'browse-web
"lb" 'eww-list-buffers "t" 'spacemacs/eww-render-latex
"lo" 'eww-list-bookmarks "r" 'eww-reload
"vx" 'eww-browse-with-external-browser "p" 'eww-previous-url
"vf" 'eww-toggle-fonts "n" 'eww-next-url
"vr" 'eww-readable) "h" 'eww-list-histories
(evil-define-key 'normal eww-mode-map "d" 'eww-download
"H" 'eww-back-url "a" 'eww-add-bookmark
"J" 'spacemacs/eww-jump-next-buffer "lb" 'eww-list-buffers
"K" 'spacemacs/eww-jump-previous-buffer "lo" 'eww-list-bookmarks
"L" 'eww-forward-url "vx" 'eww-browse-with-external-browser
(kbd "C-j") 'shr-next-link "vf" 'eww-toggle-fonts
(kbd "C-k") 'shr-previous-link "vr" 'eww-readable
"o" 'ace-link-eww) "vs" 'eww-view-source)
(dolist (mode '(eww-history-mode)) (evil-define-key 'normal eww-mode-map
(spacemacs/set-leader-keys-for-major-mode mode (kbd "C-o") 'eww-back-url
"f" 'eww-history-browse) (kbd "C-i") 'eww-forward-url
(evil-define-key 'normal eww-history-mode-map "f" 'eww-history-browse "<" 'eww-back-url
"q" 'quit-window) ">" 'eww-forward-url
(dolist (mode '(eww-bookmark-mode)) "[" 'eww-previous-url
(spacemacs/set-leader-keys-for-major-mode mode "]" 'eww-next-url
"d" 'eww-bookmark-kill "L" 'spacemacs/eww-jump-next-buffer
"y" 'eww-bookmark-yank "H" 'spacemacs/eww-jump-previous-buffer
"f" 'eww-bookmark-browse) (kbd "C-j") 'shr-next-link
(evil-define-key 'normal eww-bookmark-mode-map (kbd "C-k") 'shr-previous-link
"q" 'quit-window "o" 'ace-link-eww
"f" 'eww-bookmark-browse "+" 'zoom-frm-in
"d" 'eww-bookmark-kill "-" 'zoom-frm-out
"y" 'eww-bookmark-yank) "=" 'zoom-frm-unzoom))
(dolist (mode '(eww-buffers-mode))
(spacemacs/set-leader-keys-for-major-mode mode (let ((mode 'eww-history-mode))
"f" 'eww-buffer-select (spacemacs/set-leader-keys-for-major-mode mode
"d" 'eww-buffer-kill "f" 'eww-history-browse)
"n" 'eww-buffer-show-next (evil-define-key 'normal eww-history-mode-map "f" 'eww-history-browse
"p" 'eww-buffer-show-previous) "q" 'quit-window))
(evil-define-key 'normal eww-buffers-mode-map
"q" 'quit-window (let ((mode 'eww-bookmark-mode))
"f" 'eww-buffer-select (spacemacs/set-leader-keys-for-major-mode mode
"d" 'eww-buffer-kill "d" 'eww-bookmark-kill
"n" 'eww-buffer-show-next "y" 'eww-bookmark-yank
"p" 'eww-buffer-show-previous) "f" 'eww-bookmark-browse)
)))))) (evil-define-key 'normal eww-bookmark-mode-map
"q" 'quit-window
"f" 'eww-bookmark-browse
"d" 'eww-bookmark-kill
"y" 'eww-bookmark-yank))
(let ((mode 'eww-buffers-mode))
(spacemacs/set-leader-keys-for-major-mode mode
"f" 'eww-buffer-select
"d" 'eww-buffer-kill
"n" 'eww-buffer-show-next
"p" 'eww-buffer-show-previous)
(evil-define-key 'normal eww-buffers-mode-map
"q" 'quit-window
"f" 'eww-buffer-select
"d" 'eww-buffer-kill
"n" 'eww-buffer-show-next
"p" 'eww-buffer-show-previous)))))
(defun eww/init-texfrag ()
(use-package texfrag
:defer t))
;;; packages.el ends here ;;; packages.el ends here