[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/annotate b22f594f3b 336/372: Merge pull request #107 from
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/annotate b22f594f3b 336/372: Merge pull request #107 from cage2/prevent-saving-empty-db |
Date: |
Fri, 4 Feb 2022 16:59:18 -0500 (EST) |
branch: elpa/annotate
commit b22f594f3b813b12e442860344d2feb39d944b53
Merge: bd12129213 641daae9d0
Author: cage2 <1257703+cage2@users.noreply.github.com>
Commit: GitHub <noreply@github.com>
Merge pull request #107 from cage2/prevent-saving-empty-db
Prevented saving a file with an empty database;
---
Changelog | 8 +++++++-
NEWS.org | 12 ++++++++++++
README.org | 8 ++++++--
annotate.el | 48 ++++++++++++++++++++++++++++++++++--------------
4 files changed, 59 insertions(+), 17 deletions(-)
diff --git a/Changelog b/Changelog
index e7434ad668..33999c0519 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,10 @@
-021-04-30 cage
+2021-05-07 cage
+
+ * annotate.el:
+
+ - prevented saving a file with an empty database;
+
+2021-04-30 cage
* annotate.el:
diff --git a/NEWS.org b/NEWS.org
index eb3d0be647..3e9c0eb0dc 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -231,3 +231,15 @@
This version fixes a bug that prevented command like
'comment-region' to works properly when annotate-mode was active.
+
+- 2021-05-07 V1.3.0 cage ::
+
+ This version added a procedure to prevent an empty database to be
+ saved on the user's disk.
+
+ Moreover if an empty annotations database is going to overwrite an
+ existing stale database file on disk the file is deleted instead.
+
+ Before deleting the old database file a confirmation message is
+ printed on the minibuffer if the custom variable
+ 'annotate-database-confirm-deletion' is non nil (default: t).
diff --git a/README.org b/README.org
index f9e8c65931..eabe5b8ec6 100644
--- a/README.org
+++ b/README.org
@@ -53,15 +53,19 @@ see:
[[https://github.com/bastibe/annotate.el/issues/68][this thread]] and, in
particular
[[https://github.com/bastibe/annotate.el/issues/68#issuecomment-728218022][this
message]].
+If an empty annotation database (in memory) is saved the database
+file is deleted instead, if ~annotate-database-confirm-deletion~ is
+non nil (the default) a confirmation action is asked to the user
+before actually remove the file from the file system.
+
Users of
[[https://github.com/emacscollective/no-littering][no-littering]]
can take advantage of its packages generated files management.
**** related customizable variable
- ~annotate-file~
-
-**** related customizable variable
- ~annotate-warn-if-hash-mismatch~
+ - ~annotate-database-confirm-deletion~
** keybindings
diff --git a/annotate.el b/annotate.el
index 6ff3fc2ad1..2295d2b19a 100644
--- a/annotate.el
+++ b/annotate.el
@@ -7,7 +7,7 @@
;; Maintainer: Bastian Bechtold
;; URL: https://github.com/bastibe/annotate.el
;; Created: 2015-06-10
-;; Version: 1.2.1
+;; Version: 1.3.0
;; This file is NOT part of GNU Emacs.
@@ -58,7 +58,7 @@
;;;###autoload
(defgroup annotate nil
"Annotate files without changing them."
- :version "1.2.1"
+ :version "1.3.0"
:group 'text)
;;;###autoload
@@ -155,6 +155,13 @@ database is not filtered at all."
:type 'boolean
:group 'annotate)
+(defcustom annotate-database-confirm-deletion t
+ "If non nil a prompt asking confirmation before deleting a
+database file that is going to be empty after saving an annotated
+file will be shown"
+ :type 'boolean
+ :group 'annotate)
+
(defcustom annotate-annotation-max-size-not-place-new-line 15
"The maximum `string-width` allowed for an annotation to be
placed on the right margin of the window instead of its own line
@@ -1565,19 +1572,32 @@ annotation."
(ignore-errors (%load-annotation-data))
(%load-annotation-data))))
-(defun annotate-dump-annotation-data (data)
+(defun annotate-dump-annotation-data (data &optional save-empty-db)
"Save `data` into annotation file."
- (with-temp-file annotate-file
- (let* ((print-length nil)
- (%abbreviate-filename (lambda (record)
- (let ((full-filename
(annotate-filename-from-dump record))
- (annotations
(annotate-annotations-from-dump record))
- (file-checksum
(annotate-checksum-from-dump record)))
- (annotate-make-record
(abbreviate-file-name full-filename)
- annotations
- file-checksum))))
- (actual-data (mapcar %abbreviate-filename data)))
- (prin1 actual-data (current-buffer)))))
+ (if (or save-empty-db
+ data)
+ (with-temp-file annotate-file
+ (let* ((print-length nil)
+ (%abbreviate-filename (lambda (record)
+ (let ((full-filename
(annotate-filename-from-dump record))
+ (annotations
(annotate-annotations-from-dump record))
+ (file-checksum
(annotate-checksum-from-dump record)))
+ (annotate-make-record
(abbreviate-file-name full-filename)
+ annotations
+
file-checksum))))
+ (actual-data (mapcar %abbreviate-filename data)))
+ (prin1 actual-data (current-buffer))))
+ (let* ((confirm-message "Delete annotations database file %S? [y/N] ")
+ (delete-confirmed-p (or (not annotate-database-confirm-deletion)
+ (string= (read-from-minibuffer (format
confirm-message
+
annotate-file))
+ "y"))))
+ (if delete-confirmed-p
+ (condition-case err
+ (delete-file annotate-file t)
+ (error (message "error removing annotation database: %S"
+ (error-message-string err))))
+ (annotate-dump-annotation-data data t)))))
(cl-defmacro with-matching-annotation-fns ((filename
beginning
- [nongnu] elpa/annotate 804c7b9421 257/372: - Removed internal link because of issue #79., (continued)
- [nongnu] elpa/annotate 804c7b9421 257/372: - Removed internal link because of issue #79., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate a9f061cecd 268/372: - added more docstrings., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 88ed6f22cb 285/372: - rewritten export and integrate of annotations, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 463e215bec 284/372: - fixed export for annotated text made from a single line., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate e53c0f5adf 296/372: - added checking encrypted (GPG) file format, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate be48989c98 299/372: - fixed 'annotate-previous-annotation-ends', ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 59ca58c06b 308/372: changed function from 'font-lock-ensure' to 'font-lock-flush'., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate f823c3cf09 354/372: - changed default for asking confirm before deleting an annotation: the value is now 'nil' (do not prompt for confirmation)., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 3bb813cd62 360/372: - updated NEWS.org and Changelog., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 140eb6b6cb 363/372: - updated NEWS.org;, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate b22f594f3b 336/372: Merge pull request #107 from cage2/prevent-saving-empty-db,
ELPA Syncer <=
- [nongnu] elpa/annotate de86b9b22e 341/372: - removed uses of regular expressions from 'annotate-unwrap-text'., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate e083073ead 371/372: - updated Changelog;, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 0901aa52bc 367/372: - added the others procedures to import an annotation database., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate f08923762f 063/372: fix typo in documentation, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 16f7202d7c 091/372: - fixed docstring., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 7c759ba9eb 082/372: - fixed english language error., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 47dba946e8 075/372: - removed spurious newline character at the end of annotation text;, ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate 91f1d49368 087/372: - squeezed contiguous spaces in docstring., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate f85f8e00a1 088/372: - remove file size limit for hash calculation., ELPA Syncer, 2022/02/04
- [nongnu] elpa/annotate bf80059e7a 071/372: - use comment ends string in modes that allow it (e.g. html-mode);, ELPA Syncer, 2022/02/04