Skip to content

Commit

Permalink
Add eww transient state
Browse files Browse the repository at this point in the history
  • Loading branch information
dalanicolai committed Dec 20, 2020
1 parent 6fc3bfb commit 33459b8
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 64 deletions.
15 changes: 10 additions & 5 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@
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 .~ | Eww Transient state | |
| ~SPC m s~ | Search | helm-google-suggest |
| ~SPC m S~ | Search (alt) | browse-web |
| ~SPC m r~ | Reload | eww-reload |
Expand All @@ -58,15 +61,17 @@
| ~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 |
| ~C-o/[~ | 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 |
| ~H~ | Next Eww Buffer | eww-jump-next-buffer |
| ~C-i/[~ | 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 |
| ~+/-~ | 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 |
Expand Down
75 changes: 75 additions & 0 deletions funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,81 @@

(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^^^^ Scale/Fit^^ Annotations^^ Actions^^ Other^^
----------^^^^--------------- ---------^^------------------ -----------^^------ -------^^---------- -----^^---
[_[_/_]_] history back/forw [_v_] toggle visual-line-mode [_al_] list [_t_] toggle latex [_q_] quit
[_H_/_L_] prev/next eww-buff [_w_] toggle writeroom-mode ^^ [_c_] cycle theme
^^^^ [_+_] zoom-in
^^^^ [_-_] zoom-out
^^^^ [_=_] unzoom"))

(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
("[" eww-back-url)
("]" eww-next-url)
("H" spacemacs/eww-jump-previous-buffer)
("L" spacemacs/eww-jump-next-buffer)
;; Scale/Fit
("w" writeroom-mode)
("v" visual-line-mode)
("+" zoom-frm-in)
("-" zoom-frm-out)
("=" zoom-frm-unzoom)
;; Annotations
("al" pdf-annot-list-annotations :exit t)
;; Actions
("t" spacemacs/eww-render-latex)
("c" spacemacs/cycle-spacemacs-theme)
;; Other
("q" nil :exit t)))

(defun spacemacs//eww-get-buffers ()
(dolist (buffer (buffer-list))
(with-current-buffer buffer
Expand Down
133 changes: 74 additions & 59 deletions packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors
;;
;; Author: Colton Kopsa <[email protected]>
;; Daniel Nicolai <[email protected]>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
Expand Down Expand Up @@ -65,65 +66,79 @@ Each entry is either:
recipe. See: https://github.com/milkypostman/melpa#recipe-format")

(defun eww/init-eww ()
(with-eval-after-load "eww"
(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
"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))

(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))))
(use-package eww
:defer t
:init
(spacemacs//eww-setup-transient-state)
(spacemacs/set-leader-keys "awe" 'eww)
(spacemacs/set-leader-keys "aww" 'eww-list-buffers)
: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)
(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
"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))
Expand Down

0 comments on commit 33459b8

Please sign in to comment.