[djvu] Fix docs and prefixes

also removed layer dependency on evil
This commit is contained in:
Maxi Wolff 2021-09-11 22:02:54 +02:00
parent 5ce60dfdf7
commit 7f43d9cf6d
No known key found for this signature in database
GPG Key ID: 2DD07025BFDBD89A
4 changed files with 62 additions and 62 deletions

View File

@ -1,11 +1,9 @@
#+TITLE: djvu layer
#+TAGS: layer|reader
# The maximum height of the logo should be 200 pixels.
#+CAPTION: source: https://commons.wikimedia.org/wiki/File:DjVu-logo.svg
[[img/djvu-logo.svg]]
# TOC links should be GitHub style anchors.
* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#features][Features:]]
@ -13,6 +11,10 @@
- [[#prerequisites][Prerequisites]]
- [[#dotfile][Dotfile]]
- [[#key-bindings][Key bindings]]
- [[#djvu-read-mode][djvu-read-mode]]
- [[#annotations][Annotations]]
- [[#djvu-image-minor-mode][djvu-image-minor-mode]]
- [[#djvu-occur-mode][djvu-occur-mode]]
* Description
This layer adds support for reading djvu files with spacemacs.
@ -33,24 +35,23 @@ package]] along with the [[https://github.com/dalanicolai/djvu3][djvu3]] extensi
* Install
** Prerequisites
The =djvu= package requires the =djvused= command (from [[http://djvu.sourceforge.net/][djvulibre]]) to be
available in =exec-path=.
The =djvu= package requires the command =djvused= (from [[http://djvu.sourceforge.net/][djvulibre]]) to be
available in =exec-path=.
Additionally, for =dark-mode= availability of the command =pnminvert= (from
[[http://netpbm.sourceforge.net/][netpbm]]) is required.
Additionally, for =dark-mode= the command =pnminvert= (from
[[http://netpbm.sourceforge.net/][netpbm]]) is required.
** Dotfile
After installing the dependencies, add this to your ~/.spacemacs.
After installing the dependencies, add this to your ~/.spacemacs.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(djvu))
(setq-default dotspacemacs-configuration-layers '(djvu))
#+END_SRC
After that, syncronize your configuration with SPC f e R.
* Key bindings
*djvu-read-mode*
** djvu-read-mode
| Key Binding | Description |
|-------------+----------------------------------------------------------------------------------|
| ~i~ | djvu-image-toggle |
@ -59,30 +60,37 @@ After that, syncronize your configuration with SPC f e R.
| ~J~ | next page |
| ~K~ | previous page |
| ~g~ | goto page |
| | |
| ~d~ | djvu-toggle-invert (dark-mode) |
| ~c~ | djvu-toggle-semi-continuous-scrolling (works only when image larger than window) |
| ~+/-~ | zoom-in/out |
| ~, s~ | djvu-occur |
| ~/~ | djvu fast search |
| ~n~ | djvu search continue |
| | |
| ~SPC j i~ | imenu navigation |
| ~o~ | outline |
*Annotations*
** Annotations
| Key Binding | Description |
|--------------------+--------------------------------------------------------|
| ~SPC m h~ | keyboard highlight |
| ~mouse-1-drag~ | highlight |
| ~S-mouse-1-drag~ | text annotation ([[https://github.com/dalanicolai/djvu3#comments][comment]]) |
| ~C-mouse-1-drag~ | text pushpin (rendering pushpin not, yet, implemented) |
| ~C-mouse-1-drag~ | text pushpin (rendering pushpin not yet implemented) |
| ~mouse-2-drag~ | line |
| ~S-mouse-2-drag~ | horizontal line |
| ~C-mouse-2-drag~ | vertical line |
| ~C-S-mouse-2-drag~ | arrow |
*djvu-image-minor-mode*
| ~s~ | save-image |
** djvu-image-minor-mode
*djvu-occur-mode*
| ~C-j~ | next entry and follow |
| ~C-k~ | prevoius entry and follow |
| Key Binding | Description |
|-------------+-------------|
| ~s~ | save-image |
** djvu-occur-mode
| Key Binding | Description |
|-------------+---------------------------|
| ~C-j~ | next entry and follow |
| ~C-k~ | prevoius entry and follow |

View File

@ -21,13 +21,6 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(defun djvu-toggle-semi-continuous-scrolling ()
(interactive)
(setq djvu-semi-continuous-scrolling (not djvu-semi-continuous-scrolling))
(message "Djvu alternative scrolling %s" (if djvu-semi-continuous-scrolling
"enabled"
"disabled")))
(defun spacemacs/djvu-advise-image-toggle (_file &rest args)
(djvu-image-toggle))
@ -67,30 +60,44 @@ Use the command `djvu-search-forward-continue' to continue the search."
(interactive "sQuery: ")
(setq djvu-last-search-re query)
(unless (eq (djvu-ref page) (djvu-ref pagemax))
(search-forward query nil t))
(djvu-goto-page (let ((page (djvu-ref page))
(return 1))
(while (and (/= return 0) (< page (+ (djvu-ref pagemax) 1)))
(setq page (1+ page))
(setq return (call-process-shell-command
(format "djvused %s -e 'select %s; print-pure-txt' | grep -i '%s'"
(shell-quote-argument buffer-file-name)
page
query))))
page))
(search-forward query nil t))
(search-forward query nil t))
(djvu-goto-page (let ((page (djvu-ref page))
(return 1))
(while (and (/= return 0) (< page (+ (djvu-ref pagemax) 1)))
(setq page (1+ page))
(setq return (call-process-shell-command
(format "djvused %s -e 'select %s; print-pure-txt' | grep -i '%s'"
(shell-quote-argument buffer-file-name)
page
query))))
page))
(search-forward query nil t))
(defun spacemacs/djvu-re-search-forward-continue ()
"Continue search forward for match for `djvu-last-search-re'."
(interactive)
(spacemacs/djvu-search-forward djvu-last-search-re))
(defun djvu-occur-next-entry-and-follow ()
(defun spacemacs//djvu-set-imenu-create-index-function ()
(setq imenu-create-index-function #'djvu-imenu-create-index))
(defun spacemacs//djvu-set-imenu-goto-function ()
(setq imenu-default-goto-function (lambda (title page)
(djvu-goto-page page djvu-doc))))
(defun spacemacs/djvu-toggle-semi-continuous-scrolling ()
(interactive)
(setq djvu-semi-continuous-scrolling (not djvu-semi-continuous-scrolling))
(message "Djvu alternative scrolling %s" (if djvu-semi-continuous-scrolling
"enabled"
"disabled")))
(defun spacemacs/djvu-occur-next-entry-and-follow ()
(interactive)
(evil-next-visual-line)
(call-interactively 'djvu-occur-show-entry))
(defun djvu-occur-previous-entry-and-follow ()
(defun spacemacs/djvu-occur-previous-entry-and-follow ()
(interactive)
(evil-previous-visual-line)
(call-interactively 'djvu-occur-show-entry))

View File

@ -1 +0,0 @@
(configuration-layer/declare-layer 'spacemacs-evil)

View File

@ -1,4 +1,4 @@
;;; packages.el --- djvu layer packages file for Spacemacs.
;;; packages.el --- Djvu Layer Packages File for Spacemacs
;;
;; Copyright (c) 2021 Sylvain Benner & Contributors
;;
@ -20,8 +20,6 @@
;; 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:
(defconst djvu-packages
'(djvu
tablist
@ -43,14 +41,10 @@
:after djvu
:init
(add-to-list 'spacemacs-large-file-modes-list 'djvu-read-mode t)
(add-hook 'djvu-read-mode-hook (lambda () (setq imenu-create-index-function #'djvu-imenu-create-index)))
(add-hook 'djvu-read-mode-hook (lambda ()
(setq imenu-default-goto-function (lambda (title page)
(djvu-goto-page page djvu-doc)))))
(add-hook 'djvu-read-mode-hook 'spacemacs//djvu-set-imenu-create-index-function)
(add-hook 'djvu-read-mode-hook 'spacemacs//djvu-set-imenu-goto-function)
:config
(advice-add 'djvu-find-file :after #'spacemacs/djvu-advise-image-toggle)
(evilified-state-evilify-map djvu-read-mode-map
:mode djvu-read-mode
:bindings
@ -63,13 +57,11 @@
"n" 'spacemacs/djvu-re-search-forward-continue
"H" 'djvu-history-backward
"L" 'djvu-history-forward
"c" 'djvu-toggle-semi-continuous-scrolling
"c" 'spacemacs/djvu-toggle-semi-continuous-scrolling
"d" 'djvu-toggle-invert
"r" 'djvu-revert-buffer
"q" 'djvu-kill-doc)
(define-key djvu-image-mode-map "s" 'image-save)
(spacemacs/declare-prefix-for-mode 'djvu-read-mode "mb" "buffers")
(spacemacs/set-leader-keys-for-major-mode 'djvu-read-mode
"s" 'djvu-occur
@ -81,12 +73,10 @@
"bt" 'djvu-switch-text
"ba" 'djvu-switch-annot
"bb" 'djvu-switch-bookmarks)
;; for some reason can not use dolist here
(define-key djvu-read-mode-map [remap save-buffer] 'djvu-save)
(define-key djvu-script-mode-map [remap save-buffer] 'djvu-save)
(define-key djvu-outline-mode-map [remap save-buffer] 'djvu-save)
(spacemacs/set-leader-keys-for-major-mode 'djvu-script-mode
"r" 'djvu-switch-read
"s" 'djvu-switch-shared
@ -94,18 +84,14 @@
"t" 'djvu-switch-text
"a" 'djvu-switch-annot
"b" 'djvu-switch-bookmarks)
(evilified-state-evilify-map djvu-outline-mode-map
:mode djvu-outline-mode
:bindings
"r" 'djvu-revert-buffer
"q" 'djvu-quit-window)
(evilified-state-evilify-map djvu-occur-mode-map
:mode djvu-occur-mode
:bindings
(kbd "C-j") 'djvu-occur-next-entry-and-follow
(kbd "C-k") 'djvu-occur-previous-entry-and-follow
(kbd "C-j") 'spacemacs/djvu-occur-next-entry-and-follow
(kbd "C-k") 'spacemacs/djvu-occur-previous-entry-and-follow
"r" 'tablist-revert)))
;;; packages.el ends here