bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#50000: 27.2; tagging marked thumbnails


From: Peter Münster
Subject: bug#50000: 27.2; tagging marked thumbnails
Date: Wed, 18 Aug 2021 17:01:36 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

On Wed, Aug 18 2021, Lars Ingebrigtsen wrote:

> Thanks; applied with one minor change:

Thanks. Please find attached some further patches for image-dired.el.
I hope that they are useful.

-- 
           Peter
From 7cfc8ad4effd5820d1bdef2027148df8219b8408 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Tue, 17 Aug 2021 00:19:08 +0200
Subject: [PATCH 3/6] Fix deletion of associated image

* lisp/image-dired.el (image-dired-delete-marked): Treat original images
first, because point position is used when there are no marked files.
---
 lisp/image-dired.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 1d8e27d39e..5ae6b21766 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -2312,14 +2312,14 @@ image-dired-thumb-file-marked-p
           (image-dired-dired-file-marked-p))))))
 
 (defun image-dired-delete-marked ()
-  "Delete marked thumbnails and associated images."
+  "Delete current or marked thumbnails and associated images."
   (interactive)
+  (with-current-buffer (image-dired-associated-dired-buffer)
+    (dired-do-delete))
   (image-dired--with-marked
    (image-dired-delete-char)
    (backward-char))
-  (image-dired--line-up-with-method)
-  (with-current-buffer (image-dired-associated-dired-buffer)
-    (dired-do-delete)))
+  (image-dired--line-up-with-method))
 
 (defun image-dired-thumb-update-marks ()
   "Update the marks in the thumbnail buffer."
-- 
2.26.2

From ba6e4282f69c13dc57d00fdd7ff63f9565b8afe9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Wed, 18 Aug 2021 01:37:43 +0200
Subject: [PATCH 4/6] New placement of newline characters in
 image-dired-db-file

It's more usual to have the newline at the end of the line, instead of the
beginning. This change avoids missing newline at the end of the file, an
empty line at the start and eventually a lot of empty lines when
`require-final-newline' is not nil.

* lisp/image-dired.el (image-dired-write-tags): Insert newline at the end
of the line, instead of the beginning.
(image-dired-remove-tag): Do not delete empty line at end of buffer.
---
 lisp/image-dired.el | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 5ae6b21766..428b20d6eb 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -1095,7 +1095,7 @@ image-dired-write-tags
               (end-of-line)
               (insert (format ";%s" tag))))
         (goto-char (point-max))
-        (insert (format "\n%s;%s" file tag))))
+        (insert (format "%s;%s\n" file tag))))
      (save-buffer))))
 
 (defun image-dired-remove-tag (files tag)
@@ -1122,11 +1122,7 @@ image-dired-remove-tag
           (setq end (point))
           (beginning-of-line)
           (when (not (search-forward ";" end t))
-            (kill-line 1)
-            ;; If on empty line at end of buffer
-            (and (eobp)
-                 (looking-at "^$")
-                 (delete-char -1)))))))
+            (kill-line 1))))))
    (save-buffer)))
 
 (defun image-dired-list-tags (file)
@@ -2184,7 +2180,7 @@ image-dired-write-comments
             (insert (format "comment:%s;" comment)))
         ;; File does not exist in database - add it.
         (goto-char (point-max))
-        (insert (format "\n%s;comment:%s" file comment))))
+        (insert (format "%s;comment:%s\n" file comment))))
      (save-buffer))))
 
 (defun image-dired-update-property (prop value)
-- 
2.26.2

From 2163c4c3894272d2022e5fb78d2c0be1310d9da9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Wed, 18 Aug 2021 02:02:02 +0200
Subject: [PATCH 5/6] Avoid problems when one tag/file is a substring of
 another

* lisp/image-dired.el (image-dired-remove-tag): End of filename is bound
by ";" and end of tag is bound by ";" or end of line.
---
 lisp/image-dired.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 428b20d6eb..5ee66b0e90 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -1110,11 +1110,12 @@ image-dired-remove-tag
         (error "Files must be a string or a list of strings!")))
      (dolist (file files)
        (goto-char (point-min))
-       (when (search-forward-regexp (format "^%s" file) nil t)
+       (when (search-forward-regexp (format "^%s;" file) nil t)
         (end-of-line)
         (setq end (point))
         (beginning-of-line)
-        (when (search-forward-regexp (format "\\(;%s\\)" tag) end t)
+        (when (search-forward-regexp
+                (format "\\(;%s\\)\\($\\|;\\)" tag) end t)
           (delete-region (match-beginning 1) (match-end 1))
           ;; Check if file should still be in the database. If
           ;; it has no tags or comments, it will be removed.
-- 
2.26.2

From 364beec6d1470712415a36f5810e4f7d320c6b0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Wed, 18 Aug 2021 11:21:51 +0200
Subject: [PATCH 6/6] Add support for history of image tags and completion in
 the minibuffer

* lisp/image-dired.el (image-dired-tag-history): New variable holding the
tag history.
(image-dired-tag-files, image-dired-tag-thumbnail, image-dired-delete-tag)
(image-dired-tag-thumbnail-remove): Use it for the user input.
---
 lisp/image-dired.el | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 5ee66b0e90..5a332964d5 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -652,6 +652,8 @@ image-dired-queue-active-limit
   "Maximum number of concurrent jobs permitted for generating images.
 Increase at own risk.")
 
+(defvar image-dired-tag-history nil "Variable holding the tag history.")
+
 (defun image-dired-pngnq-thumb (spec)
   "Quantize thumbnail described by format SPEC with pngnq(1)."
   (let ((process
@@ -1146,7 +1148,9 @@ image-dired-list-tags
 (defun image-dired-tag-files (arg)
   "Tag marked file(s) in dired.  With prefix ARG, tag file at point."
   (interactive "P")
-  (let ((tag (read-string "Tags to add (separate tags with a semicolon): "))
+  (let ((tag (completing-read
+              "Tags to add (separate tags with a semicolon): "
+              image-dired-tag-history nil nil nil 'image-dired-tag-history))
         files)
     (if arg
         (setq files (list (dired-get-filename)))
@@ -1160,7 +1164,9 @@ image-dired-tag-files
 (defun image-dired-tag-thumbnail ()
   "Tag current or marked thumbnails."
   (interactive)
-  (let ((tag (read-string "Tags to add (separate tags with a semicolon): ")))
+  (let ((tag (completing-read
+              "Tags to add (separate tags with a semicolon): "
+              image-dired-tag-history nil nil nil 'image-dired-tag-history)))
     (image-dired--with-marked
      (image-dired-write-tags
       (list (cons (image-dired-original-file-name) tag)))
@@ -1172,7 +1178,8 @@ image-dired-delete-tag
   "Remove tag for selected file(s).
 With prefix argument ARG, remove tag from file at point."
   (interactive "P")
-  (let ((tag (read-string "Tag to remove: "))
+  (let ((tag (completing-read "Tag to remove: " image-dired-tag-history
+                              nil nil nil 'image-dired-tag-history))
         files)
     (if arg
         (setq files (list (dired-get-filename)))
@@ -1182,7 +1189,8 @@ image-dired-delete-tag
 (defun image-dired-tag-thumbnail-remove ()
   "Remove tag from current or marked thumbnails."
   (interactive)
-  (let ((tag (read-string "Tag to remove: ")))
+  (let ((tag (completing-read "Tag to remove: " image-dired-tag-history
+                              nil nil nil 'image-dired-tag-history)))
     (image-dired--with-marked
      (image-dired-remove-tag (image-dired-original-file-name) tag)
      (image-dired-update-property
-- 
2.26.2

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]