Add eww layer

A spacemacs layer that adds:
 - Improved spacemacs functionality to eww-mode
 - Evil keybindings to eww-mode (including eww-buffers/bookmarks/history-mode)
 - Improved eww buffer management with key bindings
This commit is contained in:
coljamkop 2017-11-15 05:43:53 -07:00 committed by Maximilian Wolff
parent 347ac504d8
commit 313f975a2f
4 changed files with 252 additions and 0 deletions

View File

@ -0,0 +1,78 @@
#+TITLE: eww layer
# The maximum height of the logo should be 200 pixels.
[[file:img/eww.png]]
# 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
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.
* Key bindings
** 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 |
** Eww History
| ~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 |
** 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 |
# 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.

49
layers/+web/eww/funcs.el Normal file
View File

@ -0,0 +1,49 @@
;;; funcs.el --- eww layer packages file for Spacemacs.
;;
;; Copyright (c) 2012-2017 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
(defvar spacemacs--eww-buffers nil)
(defun spacemacs//eww-get-buffers ()
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (and (derived-mode-p 'eww-mode)
(not (memq buffer spacemacs--eww-buffers)))
(push buffer
spacemacs--eww-buffers))))
(unless spacemacs--eww-buffers
(error "No eww buffers"))
;; remove deleted buffers maintaining order
(dolist (buffer spacemacs--eww-buffers)
(if (not (memq buffer (buffer-list)))
(delq buffer spacemacs--eww-buffers)))
spacemacs--eww-buffers)
(defun spacemacs//eww-next-buffer (buff)
(let* ((eww-buffers (spacemacs//eww-get-buffers))
(eww-buffer-pos (seq-position eww-buffers buff)))
(if (eq eww-buffer-pos (1- (length eww-buffers)))
(car eww-buffers)
(nth (1+ eww-buffer-pos) eww-buffers))))
(defun spacemacs//eww-previous-buffer (buff)
(let* ((eww-buffers (spacemacs//eww-get-buffers))
(eww-buffer-pos (seq-position eww-buffers buff)))
(if (zerop eww-buffer-pos)
(car (last eww-buffers))
(nth (1- eww-buffer-pos) eww-buffers))))
(defun spacemacs/eww-jump-next-buffer ()
(interactive)
(pop-to-buffer-same-window (spacemacs//eww-next-buffer (current-buffer))))
(defun spacemacs/eww-jump-previous-buffer ()
(interactive)
(pop-to-buffer-same-window (spacemacs//eww-previous-buffer (current-buffer))))

BIN
layers/+web/eww/img/eww.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

125
layers/+web/eww/packages.el Normal file
View File

@ -0,0 +1,125 @@
;;; packages.el --- eww layer packages file for Spacemacs.
;;
;; Copyright (c) 2012-2017 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:
;;
;; SPC h SPC layers RET
;;
;;
;; 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.
;;; Code:
(defconst eww-packages
'(
;; A local package
(eww :location built-in)
;; (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)
))))))
;;; packages.el ends here