[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.
* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#install][Install]]
- [[#key-bindings][Key bindings]]
- [[#eww][Eww]]
- [[#eww-history][Eww History]]
- [[#eww-bookmarks][Eww Bookmarks]]
- [[#eww-buffers][Eww Buffers]]
- [[#description][Description]]
- [[#install][Install]]
- [[#key-bindings][Key bindings]]
- [[#eww][Eww]]
- [[#eww-history][Eww History]]
- [[#eww-bookmarks][Eww Bookmarks]]
- [[#eww-buffers][Eww Buffers]]
* Description
This layer does wonderful things:
This layer does wonderful things:
- Adds evil keybindings support to eww-mode (including
eww-buffers/bookmarks/history-mode)
- Adds spacemacs functionality to eww-mode
- Adds ability to easily navigate eww buffers
* 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
file.
Because this layer is not officially apart of spacemacs, first clone the git
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 Binding | Description | Function |
|-------------+------------------+------------------|
| ~SPC a w e~ | Start eww | eww |
| ~SPC a w w~ | List eww buffers | eww-list-buffers |
** Eww
| Key Binding | Description | Function |
|-------------+--------------------------+----------------------------------|
| ~SPC m s~ | Search | helm-google-suggest |
| ~SPC m S~ | Search (alt) | browse-web |
| ~SPC m r~ | Reload | eww-reload |
| ~SPC m p~ | Previous URL | eww-previous-url |
| ~SPC m n~ | Next URL | eww-next-url |
| ~SPC m h~ | History | eww-list-histories |
| ~SPC m d~ | Download | eww-download |
| ~SPC m a~ | Add Bookmark | eww-add-bookmark |
| ~SPC m l o~ | List Bookmarks | eww-list-bookmarks |
| ~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 f~ | Toggle Fancy Fonts | eww-toggle-fonts |
| ~SPC m v r~ | Reader View | eww-readable |
| ~H~ | Previous URL | eww-previous-url |
| ~L~ | Next URL | eww-next-url |
| ~J~ | Next Eww Buffer | eww-jump-next-buffer |
| ~K~ | Previous Eww Buffer | eww-jump-previous-buffer |
| ~C-j~ | Next Link | shr-next-link |
| ~C-k~ | Previous Link | shr-previous-link |
| ~f~ | Follow Link | eww-follow-link |
| ~F~ | Follow Link New Buffer | eww-follow-link |
| ~o~ | Follow Link (avy/ace) | eww-follow-link |
| ~SPC m .~ | Eww Transient state | |
| ~SPC m s~ | Search | helm-google-suggest |
| ~SPC m S~ | Search (alt) | browse-web |
| ~SPC m r~ | Reload | eww-reload |
| ~SPC m p~ | Previous URL | eww-previous-url |
| ~SPC m n~ | Next URL | eww-next-url |
| ~SPC m h~ | History | eww-list-histories |
| ~SPC m d~ | Download | eww-download |
| ~SPC m a~ | Add Bookmark | eww-add-bookmark |
| ~SPC m l o~ | List Bookmarks | eww-list-bookmarks |
| ~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 f~ | Toggle Fancy Fonts | eww-toggle-fonts |
| ~SPC m v r~ | Reader View | eww-readable |
| ~[~ | Previous URL | eww-previous-url |
| ~]~ | Next URL | eww-next-url |
| ~H~ | Next Eww Buffer | eww-jump-next-buffer |
| ~L~ | Previous Eww Buffer | eww-jump-previous-buffer |
| ~C-o/<~ | History back | eww-back-url |
| ~C-i/>~ | History forward | eww-forward-url |
| ~C-j~ | Next Link | shr-next-link |
| ~C-k~ | Previous Link | shr-previous-link |
| ~f~ | Follow Link | 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
| ~SPC m f~ | Open History | eww-history-browse |
| ~f~ | Open History | eww-history-browse |
| ~SPC m f~ | Open History | eww-history-browse |
| ~f~ | Open History | eww-history-browse |
** Eww Bookmarks
| ~SPC m f~ | Open Bookmark | eww-bookmark-browse |
| ~SPC m d~ | Delete Bookmark | eww-bookmark-kill |
| ~SPC m y~ | Yank Bookmark | eww-yank-bookmark |
| ~f~ | Open Bookmark | eww-bookmark-browse |
| ~d~ | Delete Bookmark | eww-bookmark-kill |
| ~y~ | Yank Bookmark | eww-yank-bookmark |
| ~SPC m f~ | Open Bookmark | eww-bookmark-browse |
| ~SPC m d~ | Delete Bookmark | eww-bookmark-kill |
| ~SPC m y~ | Yank Bookmark | eww-yank-bookmark |
| ~f~ | Open Bookmark | eww-bookmark-browse |
| ~d~ | Delete Bookmark | eww-bookmark-kill |
| ~y~ | Yank Bookmark | eww-yank-bookmark |
** Eww Buffers
| ~SPC m f~ | Open Buffer | eww-buffer-select |
| ~SPC m d~ | Delete Buffer | eww-buffer-kill |
| ~SPC m n~ | Next Buffer | eww-buffer-show-next |
| ~SPC m p~ | Previous Buffer | eww-buffer-show-previous |
| ~f~ | Open Buffer | eww-buffer-select |
| ~d~ | Delete Buffer | eww-buffer-kill |
| ~n~ | Next Buffer | eww-buffer-show-next |
| ~p~ | Previous Buffer | eww-buffer-show-previous |
| ~SPC m f~ | Open Buffer | eww-buffer-select |
| ~SPC m d~ | Delete Buffer | eww-buffer-kill |
| ~SPC m n~ | Next Buffer | eww-buffer-show-next |
| ~SPC m p~ | Previous Buffer | eww-buffer-show-previous |
| ~f~ | Open Buffer | eww-buffer-select |
| ~d~ | Delete Buffer | eww-buffer-kill |
| ~n~ | Next Buffer | eww-buffer-show-next |
| ~p~ | Previous Buffer | eww-buffer-show-previous |
# Use GitHub URLs if you wish to link a Spacemacs documentation file or its heading.
# Examples:
# [[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]]
# If space-doc-mode is enabled, Spacemacs will open a local copy of the linked file.
# Use GitHub URLs if you wish to link a Spacemacs documentation file or its heading.
# Examples:
# [[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]]
# 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>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; 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)
(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 ()
(dolist (buffer (buffer-list))
(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>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
;;; Commentary:
;; See the Spacemacs documentation and FAQs for instructions on how to implement
;; a new layer:
;; 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.
;;
;; 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.
;;
;;
;; Briefly, each package to be installed or configured by this layer should be
;; 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.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
@ -33,93 +26,89 @@
'(
;; A local package
(eww :location built-in)
texfrag
;; (ace-link :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 ()
(progn
(dolist (mode '(eww-mode))
(eval-after-load "eww"
'(progn
(define-key eww-link-keymap "f" 'eww-follow-link)
(define-key eww-link-keymap "F" (lambda () (interactive) (eww-follow-link 2)))))
(spacemacs/declare-prefix-for-mode mode "mv" "view")
(spacemacs/declare-prefix-for-mode mode "ml" "list")
(spacemacs/set-leader-keys-for-major-mode mode
"s" 'helm-google-suggest
"S" 'browse-web
"r" 'eww-reload
"p" 'eww-previous-url
"n" 'eww-next-url
"h" 'eww-list-histories
"d" 'eww-download
"a" 'eww-add-bookmark
"lb" 'eww-list-buffers
"lo" 'eww-list-bookmarks
"vx" 'eww-browse-with-external-browser
"vf" 'eww-toggle-fonts
"vr" 'eww-readable)
(evil-define-key 'normal eww-mode-map
"H" 'eww-back-url
"J" 'spacemacs/eww-jump-next-buffer
"K" 'spacemacs/eww-jump-previous-buffer
"L" 'eww-forward-url
(kbd "C-j") 'shr-next-link
(kbd "C-k") 'shr-previous-link
"o" 'ace-link-eww)
(dolist (mode '(eww-history-mode))
(spacemacs/set-leader-keys-for-major-mode mode
"f" 'eww-history-browse)
(evil-define-key 'normal eww-history-mode-map "f" 'eww-history-browse
"q" 'quit-window)
(dolist (mode '(eww-bookmark-mode))
(spacemacs/set-leader-keys-for-major-mode mode
"d" 'eww-bookmark-kill
"y" 'eww-bookmark-yank
"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)
(dolist (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)
))))))
(use-package eww
:defer t
:init
(spacemacs//eww-setup-transient-state)
(spacemacs/set-leader-keys "awe" 'eww)
(spacemacs/set-leader-keys "aww" 'eww-switch-to-buffer)
:config
(progn
(define-key eww-link-keymap "f" 'eww-follow-link)
(define-key eww-link-keymap "F" (lambda () (interactive) (eww-follow-link 2)))
(let ((mode 'eww-mode))
(spacemacs/declare-prefix-for-mode mode "mv" "view")
(spacemacs/declare-prefix-for-mode mode "ml" "list")
(spacemacs/set-leader-keys-for-major-mode mode
"s" 'helm-google-suggest
"S" 'browse-web
"t" 'spacemacs/eww-render-latex
"r" 'eww-reload
"p" 'eww-previous-url
"n" 'eww-next-url
"h" 'eww-list-histories
"d" 'eww-download
"a" 'eww-add-bookmark
"lb" 'eww-list-buffers
"lo" 'eww-list-bookmarks
"vx" 'eww-browse-with-external-browser
"vf" 'eww-toggle-fonts
"vr" 'eww-readable
"vs" 'eww-view-source)
(evil-define-key 'normal eww-mode-map
(kbd "C-o") 'eww-back-url
(kbd "C-i") 'eww-forward-url
"<" 'eww-back-url
">" 'eww-forward-url
"[" 'eww-previous-url
"]" 'eww-next-url
"L" 'spacemacs/eww-jump-next-buffer
"H" 'spacemacs/eww-jump-previous-buffer
(kbd "C-j") 'shr-next-link
(kbd "C-k") 'shr-previous-link
"o" 'ace-link-eww
"+" 'zoom-frm-in
"-" 'zoom-frm-out
"=" 'zoom-frm-unzoom))
(let ((mode 'eww-history-mode))
(spacemacs/set-leader-keys-for-major-mode mode
"f" 'eww-history-browse)
(evil-define-key 'normal eww-history-mode-map "f" 'eww-history-browse
"q" 'quit-window))
(let ((mode 'eww-bookmark-mode))
(spacemacs/set-leader-keys-for-major-mode mode
"d" 'eww-bookmark-kill
"y" 'eww-bookmark-yank
"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