Fool around with converting pdfs to html for dirvish preview. Broken.

This commit is contained in:
MitchMarq42 2022-07-20 17:31:42 -08:00
parent 7987d82e35
commit 826c6543ec

View File

@ -109,20 +109,36 @@
(use-package dirvish (use-package dirvish
:straight (:files (:defaults "extensions/*.el")) :straight (:files (:defaults "extensions/*.el"))
:commands 'dirvish :commands 'dirvish
:custom (dirvish-attributes '(all-the-icons collapse))
:init (dirvish-override-dired-mode) :init (dirvish-override-dired-mode)
(setq dirvish-attributes '(all-the-icons collapse)) (defun convert-pdf-to-html (pdf)
(dirvish-define-preview exa (file) "Take PDF and convert it into a html file, which is returned.
"Use `exa' to generate directory preview." Requires `mutool' to be installed and available in $PATH (it comes with MuPDF)."
:require ("exa") ; tell Dirvish to check if we have the executable (let ((html (file-name-with-extension pdf ".html")))
(when (file-directory-p file) ; we only interest in directories here (shell-command (concat
`(shell . ("exa" "--color=always" "-al" ,file)))) ; use the command output as preview (format
(add-to-list 'dirvish-preview-dispatchers 'exa) "mutool convert -F html -O preserve-images -o '%s' "
html) (format "'%s'" pdf))) html))
(defun view-pdf-in-webkit (pdf)
"View PDF in BUFFER by using `mutool'. This works by converting it to a
html file and viewing that file in `xwidget-webkit'. Requires `mutool' to be
installed and available in $PATH (it comes with MuPDF). Also requires Emacs to
be built with `xwidget' support."
(xwidget-webkit-browse-url
(format "file://%s" (convert-pdf-to-html pdf))))
(dirvish-define-preview pdf (file ext)
"Use `mupdf' and `xwidget-webkit' to generate pdf preview."
:require ("mutool")
(when (equal ext "pdf")
(if (featurep 'xwidget webkit)
(view-pdf-in-webkit file))))
(add-to-list 'dirvish-preview-dispatchers 'pdf)
(setq dired-listing-switches "-l --almost-all") (setq dired-listing-switches "-l --almost-all")
:hook (dirvish-mode . turn-off-line-numbers) :hook (dirvish-mode . turn-off-line-numbers)
:general :general
(general-define-key (general-define-key
:states 'normal :states 'normal
:keymaps '(dirvish-mode-map local) :keymaps 'dirvish-mode-map
"h" 'dired-up-directory "h" 'dired-up-directory
"l" 'dired-find-file "l" 'dired-find-file
"/" 'dirvish-narrow) "/" 'dirvish-narrow)
@ -132,6 +148,8 @@
:prefix-map 'file-tree-map :prefix-map 'file-tree-map
:prefix "SPC t" :prefix "SPC t"
"t" 'dirvish-side)) "t" 'dirvish-side))
;; Completion framework... ;; Completion framework...
;; (use-package ivy ;; (use-package ivy
;; :diminish ;; :diminish
@ -288,11 +306,15 @@
(airline-display-directory t) (airline-display-directory t)
(airline-eshell-colors nil) (airline-eshell-colors nil)
(airline-shortened-directory-length 20) (airline-shortened-directory-length 20)
(airline-utf-glyph-separator-left 9585) ;; (airline-utf-glyph-separator-left 9585)
(airline-utf-glyph-separator-right 9586) ;; (airline-utf-glyph-separator-right 9586)
;; (airline-utf-glyph-separator-left "") (airline-utf-glyph-separator-left (string-to-char ""))
;; (airline-utf-glyph-separator-right "") (airline-utf-glyph-separator-right (string-to-char ""))
:custom-face (mode-line ((t (:box (:line-width 2 :style released-button))))) :custom-face
(mode-line
((t
(:box (:line-width 2 :style released-button)
(:height (:inherit 'fixed-pitch))))))
:config :config
;; (load-theme 'airline-kolor t) ;; (load-theme 'airline-kolor t)
(load-theme 'airline-ravenpower t)) (load-theme 'airline-ravenpower t))
@ -708,8 +730,8 @@
:custom (inferior-lisp-program "sbcl") :custom (inferior-lisp-program "sbcl")
:init (load (expand-file-name "~/quicklisp/slime-helper.el"))) :init (load (expand-file-name "~/quicklisp/slime-helper.el")))
(use-package nyan-mode ;; (use-package pdf-tools
:init (nyan-mode)) ;; :config (add-hook 'pdf-view-mode-hook 'turn-off-line-numbers))
(provide 'mitch-packages) (provide 'mitch-packages)
;;; mitch-packages.el ends here ;;; mitch-packages.el ends here