(defvar sshot-geom-file "/tmp/sshot.geom") (defvar sshot-fname-prefix "/tmp/sshot/test") (defvar sshot-next 1)
(defun sshot-save-fvwm-script ()
(write-region "Current Exec sh -c \
'echo $[w.width]x$[w.height]+$[w.x]+$[w.y] > /tmp/sshot.geom'"
nil "/tmp/sshot.geom.fvwm"))
(defun sshot-save-tcl-script ()
(write-region "bind . <Key-q> {
puts [exec FvwmCommand {read /tmp/sshot.geom.fvwm}]; exit
}" nil "/tmp/sshot.geom.tcl"))
(defun sshot-save-geom-fvwm () (sshot-save-fvwm-script) (find-sh0
"FvwmCommand 'read /tmp/sshot.geom.fvwm'"))
(defun sshot-save-geom-tcl () (sshot-save-fvwm-script)
(sshot-save-tcl-script)
(find-sh0 "wish /tmp/sshot.geom.tcl"))
(defun sshot-force-geom (geom) (write-region geom nil "/tmp/sshot.geom"))
(defun sshot-save-geom () (sshot-save-geom-fvwm)) (defun sshot-geom () (ee-no-trailing-nl (ee-read-file sshot-geom-file)))
(defun sshot-n-to-fname (n) (format "%s_%03d.png" sshot-fname-prefix n))
(defun sshot-fname-next () (sshot-n-to-fname sshot-next))
(defun sshot-import-cmd ()
(format "import -window root -crop %s %s" (sshot-geom) (sshot-fname-next)))
(defun sshot-import () (find-sh0 (sshot-import-cmd)))
(defun sshot-next++ () (setq sshot-next (1+ sshot-next)))
(defun sshot-dir () (file-name-directory sshot-fname-prefix))
(defun sshot-mkdir () (make-directory (file-name-directory (sshot-dir)) t))
(defun sshot-fname-*png () (concat sshot-fname-prefix "*.png"))
(defun sshot-rm-v-shots () (find-sh0 (format "rm -v %s" (sshot-fname-*png))))
(defun sshot-next=1 () (setq sshot-next 1))
(defun sshot-cursor () (blink-cursor-mode 0))
(defun sshot-blink () (blink-cursor-mode 1))
(defun sshot-init (prefix) (interactive) (setq sshot-fname-prefix prefix)
(sshot-rm-v-shots) (sshot-mkdir) (sshot-next=1)
(sshot-cursor))
(defun sshot-take () (interactive) (sshot-import) (sshot-next++))
(defun sshot-read-file (f) (with-temp-buffer
(insert-file-contents-literally f)
(buffer-string)))
(defun sshot-read-file-n (n) (sshot-read-file (sshot-n-to-fname n)))
(defun sshot-equal-prev () (and (> sshot-next 2)
(equal (sshot-read-file-n (- sshot-next 1))
(sshot-read-file-n (- sshot-next 2)))))
(defun sshot-remove () (setq sshot-next (- sshot-next 1))
(delete-file (sshot-n-to-fname sshot-next)))
(defun sshot-remove* () (while (sshot-equal-prev) (sshot-remove)))
(defun sshot-take-unique () (interactive) (sshot-take) (sshot-remove*))
(defun sshot-aname (n) (format "<a name=\"%03d\"></a>" n))
(defun sshot-imgsrc (pr n) (format "<img src=\"%s_%03d.png\">" pr n))
(defun sshot-prev-text (n) (format "←%03d" n))
(defun sshot-prev-href (n) (format "<a href=\"#%03d\">←%03d</a>" n n))
(defun sshot-this-href (n) (format "<a href=\"#%03d\">%03d</a>" n n))
(defun sshot-next-text (n) (format "%03d→" n))
(defun sshot-next-href (n) (format "<a href=\"#%03d\">%03d→</a>" n n))
(defun sshot-image-html (prefix max n) (format "%s\n%s<br>\n%s %s %s<br>\n"
(sshot-aname n)
(sshot-imgsrc prefix n)
(if (<= n 1) (sshot-prev-text (- n 1)) (sshot-prev-href (- n 1)))
(sshot-this-href n)
(if (>= n max) (sshot-next-text (+ n 1)) (sshot-next-href (+ n 1)))))
(defun sshot-images-html (prefix max) (mapconcat
(lambda (n) (sshot-image-html prefix max n))
(number-sequence 1 max)
"<br>\n\n"))
(defun sshot-html-wrap (title body tail)
(format "<html>\n%s\n%s</html>\n"
(format "<head>\n<title>%s</title>\n</head>" title)
(format "<body bgcolor=\"#4C4C4C\">\n\n%s\n%s\n</body>" body tail)))
(defun sshot-mkstr (s n) (mapconcat (lambda (n) s) (number-sequence 1 n) ""))
(defun sshot-html-3 (title prefix max) (sshot-html-wrap title
(sshot-images-html prefix max)
(sshot-mkstr "<br>\n" 40)))
(defun sshot-stem () (file-name-nondirectory sshot-fname-prefix))
(defun sshot-fname-html () (format "%s.html" sshot-fname-prefix))
(defun sshot-title-html () (format "flipbook: %s" (sshot-stem)))
(defun sshot-html-0 () (sshot-html-3 (sshot-title-html) (sshot-stem)
(- sshot-next 1)))
(defun sshot-write-html () (write-region (sshot-html-0) nil (sshot-fname-html)))
(defun sshot-take+ () (interactive) (sshot-take-unique) (sshot-write-html))
(defvar sshot-view-mode-map (make-sparse-keymap))
(define-key sshot-view-mode-map (kbd "<left>") 'sshot-open-prev)
(define-key sshot-view-mode-map (kbd "<right>") 'sshot-open-next)
(define-key sshot-view-mode-map (kbd "q") 'sshot-bury-all)
(define-minor-mode sshot-view-mode
"Navigate through screenshots with <left> and <right>."
nil " sshot-view" sshot-view-mode-map)
(defvar sshot-this nil) (defvar sshot-view-prefix nil) (make-variable-buffer-local 'sshot-this)
(make-variable-buffer-local 'sshot-view-prefix)
(defun sshot-message () "sshot-view-mode - navigate with <left>, <right>, q")
(defun sshot-pn-to-fname (p n) (format "%s_%03d.png" p n))
(defun sshot-exists-p (p n) (file-exists-p (sshot-pn-to-fname p n)))
(defun sshot-not-found (p n) (error "Not found: %s" (sshot-pn-to-fname p n)))
(defun sshot-assert (p n) (or (sshot-exists-p p n) (sshot-not-found p n)))
(defun sshot-open (p n) (sshot-assert p n)
(find-file (sshot-pn-to-fname p n))
(sshot-view-mode 1)
(setq sshot-view-prefix p sshot-this n)
(message (sshot-message)))
(defun sshot-open-prev () (interactive)
(sshot-open sshot-view-prefix (- sshot-this 1)))
(defun sshot-open-next () (interactive)
(sshot-open sshot-view-prefix (+ sshot-this 1)))
(defun sshot-bury-all () (interactive) (let ((p sshot-view-prefix))
(if p (while (equal p sshot-view-prefix)
(bury-buffer)))))
(defun find-sshot (p n) (sshot-open p n) (sshot-message))
(provide 'eev-sshot)