emacs-framebuffer

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

commit e99f1fc059555a07291c6b437f3feb0c39ad404c
parent e75ca19318dcfaef7750b422baa5463125638e7f
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sat, 17 Oct 2020 19:49:02 +0200

more robust w3mimgdisplay invocation

on debian 10:
- the program is not in the path
- W3M_TTY needs to be set

Diffstat:
Memacs-framebuffer.el | 43++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -25,6 +25,11 @@ ;;; (require 'framebuffer) ;;; (framebuffer-install)) +(defcustom framebuffer-w3mimgdisplay-program nil + "Specify the path to w3mimgdisplay program." + :type 'string + :group 'framebuffer) + (defcustom framebuffer-width nil "Specify the framebuffer width." :type 'number @@ -159,6 +164,26 @@ (call-process "convert" nil nil nil (expand-file-name file) ofile)) ofile)) +(defun framebuffer-tty-p (filename) + (when (string-match "^/dev/tty[0-9]+$" filename) + filename)) + +(defvar framebuffer-tty nil) +(defun framebuffer-tty () + (or framebuffer-tty + (setq framebuffer-tty + (framebuffer-tty-p + (file-chase-links (format "/proc/%d/fd/0" (emacs-pid))))))) + +(defun framebuffer-file-exists-p (filename) + (when (file-exists-p filename) + filename)) + +(defun framebuffer-w3mimgdisplay-program () + (or framebuffer-w3mimgdisplay-program + (framebuffer-file-exists-p "/usr/lib/w3m/w3mimgdisplay") ;; debian10 + "w3mimgdisplay")) + (defun framebuffer-draw (x y w h sx sy sw sh file) (let ((format (framebuffer-file-format file))) (case format @@ -175,7 +200,23 @@ (insert (format "0;1;%d;%d;%d;%d;%s;%s;%s;%s;%s\n" x y w h (or sx "") (or sy "") (or sw "") (or sh "") (expand-file-name file))) - (call-process-region (point-min) (point-max) "w3mimgdisplay"))) + (let ((z (call-process-region (point-min) + (point-max) + (framebuffer-w3mimgdisplay-program)))) + (unless (zerop z) + (if (getenv "W3M_TTY") + (error "w3mimgdisplay failed with code %d" z) + (let ((tty (framebuffer-tty))) + (cond + (tty + (setenv "W3M_TTY" tty) + (let ((z (call-process-region (point-min) + (point-max) + (framebuffer-w3mimgdisplay-program)))) + (unless (zerop z) + (error "w3mimgdisplay failed with code %d, try setting W3M_TTY=$(tty)" z)))) + (t + (error "w3mimgdisplay failed with code %d, try setting W3M_TTY=$(tty)" z))))))))) (defun framebuffer-buffer-brook () (lambda ()