diff options
Diffstat (limited to 'emacs/.emacs.d/lisp/my/infobox.el')
-rw-r--r-- | emacs/.emacs.d/lisp/my/infobox.el | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/emacs/.emacs.d/lisp/my/infobox.el b/emacs/.emacs.d/lisp/my/infobox.el index 518c7db..ff4adb6 100644 --- a/emacs/.emacs.d/lisp/my/infobox.el +++ b/emacs/.emacs.d/lisp/my/infobox.el @@ -27,6 +27,17 @@ ;;; Code: +(defun infobox-transform-field-value (v) + (cond ((stringp v) v) + ((eq v t) "YES") + ((eq v :json-false) "NO") + ((seqp v) + (mapconcat + (lambda (x) (if (stringp x) x (prin1-to-string x))) + v + ", ")) + (t (format "%s" v)))) + (defun infobox-default-specs (info) (seq-map (lambda (pair) @@ -47,7 +58,7 @@ something like (lambda (pair) (when-let ((val (alist-get (car pair) info))) (if (or (stringp (cdr pair)) (symbolp (cdr pair))) - (cons (cdr pair) val) + (cons (cdr pair) (infobox-transform-field-value val)) (cons (cadr pair) (funcall (cddr pair) val))))) specs)) @@ -56,6 +67,22 @@ something like (with-help-window "*infobox*" (with-current-buffer standard-output (let ((n-rows 0)) + ;; TODO: use a more standard function than + ;; `my-make-filename-from-url' + (when-let* ((thumb-url (alist-get "Thumbnail" info nil nil 'equal)) + (file-name + (if (string-prefix-p "file://" thumb-url) + (string-remove-prefix "file://" thumb-url) + (make-temp-name "/tmp/infobox-")))) + (unless (string-prefix-p "file://" thumb-url) + (url-copy-file thumb-url file-name t)) + (insert-image (create-image file-name nil nil + :max-width (window-pixel-width) + :max-height (/ (window-pixel-height) 2))) + (insert "\n") + (setq n-rows (1+ n-rows)) + (setq info (assoc-delete-all "Thumbnail" info)) + ) (seq-do (lambda (pair) (when pair @@ -90,6 +117,13 @@ something like (infobox-render-string (with-temp-buffer (call-process "exiftool" nil t nil filename) + (goto-char (point-min)) + (flush-lines "ExifTool Version") + (end-of-line) + (insert " -- " (buttonize + "xdg-open" + (lambda (_) (call-process "xdg-open" nil 0 nil filename))) + " " (buttonize "find-file" (lambda (_) (find-file filename)))) (buffer-string)) `(infobox-exiftool ,filename) (called-interactively-p 'interactive) @@ -137,9 +171,4 @@ something like (lambda (line) (string-match-p "^[0-9]" line)) (split-string (buffer-string) "\n")))) -(defun my-call-process-out (command &rest args) - (with-temp-buffer - (apply 'call-process (append (list command nil t nil) args)) - (buffer-string))) - (provide 'infobox) |