branch: externals/calibre
commit 143309131c0f40a409ece4616c1c75403b461f4d
Author: Kjartan Oli Agustsson <[email protected]>
Commit: Kjartan Oli Agustsson <[email protected]>

    Retain modification mark when unmarking a marked book
    
    * calibre-edit.el (calibre-edit--mark-modified): Rename 
calibre-edit-mark-modified.
    (calibre-edit-apply):
    (calibre-edit-add-tag):
    (calibre-edit-remove-tag):
    
    Adjust to renaming of calibre-edit--mark-modified.
    
    (calibre-edit-modified-p): New function.
    * calibre-library.el (calibre-library-mark-unmark): Preserve the 'M'
    modification mark when unmarking a '*' mark.
    * doc/calibre.texi: Remove warning about marking modified books.
    
    If a book was modified and subsequently marked, unmarking it would
    result in the modification mark being discarded.  This would result in
    those modifications not being picked up by calibre-library-execute,
    which would result in the modifications being lost.
---
 calibre-edit.el    | 12 ++++++++----
 calibre-library.el | 14 ++++++++++----
 doc/calibre.texi   | 12 ------------
 3 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/calibre-edit.el b/calibre-edit.el
index d41f63c1f7..d792765be9 100644
--- a/calibre-edit.el
+++ b/calibre-edit.el
@@ -48,7 +48,7 @@
 (defvar-local calibre-edit--tags nil
   "The tags widget in the current buffer.")
 
-(defun calibre-edit--mark-modified (book)
+(defun calibre-edit-mark-modified (book)
   "Mark BOOK as modified in the *Library* buffer."
   (with-current-buffer (get-buffer calibre-library-buffer)
     (calibre-library--find-book book)
@@ -68,7 +68,7 @@
                                                          1)
         (calibre-book-tags calibre-edit--book) (widget-value 
calibre-edit--tags))
   (calibre-library--refresh)
-  (calibre-edit--mark-modified calibre-edit--book))
+  (calibre-edit-mark-modified calibre-edit--book))
 
 (defun calibre-edit-abort (&rest _)
   "Abort any changes made in the current buffer."
@@ -122,12 +122,16 @@ function does nothing."
   (unless (calibre-util-find-book book calibre-edit--edited-books)
     (push (copy-calibre-book book) calibre-edit--edited-books)))
 
+(defun calibre-edit-modified-p (book)
+  "Return non-nil if BOOK has been modified, nil otherwise."
+  (calibre-edit--find-original book))
+
 (defun calibre-edit-add-tags (tags book)
   "Add TAGS to BOOK."
   (calibre-edit--preserve-original book)
   (when (seq-difference tags (calibre-book-tags book))
     (setf (calibre-book-tags book) (seq-union tags (calibre-book-tags book)))
-    (calibre-edit--mark-modified book)))
+    (calibre-edit-mark-modified book)))
 
 (defun calibre-edit-remove-tags (tags book)
   "Remove TAGS from BOOK."
@@ -135,7 +139,7 @@ function does nothing."
   (let ((difference (seq-difference (calibre-book-tags book) tags)))
     (unless (seq-set-equal-p (calibre-book-tags book) difference)
       (setf (calibre-book-tags book) difference)
-      (calibre-edit--mark-modified book))))
+      (calibre-edit-mark-modified book))))
 
 (defun calibre-edit-add-tag (tag book)
   "Add TAG to BOOK."
diff --git a/calibre-library.el b/calibre-library.el
index 47826a59e6..edf7327974 100644
--- a/calibre-library.el
+++ b/calibre-library.el
@@ -116,10 +116,16 @@ TAGS should be a list of strings to add to FILE."
   (interactive "p" calibre-library-mode)
   (let ((book (tabulated-list-get-id)))
     (beginning-of-line)
-    (when (char-equal (char-after) ?M)
-      (calibre-edit-revert book))
-    (calibre-library--find-book book)
-    (tabulated-list-put-tag " " t)))
+    (let ((mark (char-after)))
+      (unless (char-equal mark 32)
+        (cond
+         ((char-equal mark calibre-mod-marker)
+          (calibre-edit-revert book)
+          (tabulated-list-put-tag " " t))
+         ((char-equal mark calibre-mark-marker)
+          (if (calibre-edit-modified-p book)
+              (calibre-edit-mark-modified book)
+              (tabulated-list-put-tag " " t))))))))
 
 (defun calibre-library-get-marked (&optional mark)
   "Return books marked with MARK.
diff --git a/doc/calibre.texi b/doc/calibre.texi
index d053d826cb..19f74b77b5 100644
--- a/doc/calibre.texi
+++ b/doc/calibre.texi
@@ -361,18 +361,6 @@ you are satisfied with your selection simply call any of 
the commands in
 this section.  If no books are selected all of the commands in this
 section will operate on the book at point.
 
-Be careful when marking already modified books with
-@code{calibre-library-mark}.  calibre.el uses the mark applied by the
-modification commands to identify changes that have not been committed
-(@pxref{Committing and reverting modifications}) and the mark applied by
-@code{calibre-library-mark} overwrites that mark (but not the
-modifications themselves), this is fine as long as you subsequently
-perform some modification on the book since the two sets of
-modifications will merge together and the book will again be marked as
-modified.  However, if you unmark the book with
-@code{calibre-library-mark-unmark} the modification mark will not be
-restored and any modifications will be lost.
-
 @findex calibre-library-add-tags
 @findex calibre-library-remove-tags
 Currently the only metadata that can be modified from the

Reply via email to