From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61394: 30.0.50; [PATCH] Image-dired thumb name based on content Date: Thu, 27 Jul 2023 15:52:55 +0200 Message-ID: <87fs59qx54.fsf@ledu-giraud.fr> References: <874jruy7xx.fsf@ledu-giraud.fr> <87ttztk0yw.fsf@tcd.ie> <87v8k9s6j9.fsf@ledu-giraud.fr> <83ilg8jzti.fsf@gnu.org> <87k00oo03r.fsf@ledu-giraud.fr> <838rh4jlsq.fsf@gnu.org> <87bklzol8n.fsf@ledu-giraud.fr> <877cwmo8ij.fsf@ledu-giraud.fr> <87y1oz54bn.fsf@ledu-giraud.fr> <87wn4dra0h.fsf@ledu-giraud.fr> <87bklhtwhd.fsf@ledu-giraud.fr> <871qgumqh7.fsf@ledu-giraud.fr> <83ila5n8co.fsf@gnu.org> Reply-To: Manuel Giraud Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25009"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: contovob@tcd.ie, stefankangas@gmail.com, 61394@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 27 16:00:20 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qP1XQ-0006I8-DY for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 27 Jul 2023 16:00:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP1RR-0002JI-CA; Thu, 27 Jul 2023 09:54:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP1RK-0002Go-Qp for bug-gnu-emacs@gnu.org; Thu, 27 Jul 2023 09:54:03 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qP1RJ-0004N8-RC for bug-gnu-emacs@gnu.org; Thu, 27 Jul 2023 09:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qP1RJ-0004fj-NK for bug-gnu-emacs@gnu.org; Thu, 27 Jul 2023 09:54:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 27 Jul 2023 13:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61394 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 61394-submit@debbugs.gnu.org id=B61394.169046598417880 (code B ref 61394); Thu, 27 Jul 2023 13:54:01 +0000 Original-Received: (at 61394) by debbugs.gnu.org; 27 Jul 2023 13:53:04 +0000 Original-Received: from localhost ([127.0.0.1]:40994 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qP1QN-0004eK-B4 for submit@debbugs.gnu.org; Thu, 27 Jul 2023 09:53:03 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:47059) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qP1QJ-0004dl-Nr for 61394@debbugs.gnu.org; Thu, 27 Jul 2023 09:53:01 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=lkR+e6VL l8oDSAuDie0aj9xY9TaIfJwGE6xLgAhS1MQ=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=PKkUyRiYVzqDNd5BvQDWuBokam/vkC 1w1Yh/67pyPkS2GbEaV2fPxuVLwITuaa9Qz0Dhd5K8GomlXtLnI7L+Ag== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=lkR+e6VLl8oDSAuD ie0aj9xY9TaIfJwGE6xLgAhS1MQ=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=yz5nN+trbsAYeuzDYg1bZPU0NXsg50+hA1qK05 craJIg434F+s6aVXZdooxwXITJt3ZzKTWIucWxybp3WvhIlRwRD/qhgE4a0ExnwcHb4tjU 9BlN91rQoUb5i1ktc6tD6Q0zPD11ZrJMOyBSRMb2Sk18sIhPqYf++dKvIPnizQqdLRYlEW XE1v1fJcHKgp5zihMOHxRL7M1qteFZP+lboh9iPhIAJsWN3WUOvHolsgHyubS7RASqcy87 bdiUoGiOGPN4sdY3+hNHpB6b5E8Pc/7YwaXU9r/Lsa4ijfCPiJlTNuNbO1b0C8VTVtO56t 3giNYQvLwUTsbGGwWUqFx0Pg== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id fd6149ec (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 27 Jul 2023 15:52:57 +0200 (CEST) In-Reply-To: <83ila5n8co.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 27 Jul 2023 10:04:23 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:266191 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > Thanks for the reminder. I think we should install this now. So > please rebase on the current master branch and repost, and I will > install it then. Thanks. Here is the rebased version of the patch. -- Manuel Giraud --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-New-option-image-dired-thumb-naming-bug-61394.patch >From 83002e2cda2c3c8c28b2e37837625709fc4ca233 Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Sat, 25 Feb 2023 19:27:07 +0100 Subject: [PATCH] New option 'image-dired-thumb-naming' (bug#61394) * lisp/image/image-dired.el (image-dired-thumb-naming): New user option to control thumbnail name. * lisp/image/image-dired-util.el (image-dired-thumb-name): Update to use new user option and compute contents SHA-1 if needed. (image-dired-contents-sha1): New function to compute the SHA-1 of the first 4KiB of a file. --- etc/NEWS | 5 ++ lisp/image/image-dired-util.el | 84 +++++++++++++++++++++------------- lisp/image/image-dired.el | 26 ++++++++++- 3 files changed, 80 insertions(+), 35 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index d0dab755212..a8e7d97df7e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -567,6 +567,11 @@ Similarly to buffer restoration by Desktop, 'recentf-mode' checking of the accessibility of remote files can now time out if 'remote-file-name-access-timeout' is set to a positive number. +** Image Dired + +*** New user option 'image-dired-thumb-naming'. +You can now configure how a thumbnail is named using this option. + * New Modes and Packages in Emacs 30.1 diff --git a/lisp/image/image-dired-util.el b/lisp/image/image-dired-util.el index a80b3afc0f3..3f6880fc807 100644 --- a/lisp/image/image-dired-util.el +++ b/lisp/image/image-dired-util.el @@ -30,6 +30,7 @@ (eval-when-compile (require 'cl-lib)) (defvar image-dired-dir) +(defvar image-dired-thumb-naming) (defvar image-dired-thumbnail-storage) (defconst image-dired--thumbnail-standard-sizes @@ -57,42 +58,59 @@ image-dired-dir (message "Thumbnail directory created: %s" image-dired-dir)) image-dired-dir)) +(defun image-dired-contents-sha1 (filename) + "Compute the SHA-1 of the first 4KiB of FILENAME's contents." + (with-temp-buffer + (insert-file-contents-literally filename nil 0 4096) + (sha1 (current-buffer)))) + (defun image-dired-thumb-name (file) "Return absolute file name for thumbnail FILE. -Depending on the value of `image-dired-thumbnail-storage', the -file name of the thumbnail will vary: -- For `use-image-dired-dir', make a SHA1-hash of the image file's - directory name and add that to make the thumbnail file name - unique. -- For `per-directory' storage, just add a subdirectory. -- For `standard' storage, produce the file name according to the - Thumbnail Managing Standard. Among other things, an MD5-hash - of the image file's directory name will be added to the - filename. -See also `image-dired-thumbnail-storage'." +Depending on the value of `image-dired-thumbnail-storage' and +`image-dired-thumb-naming', the file name of the thumbnail will +vary: + +- If `image-dired-thumbnail-storage' is set to one of the value + of `image-dired--thumbnail-standard-sizes', produce the file + name according to the Thumbnail Managing Standard. Among other + things, an MD5-hash of the image file's directory name will be + added to the file name. + +- Otherwise `image-dired-thumbnail-storage' is used to set the + directory where to store the thumbnail. In this latter case + the name given to the thumbnail depends on the value of + `image-dired-thumb-naming'. + +See also `image-dired-thumbnail-storage' and +`image-dired-thumb-naming'." (let ((file (expand-file-name file))) - (cond ((memq image-dired-thumbnail-storage - image-dired--thumbnail-standard-sizes) - (let ((thumbdir (cl-case image-dired-thumbnail-storage - (standard "thumbnails/normal") - (standard-large "thumbnails/large") - (standard-x-large "thumbnails/x-large") - (standard-xx-large "thumbnails/xx-large")))) - (expand-file-name - ;; MD5 is mandated by the Thumbnail Managing Standard. - (concat (md5 (concat "file://" file)) ".png") - (expand-file-name thumbdir (xdg-cache-home))))) - ((or (eq 'image-dired image-dired-thumbnail-storage) - ;; Maintained for backwards compatibility: - (eq 'use-image-dired-dir image-dired-thumbnail-storage)) - (expand-file-name (format "%s.jpg" (sha1 file)) - (image-dired-dir))) - ((eq 'per-directory image-dired-thumbnail-storage) - (expand-file-name (format "%s.thumb.jpg" - (file-name-nondirectory file)) - (expand-file-name - ".image-dired" - (file-name-directory file))))))) + (if (memq image-dired-thumbnail-storage + image-dired--thumbnail-standard-sizes) + (let ((thumbdir (cl-case image-dired-thumbnail-storage + (standard "thumbnails/normal") + (standard-large "thumbnails/large") + (standard-x-large "thumbnails/x-large") + (standard-xx-large "thumbnails/xx-large")))) + (expand-file-name + ;; MD5 and PNG is mandated by the Thumbnail Managing + ;; Standard. + (concat (md5 (concat "file://" file)) ".png") + (expand-file-name thumbdir (xdg-cache-home)))) + (let ((name (if (eq 'sha1-contents image-dired-thumb-naming) + (image-dired-contents-sha1 file) + ;; Defaults to SHA-1 of file name + (if (eq 'per-directory image-dired-thumbnail-storage) + (sha1 (file-name-nondirectory file)) + (sha1 file))))) + (cond ((or (eq 'image-dired image-dired-thumbnail-storage) + ;; Maintained for backwards compatibility: + (eq 'use-image-dired-dir image-dired-thumbnail-storage)) + (expand-file-name (format "%s.jpg" name) (image-dired-dir))) + ((eq 'per-directory image-dired-thumbnail-storage) + (expand-file-name (format "%s.jpg" name) + (expand-file-name + ".image-dired" + (file-name-directory file))))))))) (defvar image-dired-thumbnail-buffer "*image-dired*" "Image-Dired's thumbnail buffer.") diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el index b13b3e08ce2..96a0c2ef9bc 100644 --- a/lisp/image/image-dired.el +++ b/lisp/image/image-dired.el @@ -162,8 +162,27 @@ image-dired-dir `image-dired-thumbnail-storage'." :type 'directory) +(defcustom image-dired-thumb-naming 'sha1-filename + "How `image-dired' names thumbnail files. +When set to `sha1-filename' the name of thumbnail is built by +computing the SHA-1 of the full file name of the image. + +When set to `sha1-contents' the name of thumbnail is built by +computing the SHA-1 of first 4KiB of the image contents (See +`image-dired-contents-sha1'). + +In both case, a \"jpg\" extension is appended to save as JPEG. + +The value of this option is ignored if Image-Dired is customized +to use the Thumbnail Managing Standard. See +`image-dired-thumbnail-storage'." + :type '(choice :tag "How to name thumbnail files" + (const :tag "SHA-1 of the image file name" sha1-filename) + (const :tag "SHA-1 of the image contents" sha1-contents)) + :version "30.1") + (defcustom image-dired-thumbnail-storage 'image-dired - "How `image-dired' stores thumbnail files. + "Where `image-dired' stores thumbnail files. There are three ways that Image-Dired can store and generate thumbnails: @@ -189,6 +208,9 @@ image-dired-thumbnail-storage Set this user option to `per-directory'. +To control the naming of thumbnails for alternatives (2) and (3) +above, customize the value of `image-dired-thumb-naming'. + To control the default size of thumbnails for alternatives (2) and (3) above, customize the value of `image-dired-thumb-size'. @@ -197,7 +219,7 @@ image-dired-thumbnail-storage For more information on the Thumbnail Managing Standard, see: https://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html" - :type '(choice :tag "How to store thumbnail files" + :type '(choice :tag "Where to store thumbnail files" (const :tag "Use image-dired-dir" image-dired) (const :tag "Thumbnail Managing Standard (normal 128x128)" standard) -- 2.40.0 --=-=-=--