-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update layers/+readers/djvu/packages.el Co-authored-by: Lucius Hu <1222865+lebensterben@users.noreply.github.com>
- Loading branch information
1 parent
671431f
commit f7a7a6f
Showing
7 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#+TITLE: djvu layer | ||
#+TAGS: layer|reader | ||
|
||
# The maximum height of the logo should be 200 pixels. | ||
[[img/djvu-logo.svg]] | ||
|
||
# TOC links should be GitHub style anchors. | ||
* Table of Contents :TOC_4_gh:noexport: | ||
- [[#description][Description]] | ||
- [[#features][Features:]] | ||
- [[#install][Install]] | ||
- [[#prerequisites][Prerequisites]] | ||
- [[#dotfile][Dotfile]] | ||
- [[#key-bindings][Key bindings]] | ||
|
||
* Description | ||
This layer adds support for reading djvu files with spacemacs. | ||
|
||
Because of some difficulties, the layer does not lazy load the =djvu.el= and | ||
=djvu3.el= packages. | ||
|
||
** Features: | ||
This layer provides a full featured djvu editor by implementing the [[https://github.com/dalanicolai/djvu2.el][djvu.el | ||
package]] along with the [[https://github.com/dalanicolai/djvu3][djvu3]] extension (a newer alternative to [[https://github.com/dalanicolai/djvu2.el][djvu2.el]]). | ||
|
||
- flexible annotation editing and rendering, covering most (but not all) of | ||
[[https://linux.die.net/man/1/djvused][djvused]] annotation definitions | ||
- fast navigation with imenu | ||
- fast search with djvu-occur | ||
- remember last view with djvu-restore | ||
- dark mode | ||
|
||
* Install | ||
** Prerequisites | ||
The =djvu= package requires the =djvused= command (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. | ||
|
||
** Dotfile | ||
After installing the dependencies, add this to your ~/.spacemacs. | ||
|
||
#+BEGIN_SRC emacs-lisp | ||
(setq-default dotspacemacs-configuration-layers '(djvu)) | ||
#+END_SRC | ||
|
||
After that, syncronize your configuration with SPC f e R. | ||
|
||
* Key bindings | ||
|
||
*djvu-read-mode* | ||
| Key Binding | Description | | ||
|-------------+----------------------------------------------------------------------------------| | ||
| ~i~ | djvu-image-toggle | | ||
| ~j~ | scroll up | | ||
| ~k~ | scroll down | | ||
| ~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* | ||
| ~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) | | ||
| ~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-occur-mode* | ||
| ~C-j~ | next entry and follow | | ||
| ~C-k~ | prevoius entry and follow | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(defvar djvu-semi-continuous-scrolling nil | ||
"If non-nil, scroll using visual lines.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
;;; funcs.el --- DjVu Layer functions File for Spacemacs | ||
;; | ||
;; Copyright (c) 2021 Sylvain Benner & Contributors | ||
;; | ||
;; Author: Daniel Nicolai <dalanicolai@gmail.com> | ||
;; URL: https://github.com/syl20bnr/spacemacs | ||
;; | ||
;; This file is not part of GNU Emacs. | ||
;; | ||
;; 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/>. | ||
|
||
|
||
(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)) | ||
|
||
;; djvu-continuous of djvu.el does not work with djvu3.el | ||
(defun spacemacs/djvu-scroll-up-or-next-page () | ||
(interactive) | ||
(if (not djvu-semi-continuous-scrolling) | ||
(if djvu-image-mode | ||
(djvu-image-scroll-up) | ||
(evil-next-visual-line)) | ||
(scroll-up-line 5) | ||
(when (= (window-vscroll) 0) | ||
(djvu-next-page 1)))) | ||
|
||
(defun spacemacs/djvu-scroll-down-or-previous-page () | ||
(interactive) | ||
(if (not djvu-semi-continuous-scrolling) | ||
(if djvu-image-mode | ||
(djvu-image-scroll-down) | ||
(evil-previous-visual-line)) | ||
(if (/= (window-vscroll) 0) | ||
(scroll-down-line 5) | ||
(djvu-prev-page 1) | ||
(scroll-up-command)))) | ||
|
||
(defun spacemacs/djvu-fast-search (regexp) | ||
(interactive "sSearch (regexp): ") | ||
(when djvu-image-mode | ||
(djvu-image-toggle)) | ||
(spacemacs/djvu-search-forward regexp)) | ||
|
||
(defun spacemacs/djvu-search-forward (query) | ||
"Search forward for match for REGEXP. | ||
Search case-sensitivity is determined by the value of the variable | ||
`case-fold-search', see Info node `(elisp)Searching and Case'. | ||
Use the command `djvu-search-forward-continue' to continue the search." | ||
(interactive "sQuery: ") | ||
(setq djvu-last-search-re query) | ||
(while (not (or (search-forward query nil t) | ||
(eq (djvu-ref page) (djvu-ref pagemax)))) | ||
(djvu-goto-page (let ((page (djvu-ref page)) | ||
(return 1)) | ||
(while (and (/= return 0) (< page (+ (djvu-ref pagemax) 1))) | ||
(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))) | ||
(setq page (1+ page))) | ||
(print page))))) | ||
|
||
(defun djvu-occur-next-entry-and-follow () | ||
(interactive) | ||
(evil-next-visual-line) | ||
(call-interactively 'djvu-occur-show-entry)) | ||
|
||
(defun djvu-occur-previous-entry-and-follow () | ||
(interactive) | ||
(evil-previous-visual-line) | ||
(call-interactively 'djvu-occur-show-entry)) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(configuration-layer/declare-layer 'spacemacs-evil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
;;; packages.el --- djvu layer packages file for Spacemacs. | ||
;; | ||
;; Copyright (c) 2021 Sylvain Benner & Contributors | ||
;; | ||
;; Author: Daniel Laurens Nicolai <dalanicolai@gmail.com> | ||
;; URL: https://github.com/syl20bnr/spacemacs | ||
;; | ||
;; This file is not part of GNU Emacs. | ||
;; | ||
;; 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/>. | ||
|
||
;;; Code: | ||
|
||
(defconst djvu-packages | ||
'(djvu | ||
tablist | ||
(djvu3 :location (recipe | ||
:fetcher github | ||
:repo "dalanicolai/djvu3")))) | ||
|
||
(defun djvu/init-djvu () | ||
(use-package djvu | ||
:defer t | ||
:magic ("%DJVU" . djvu-read-mode))) | ||
|
||
(defun djvu/init-tablist () | ||
(use-package tablist | ||
:defer t)) | ||
|
||
(defun djvu/init-djvu3 () | ||
(use-package djvu3 | ||
: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))))) | ||
|
||
: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 | ||
"j" 'spacemacs/djvu-scroll-up-or-next-page | ||
"k" 'spacemacs/djvu-scroll-down-or-previous-page | ||
"J" 'djvu-next-page | ||
"K" 'djvu-prev-page | ||
"g" 'djvu-goto-page | ||
"/" 'spacemacs/djvu-fast-search | ||
"n" 'djvu-re-search-forward-continue | ||
"H" 'djvu-history-backward | ||
"L" 'djvu-history-forward | ||
"c" '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 | ||
"h" 'djvu-keyboard-annot | ||
"d" 'djvu-toggle-invert | ||
"i" 'djvu-image-toggle | ||
"bs" 'djvu-switch-shared | ||
"bo" 'djvu-switch-outline | ||
"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 | ||
"o" 'djvu-switch-outline | ||
"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 | ||
"r" 'tablist-revert))) | ||
|
||
;;; packages.el ends here |