diff options
| author | Stefan Kangas | 2021-11-08 06:42:44 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2021-11-08 07:37:48 +0100 |
| commit | cc093b03e06c9ef5b4a1493b6fcf864f119702ef (patch) | |
| tree | e57bf884904808014e2ed2f9f8ae42938c773150 | |
| parent | 553e4b74f763077b72b9232c1a1b595b6302038f (diff) | |
| download | emacs-cc093b03e06c9ef5b4a1493b6fcf864f119702ef.tar.gz emacs-cc093b03e06c9ef5b4a1493b6fcf864f119702ef.zip | |
; * lisp/image-dired.el: Add some basic sections.
This file is currently rather hard to follow due to things just being
thrown in at random by many different contributors, with seemingly no
overall plan or idea. This is the first step towards giving it some
kind of organization.
| -rw-r--r-- | lisp/image-dired.el | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/lisp/image-dired.el b/lisp/image-dired.el index b67e1e7888f..a2c37f00f23 100644 --- a/lisp/image-dired.el +++ b/lisp/image-dired.el | |||
| @@ -152,6 +152,9 @@ | |||
| 152 | (require 'cl-lib) | 152 | (require 'cl-lib) |
| 153 | (require 'wid-edit)) | 153 | (require 'wid-edit)) |
| 154 | 154 | ||
| 155 | |||
| 156 | ;;; Customizable variables | ||
| 157 | |||
| 155 | (defgroup image-dired nil | 158 | (defgroup image-dired nil |
| 156 | "Use Dired to browse your images as thumbnails, and more." | 159 | "Use Dired to browse your images as thumbnails, and more." |
| 157 | :prefix "image-dired-" | 160 | :prefix "image-dired-" |
| @@ -216,8 +219,6 @@ https://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html | |||
| 216 | "Database file where file names and their associated tags are stored." | 219 | "Database file where file names and their associated tags are stored." |
| 217 | :type 'file) | 220 | :type 'file) |
| 218 | 221 | ||
| 219 | |||
| 220 | |||
| 221 | (defcustom image-dired-cmd-create-thumbnail-program | 222 | (defcustom image-dired-cmd-create-thumbnail-program |
| 222 | (if (executable-find "gm") "gm" "convert") | 223 | (if (executable-find "gm") "gm" "convert") |
| 223 | "Executable used to create thumbnail. | 224 | "Executable used to create thumbnail. |
| @@ -498,6 +499,9 @@ variable is nil, it will never ask." | |||
| 498 | (const :tag "Disable warning" nil)) | 499 | (const :tag "Disable warning" nil)) |
| 499 | :version "29.1") | 500 | :version "29.1") |
| 500 | 501 | ||
| 502 | |||
| 503 | ;;; Util functions | ||
| 504 | |||
| 501 | (defvar image-dired-debug nil | 505 | (defvar image-dired-debug nil |
| 502 | "Non-nil means enable debug messages.") | 506 | "Non-nil means enable debug messages.") |
| 503 | 507 | ||
| @@ -622,6 +626,9 @@ See also `image-dired-thumbnail-storage'." | |||
| 622 | (unless (executable-find (symbol-value executable)) | 626 | (unless (executable-find (symbol-value executable)) |
| 623 | (error "Executable %S not found" executable))) | 627 | (error "Executable %S not found" executable))) |
| 624 | 628 | ||
| 629 | |||
| 630 | ;;; Creating thumbnails | ||
| 631 | |||
| 625 | (defun image-dired-thumb-size (dimension) | 632 | (defun image-dired-thumb-size (dimension) |
| 626 | "Return thumb size depending on `image-dired-thumbnail-storage'. | 633 | "Return thumb size depending on `image-dired-thumbnail-storage'. |
| 627 | DIMENSION should be either the symbol `width' or `height'." | 634 | DIMENSION should be either the symbol `width' or `height'." |
| @@ -651,8 +658,6 @@ consider setting `image-dired-debug' to a non-nil value to see | |||
| 651 | the time spent on generating thumbnails. Run `image-clear-cache' | 658 | the time spent on generating thumbnails. Run `image-clear-cache' |
| 652 | and remove the cached thumbnail files between each trial run.") | 659 | and remove the cached thumbnail files between each trial run.") |
| 653 | 660 | ||
| 654 | (defvar image-dired-tag-history nil "Variable holding the tag history.") | ||
| 655 | |||
| 656 | (defun image-dired-pngnq-thumb (spec) | 661 | (defun image-dired-pngnq-thumb (spec) |
| 657 | "Quantize thumbnail described by format SPEC with pngnq(1)." | 662 | "Quantize thumbnail described by format SPEC with pngnq(1)." |
| 658 | (let ((process | 663 | (let ((process |
| @@ -1064,6 +1069,9 @@ never ask for confirmation." | |||
| 1064 | ;;;###autoload | 1069 | ;;;###autoload |
| 1065 | (defalias 'image-dired 'image-dired-show-all-from-dir) | 1070 | (defalias 'image-dired 'image-dired-show-all-from-dir) |
| 1066 | 1071 | ||
| 1072 | |||
| 1073 | ;;; Tags | ||
| 1074 | |||
| 1067 | (defun image-dired-sane-db-file () | 1075 | (defun image-dired-sane-db-file () |
| 1068 | "Check if `image-dired-db-file' exists. | 1076 | "Check if `image-dired-db-file' exists. |
| 1069 | If not, try to create it (including any parent directories). | 1077 | If not, try to create it (including any parent directories). |
| @@ -1082,6 +1090,8 @@ Signal error if there are problems creating it." | |||
| 1082 | (file-exists-p image-dired-db-file)) | 1090 | (file-exists-p image-dired-db-file)) |
| 1083 | (error "Could not create %s" image-dired-db-file))) | 1091 | (error "Could not create %s" image-dired-db-file))) |
| 1084 | 1092 | ||
| 1093 | (defvar image-dired-tag-history nil "Variable holding the tag history.") | ||
| 1094 | |||
| 1085 | (defun image-dired-write-tags (file-tags) | 1095 | (defun image-dired-write-tags (file-tags) |
| 1086 | "Write file tags to database. | 1096 | "Write file tags to database. |
| 1087 | Write each file and tag in FILE-TAGS to the database. | 1097 | Write each file and tag in FILE-TAGS to the database. |
| @@ -1202,6 +1212,9 @@ With prefix argument ARG, remove tag from file at point." | |||
| 1202 | (image-dired-update-property | 1212 | (image-dired-update-property |
| 1203 | 'tags (image-dired-list-tags (image-dired-original-file-name)))))) | 1213 | 'tags (image-dired-list-tags (image-dired-original-file-name)))))) |
| 1204 | 1214 | ||
| 1215 | |||
| 1216 | ;;; Thumbnail mode (cont.) | ||
| 1217 | |||
| 1205 | (defun image-dired-original-file-name () | 1218 | (defun image-dired-original-file-name () |
| 1206 | "Get original file name for thumbnail or display image at point." | 1219 | "Get original file name for thumbnail or display image at point." |
| 1207 | (get-text-property (point) 'original-file-name)) | 1220 | (get-text-property (point) 'original-file-name)) |
| @@ -1654,6 +1667,9 @@ Use `image-dired-minor-mode' to get a nice setup." | |||
| 1654 | ;; Use approximately as much vertical spacing as horizontal. | 1667 | ;; Use approximately as much vertical spacing as horizontal. |
| 1655 | (setq-local line-spacing (frame-char-width))) | 1668 | (setq-local line-spacing (frame-char-width))) |
| 1656 | 1669 | ||
| 1670 | |||
| 1671 | ;;; Display image mode | ||
| 1672 | |||
| 1657 | (define-derived-mode image-dired-display-image-mode | 1673 | (define-derived-mode image-dired-display-image-mode |
| 1658 | image-mode "image-dired-image-display" | 1674 | image-mode "image-dired-image-display" |
| 1659 | "Mode for displaying and manipulating original image. | 1675 | "Mode for displaying and manipulating original image. |
| @@ -1741,6 +1757,9 @@ With prefix argument ARG, create thumbnails even if they already exist | |||
| 1741 | arg) | 1757 | arg) |
| 1742 | (image-dired-create-thumb curr-file thumb-name))))) | 1758 | (image-dired-create-thumb curr-file thumb-name))))) |
| 1743 | 1759 | ||
| 1760 | |||
| 1761 | ;;; Slideshow. | ||
| 1762 | |||
| 1744 | (defvar image-dired-slideshow-timer nil | 1763 | (defvar image-dired-slideshow-timer nil |
| 1745 | "Slideshow timer.") | 1764 | "Slideshow timer.") |
| 1746 | 1765 | ||
| @@ -1778,6 +1797,9 @@ Ask user for number of images to show and the delay in between." | |||
| 1778 | (interactive) | 1797 | (interactive) |
| 1779 | (cancel-timer image-dired-slideshow-timer)) | 1798 | (cancel-timer image-dired-slideshow-timer)) |
| 1780 | 1799 | ||
| 1800 | |||
| 1801 | ;;; Thumbnail mode (cont. 3) | ||
| 1802 | |||
| 1781 | (defun image-dired-delete-char () | 1803 | (defun image-dired-delete-char () |
| 1782 | "Remove current thumbnail from thumbnail buffer and line up." | 1804 | "Remove current thumbnail from thumbnail buffer and line up." |
| 1783 | (interactive nil image-dired-thumbnail-mode) | 1805 | (interactive nil image-dired-thumbnail-mode) |
| @@ -2008,6 +2030,9 @@ overwritten. This confirmation can be turned off using | |||
| 2008 | (interactive) | 2030 | (interactive) |
| 2009 | (image-dired-rotate-original "90")) | 2031 | (image-dired-rotate-original "90")) |
| 2010 | 2032 | ||
| 2033 | |||
| 2034 | ;;; EXIF support | ||
| 2035 | |||
| 2011 | (defun image-dired-get-exif-file-name (file) | 2036 | (defun image-dired-get-exif-file-name (file) |
| 2012 | "Use the image's EXIF information to return a unique file name. | 2037 | "Use the image's EXIF information to return a unique file name. |
| 2013 | The file name should be unique as long as you do not take more than | 2038 | The file name should be unique as long as you do not take more than |
| @@ -2088,6 +2113,8 @@ function. The result is a couple of new files in | |||
| 2088 | (copy-file curr-file new-name)) | 2113 | (copy-file curr-file new-name)) |
| 2089 | files))) | 2114 | files))) |
| 2090 | 2115 | ||
| 2116 | ;;; Thumbnail mode (cont.) | ||
| 2117 | |||
| 2091 | (defun image-dired-display-next-thumbnail-original (&optional arg) | 2118 | (defun image-dired-display-next-thumbnail-original (&optional arg) |
| 2092 | "In thumbnail buffer, move to next thumbnail and display the image. | 2119 | "In thumbnail buffer, move to next thumbnail and display the image. |
| 2093 | With prefix ARG, move that many thumbnails." | 2120 | With prefix ARG, move that many thumbnails." |
| @@ -2101,6 +2128,9 @@ With prefix ARG, move that many thumbnails." | |||
| 2101 | (interactive "p" image-dired-thumbnail-mode) | 2128 | (interactive "p" image-dired-thumbnail-mode) |
| 2102 | (image-dired-display-next-thumbnail-original (- arg))) | 2129 | (image-dired-display-next-thumbnail-original (- arg))) |
| 2103 | 2130 | ||
| 2131 | |||
| 2132 | ;;; Image Comments | ||
| 2133 | |||
| 2104 | (defun image-dired-write-comments (file-comments) | 2134 | (defun image-dired-write-comments (file-comments) |
| 2105 | "Write file comments to database. | 2135 | "Write file comments to database. |
| 2106 | Write file comments to one or more files. | 2136 | Write file comments to one or more files. |
| @@ -2227,6 +2257,10 @@ matching tag will be marked in the Dired buffer." | |||
| 2227 | (dired-mark 1)))) | 2257 | (dired-mark 1)))) |
| 2228 | (message "%d files with matching tag marked." hits))) | 2258 | (message "%d files with matching tag marked." hits))) |
| 2229 | 2259 | ||
| 2260 | |||
| 2261 | |||
| 2262 | ;;; Mouse support | ||
| 2263 | |||
| 2230 | (defun image-dired-mouse-display-image (event) | 2264 | (defun image-dired-mouse-display-image (event) |
| 2231 | "Use mouse EVENT, call `image-dired-display-image' to display image. | 2265 | "Use mouse EVENT, call `image-dired-display-image' to display image. |
| 2232 | Track this in associated Dired buffer if `image-dired-track-movement' is | 2266 | Track this in associated Dired buffer if `image-dired-track-movement' is |
| @@ -2255,6 +2289,10 @@ non-nil." | |||
| 2255 | (image-dired-track-original-file)) | 2289 | (image-dired-track-original-file)) |
| 2256 | (image-dired-display-thumb-properties)) | 2290 | (image-dired-display-thumb-properties)) |
| 2257 | 2291 | ||
| 2292 | |||
| 2293 | |||
| 2294 | ;;; Dired marks and tags | ||
| 2295 | |||
| 2258 | (defun image-dired-thumb-file-marked-p (&optional flagged) | 2296 | (defun image-dired-thumb-file-marked-p (&optional flagged) |
| 2259 | "Check if file is marked in associated Dired buffer. | 2297 | "Check if file is marked in associated Dired buffer. |
| 2260 | If optional argument FLAGGED is non-nil, check if file is flagged | 2298 | If optional argument FLAGGED is non-nil, check if file is flagged |
| @@ -2347,7 +2385,8 @@ Track this in associated Dired buffer if | |||
| 2347 | comment))))) | 2385 | comment))))) |
| 2348 | 2386 | ||
| 2349 | 2387 | ||
| 2350 | ;;;; Gallery support | 2388 | |
| 2389 | ;;; Gallery support | ||
| 2351 | 2390 | ||
| 2352 | ;; TODO: | 2391 | ;; TODO: |
| 2353 | ;; * Support gallery creation when using per-directory thumbnail | 2392 | ;; * Support gallery creation when using per-directory thumbnail |
| @@ -2581,7 +2620,7 @@ when using per-directory thumbnail file storage")) | |||
| 2581 | (insert "</html>")))) | 2620 | (insert "</html>")))) |
| 2582 | 2621 | ||
| 2583 | 2622 | ||
| 2584 | ;;;; Tag support | 2623 | ;;; Tag support |
| 2585 | 2624 | ||
| 2586 | (defvar image-dired-widget-list nil | 2625 | (defvar image-dired-widget-list nil |
| 2587 | "List to keep track of meta data in edit buffer.") | 2626 | "List to keep track of meta data in edit buffer.") |
| @@ -2685,7 +2724,7 @@ tags to their respective image file. Internal function used by | |||
| 2685 | (push (cons file tag) lst)))))) | 2724 | (push (cons file tag) lst)))))) |
| 2686 | 2725 | ||
| 2687 | 2726 | ||
| 2688 | ;;;; bookmark.el support | 2727 | ;;; bookmark.el support |
| 2689 | 2728 | ||
| 2690 | (declare-function bookmark-make-record-default | 2729 | (declare-function bookmark-make-record-default |
| 2691 | "bookmark" (&optional no-file no-context posn)) | 2730 | "bookmark" (&optional no-file no-context posn)) |
| @@ -2716,7 +2755,7 @@ tags to their respective image file. Internal function used by | |||
| 2716 | (goto-char (point-min)))) | 2755 | (goto-char (point-min)))) |
| 2717 | 2756 | ||
| 2718 | 2757 | ||
| 2719 | ;;;; Obsolete | 2758 | ;;; Obsolete |
| 2720 | 2759 | ||
| 2721 | ;;;###autoload | 2760 | ;;;###autoload |
| 2722 | (define-obsolete-function-alias 'tumme #'image-dired "24.4") | 2761 | (define-obsolete-function-alias 'tumme #'image-dired "24.4") |