Refactor epub layer

Evilify layer and put bindings behind g.
This commit is contained in:
syl20bnr 2018-06-06 00:34:53 -04:00
parent b37e6d687c
commit 763fec9900
3 changed files with 27 additions and 82 deletions

View File

@ -1,11 +1,12 @@
#+TITLE: epub layer
[[file:img/epub.png]]
* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#features][Features:]]
- [[#install][Install]]
- [[#key-bindings][Key bindings]]
- [[#layer-variables][Layer Variables]]
* Description
This layer provides support for reading EPUB-formatted eBooks in Spacemacs using the
@ -31,19 +32,14 @@ file.
| Key Binding | Description |
|-------------+---------------------|
| ~SPC m n~ | Next chapter |
| ~SPC m p~ | Previous chapter |
| ~SPC m t~ | Table of contents |
| ~SPC m g~ | Re-render document |
| ~SPC m v~ | View source |
| ~SPC m V~ | View content source |
| ~SPC m m~ | Display metadata |
| ~<TAB>~ | Next link |
| ~<BACKTAB>~ | Previous link |
| ~H~ or ~[~ | Previous chapter |
| ~L~ or ~]~ | Next chapter |
| ~g m~ | Display metadata |
| ~g r~ | Re-render document |
| ~g t~ | Table of contents |
| ~g v~ | View source |
| ~g V~ | View content source |
* Layer Variables
The following variables can be set set using the :variables option in the layer declaration:
| Variable | Description |
|---------------------+--------------------------------------|
| epub-nov-text-width | Width of eBook text. Defaults to 80. |
Hint: use ~SPC w c~ to center the buffer.

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -9,73 +9,22 @@
;;
;;; 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 `epub-packages'. Then, for each package PACKAGE:
;;
;; - If PACKAGE is not referenced by any other Spacemacs layer, define a
;; function `epub/init-PACKAGE' to load and initialize the package.
;; - Otherwise, PACKAGE is already referenced by another Spacemacs layer, so
;; define the functions `epub/pre-init-PACKAGE' and/or
;; `epub/post-init-PACKAGE' to customize the package as it is loaded.
;;; Code:
(defconst epub-packages
'((nov :location elpa))
"The list of Lisp packages required by the epub 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 epub/setup-nov-major-mode-keys ()
(spacemacs/set-leader-keys-for-major-mode 'nov-mode
"g" 'nov-render-document
"v" 'nov-view-source
"V" 'nov-view-content-source
"m" 'nov-display-metadata
"n" 'nov-next-document
"]" 'nov-next-document
"p" 'nov-previous-document
"[" 'nov-previous-document
"t" 'nov-goto-toc))
(defconst epub-packages '(nov))
(defun epub/init-nov ()
(let ((epub/nov-text-width
(if (boundp 'epub-nov-text-width) epub-nov-text-width 80)))
(use-package nov
:mode ("\\.epub\\'" . nov-mode)
:init (setq nov-text-width epub/nov-text-width)
:config (epub/setup-nov-major-mode-keys))))
;;; packages.el ends here
(use-package nov
:defer t
:mode ("\\.epub\\'" . nov-mode)
:config
(evilified-state-evilify-map nov-mode-map
:mode nov-mode
:bindings
(kbd "H") 'nov-previous-document
(kbd "L") 'nov-next-document
(kbd "[") 'nov-previous-document
(kbd "]") 'nov-next-document
(kbd "gm") 'nov-display-metadata
(kbd "gr") 'nov-render-document
(kbd "gt") 'nov-goto-toc
(kbd "gv") 'nov-view-source
(kbd "gV") 'nov-view-content-source)))