emacs-framebuffer

Emacs library to show images and documents in console using Linux framebuffer
Log | Files | Refs

commit e727d1ef6dd4896e7edfa66a44ac6d3b1191ad50
parent 464100a2b9b1b910e61b2206018a6e1e612e7477
Author: Tomas Hlavaty <tom@logand.com>
Date:   Wed, 26 Oct 2022 00:20:52 +0200

use cl-lib

Diffstat:
Memacs-framebuffer.el | 94++++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 47 insertions(+), 47 deletions(-)

diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -162,7 +162,7 @@ file)) (defun framebuffer-cache-abiword (format ifile ofile) - (case format + (cl-case format ((abw odt rtf doc docx) (unless (file-readable-p ofile) (call-process "abiword" nil nil nil @@ -240,12 +240,12 @@ (defun framebuffer-draw (x y w h sx sy sw sh file) (setq file (framebuffer-cache-remote file)) (let ((format (framebuffer-file-format file))) - (case format + (cl-case format (svg (setq file (framebuffer-cache-svg-to-png file))) ((abw odt rtf doc docx) (setq file (framebuffer-cache-to-pdf format file))))) - (case (framebuffer-file-format file) + (cl-case (framebuffer-file-format file) (pdf (setq file (framebuffer-cache-pdf-to-png file @@ -296,15 +296,15 @@ (insert-file-contents-literally file) (let* ((brook (framebuffer-buffer-brook)) (a (framebuffer-next-u8 brook))) - (case a + (cl-case a (?% ;; pdf - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?P - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?D - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?F - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?- (framebuffer-pdf-page-size file)))))))))) (137 ;; png @@ -352,8 +352,8 @@ ((?I ?M) ;; tiff (let ((b (framebuffer-next-u8 brook))) (when (= a b) - (multiple-value-bind (u16 u32) - (ecase a + (cl-multiple-value-bind (u16 u32) + (cl-ecase a (?I (values 'framebuffer-next-u16le 'framebuffer-next-u32le)) (?M (values 'framebuffer-next-u16 'framebuffer-next-u32))) (when (= #x2a (funcall u16 brook)) @@ -364,19 +364,19 @@ (type (funcall u16 brook)) (n (funcall u32 brook)) (v (funcall u32 brook))) - (case tag + (cl-case tag (#x0100 - (ecase type + (cl-ecase type (3 (setq w v)))) (#x0101 - (ecase type + (cl-ecase type (3 (setq h v))))))) (when (and w h) (cons w h)))))))) (?P ;; docx odt pbm pgm pnm ppm - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?K - (case (framebuffer-file-format file) + (cl-case (framebuffer-file-format file) (odt (framebuffer-pdf-page-size (framebuffer-cache-to-pdf 'odt file))) @@ -387,25 +387,25 @@ (search-forward-regexp "^\\([0-9]+\\) \\([0-9]+\\)$") (cons (read (match-string 1)) (read (match-string 2)))))) (?< ;; abw svg - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?s - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?v - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?g (framebuffer-image-size (framebuffer-cache-svg-to-png file))))))) (?? - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?x - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?m - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?l - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) ((? ) (let ((xml (xml-parse-file file))) - (ecase (caar xml) + (cl-ecase (caar xml) (svg (framebuffer-image-size (framebuffer-cache-svg-to-png file))) @@ -413,18 +413,18 @@ (framebuffer-pdf-page-size (framebuffer-cache-to-pdf 'abw file)))))))))))))))) (?{ ;; rtf - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?\\ - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?r - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?t - (case (framebuffer-next-u8 brook) + (cl-case (framebuffer-next-u8 brook) (?f (framebuffer-pdf-page-size (framebuffer-cache-to-pdf 'rtf file))))))))))) (t ;; doc xbm xpm - (case (framebuffer-file-format file) + (cl-case (framebuffer-file-format file) (doc (framebuffer-pdf-page-size (framebuffer-cache-to-pdf 'doc file))) @@ -442,8 +442,8 @@ (defun framebuffer-image-file (file) (interactive "fFile: ") (setq file (framebuffer-cache-remote file)) - (destructuring-bind (w &rest h) (framebuffer-image-size file) - (destructuring-bind (fw &rest fh) (framebuffer-size) + (cl-destructuring-bind (w &rest h) (framebuffer-image-size file) + (cl-destructuring-bind (fw &rest fh) (framebuffer-size) (let* ((scale (min (/ fw 1.0 w) (/ fh 1.0 h))) (ww (floor (* scale w))) (hh (floor (* scale h))) @@ -481,10 +481,10 @@ (interactive) (let ((buffer (or buffer (current-buffer))) (file (buffer-file-name))) - (destructuring-bind (w &rest h) framebuffer-image-mode-image-size - (destructuring-bind (fbw &rest fbh) (framebuffer-size) + (cl-destructuring-bind (w &rest h) framebuffer-image-mode-image-size + (cl-destructuring-bind (fbw &rest fbh) (framebuffer-size) (dolist (window (get-buffer-window-list buffer nil 'visible)) - (destructuring-bind (x1 y1 x2 y2) (window-edges window t) + (cl-destructuring-bind (x1 y1 x2 y2) (window-edges window t) (let* ((fw (frame-width)) (fh (frame-height)) (cw (floor fbw fw)) @@ -493,7 +493,7 @@ (wy (* y1 ch)) (ww (* (- x2 x1) cw)) (wh (* (- y2 y1) ch)) - (scale (ecase framebuffer-image-mode-scale + (scale (cl-ecase framebuffer-image-mode-scale (:fit-page (min (/ ww 1.0 w) (/ wh 1.0 h))) (:fit-width (/ ww 1.0 w)) (:fit-height (/ wh 1.0 h)))) @@ -524,7 +524,7 @@ (defun framebuffer-image-npages (file) (setq file (framebuffer-cache-remote file)) (let ((format (framebuffer-file-format file))) - (case format + (cl-case format (pdf (framebuffer-pdf-npages file)) ((abw odt rtf doc docx) @@ -663,7 +663,7 @@ (shell-quote-argument (expand-file-name filename))))) (defun framebuffer-hh:mm:ss (sec) - (etypecase sec + (cl-etypecase sec (string sec) (integer (let* ((m (mod sec 3600)) @@ -729,9 +729,9 @@ (defun framebuffer-draw-test () (interactive) - (destructuring-bind (fbw &rest fbh) (framebuffer-size) - (destructuring-bind (vw &rest vh) (framebuffer-virtual-size) - (destructuring-bind (x1 y1 x2 y2) (window-edges (get-buffer-window) t) + (cl-destructuring-bind (fbw &rest fbh) (framebuffer-size) + (cl-destructuring-bind (vw &rest vh) (framebuffer-virtual-size) + (cl-destructuring-bind (x1 y1 x2 y2) (window-edges (get-buffer-window) t) (let* ((fw (frame-width)) (fh (frame-height)) (stride (framebuffer-stride)) @@ -744,7 +744,7 @@ (with-temp-buffer (set-buffer-multibyte nil) (insert-file-contents-literally "/dev/fb0") - (ecase (framebuffer-bits-per-pixel) + (cl-ecase (framebuffer-bits-per-pixel) (32 (dotimes (y wh) (goto-char (+ (point-min) (* stride (+ y wy)) (* 4 wx))) @@ -765,8 +765,8 @@ (format-time-string "screenshot-%Y%m%d-%H%M%S.ppm") (or framebuffer-screenshot-directory (temporary-file-directory)))))) - (destructuring-bind (w &rest h) (framebuffer-size) - (destructuring-bind (vw &rest vh) (framebuffer-virtual-size) + (cl-destructuring-bind (w &rest h) (framebuffer-size) + (cl-destructuring-bind (vw &rest vh) (framebuffer-virtual-size) (with-temp-buffer (set-buffer-multibyte nil) (insert-file-contents-literally "/dev/fb0") @@ -775,11 +775,11 @@ (fb (current-buffer))) (with-temp-buffer (set-buffer-multibyte nil) - (ecase (framebuffer-file-format file) + (cl-ecase (framebuffer-file-format file) (pbm (insert "P4\n") (insert (format "%d %d\n" w h)) - (ecase bpp + (cl-ecase bpp (32 (dotimes (y h) (with-current-buffer fb @@ -795,7 +795,7 @@ a (char-after (goto-char (1+ (point))))) (goto-char (1+ (point)))) (setq n (+ (ash n 1) (if (plusp (+ r g b)) 1 0))) - (incf i) + (cl-incf i) (unless (< i 8) (insert n) (setq i 0 @@ -808,7 +808,7 @@ (insert "P5\n") (insert (format "%d %d\n" w h)) (insert "255\n") - (ecase bpp + (cl-ecase bpp (32 (dotimes (y h) (with-current-buffer fb @@ -828,7 +828,7 @@ (insert "P6\n") (insert (format "%d %d\n" w h)) (insert "255\n") - (ecase bpp + (cl-ecase bpp (32 (dotimes (y h) (with-current-buffer fb