emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/annotate cc0b5da6c1 229/372: Merge pull request #69 from c


From: ELPA Syncer
Subject: [nongnu] elpa/annotate cc0b5da6c1 229/372: Merge pull request #69 from cage2/switch-database
Date: Fri, 4 Feb 2022 16:59:02 -0500 (EST)

branch: elpa/annotate
commit cc0b5da6c1f8f09cc3ebe1c0d130c093c7e1d3c6
Merge: 99c45f553e 85520c0202
Author: cage2 <1257703+cage2@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #69 from cage2/switch-database
    
    - added a couple of functions to allow an user to change annotation database
---
 Changelog   |  7 ++++++-
 NEWS.org    |  3 +++
 README.org  | 12 ++++++++++--
 annotate.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/Changelog b/Changelog
index 5b572e1e82..1fb758125c 100644
--- a/Changelog
+++ b/Changelog
@@ -1,10 +1,15 @@
+2020-06-09 Bastian Bechtold, cage
+       * annotate.el (annotate-buffers-annotate-mode, annotate-switch-db)
+       - added functions to switch the database of annotations used for the 
emacs session;
+       - increased version to 0.8.0
+
 2020-05-18 Bastian Bechtold, cage
        * annotate.el
        - Increased version to 0.7.0 for stable release
 
 2020-01-25 Bastian Bechtold, cage
 
-        * annotate.el (defun annotate-annotation-force-newline-policy,
+        * annotate.el (annotate-annotation-force-newline-policy,
                        annotate-annotation-newline-policy-forced-p,
                        annotate-create-annotation,
                        annotate-lineate,
diff --git a/NEWS.org b/NEWS.org
index 9c9f82552a..cbbce9065c 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -114,3 +114,6 @@
 
 - 2020-05-18 V0.7.0 Bastian Bechtold, cage ::
   Increased version to 0.7.0 for stable release
+
+- 2020-06-09 V0.8.0 Bastian Bechtold, cage ::
+  The database of annotation can be changed using the command 
~annotate-switch-db~.
diff --git a/README.org b/README.org
index a978e841f7..19c655be97 100644
--- a/README.org
+++ b/README.org
@@ -30,8 +30,16 @@ previous annotation.
 
 ** Metadata
 
-All  annotations are  saved  in  ~annotate-file~ (=~/.annotations=  by
-default).
+The  current  database  for  annotations  is  contained  in  the  file
+indicated by the variable ~annotate-file~ (=~/.emacs.d/annotations= by
+default) but  each user can change  this value in a  dynamic way using
+the  command ~annotate-switch-db~.   This  command will  take care  to
+refresh/redraw   all   annotations   in    the   buffers   that   uses
+~annotate-mode~.
+
+Please note that switching database,  in this context, means rebinding
+the  aforementioned variable  (~annotate-file~).  This  means than  no
+more than a single database can be active for each Emacs session.
 
 Users of
 [[https://github.com/emacscollective/no-littering][no-littering]]
diff --git a/annotate.el b/annotate.el
index e138fa924e..84789fcc5d 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: 0.7.0
+;; Version: 0.8.0
 
 ;; This file is NOT part of GNU Emacs.
 
@@ -55,7 +55,7 @@
 ;;;###autoload
 (defgroup annotate nil
   "Annotate files without changing them."
-  :version "0.7.0"
+  :version "0.8.0"
   :group 'text)
 
 ;;;###autoload
@@ -2489,5 +2489,54 @@ annotation, like this:
 
 ;;;; end of filtering: parser, lexer, etc.
 
+;;;; switching database
+
+(defun annotate-buffers-annotate-mode ()
+ "Returns a list of all the buffers that have
+annotate minor mode active"
+  (let ((all-buffers (buffer-list)))
+    (cl-labels ((annotate-mode-p (buffer)
+                  (with-current-buffer buffer
+                    (and (boundp 'annotate-mode)
+                         annotate-mode))))
+      (cl-remove-if-not #'annotate-mode-p all-buffers))))
+
+(cl-defun annotate-switch-db (&optional (force-load nil))
+ "Ask the user for a new annotation database files, load it and
+refresh all the annotations contained in each buffer where
+annotate minor mode is active.
+
+If `force-load' is non nil no prompt asking user for confirmation
+about loading the new file is shown.
+
+Note: this function will attempt to load (compile and
+eval/execute) the content of the file as it was elisp source
+code, always use load files from trusted sources!"
+  (interactive)
+  (let ((new-db (read-file-name "Database file location: ")))
+    (when (not (annotate-string-empty-p new-db))
+      (if (file-exists-p new-db)
+          (let* ((confirm-message "Loading elisp file from untrusted source 
may results in severe security problems. Load %S? [y/N] ")
+                 (load-file-confirmed (if force-load
+                                          t
+                                        (string= (read-from-minibuffer (format 
confirm-message
+                                                                               
new-db))
+                                                 "y"))))
+            (if load-file-confirmed
+                (progn
+                  (setf annotate-file new-db)
+                  (cl-loop for annotated-buffer in 
(annotate-buffers-annotate-mode) do
+                           (with-current-buffer annotated-buffer
+                             (let ((buffer-was-modified-p (buffer-modified-p 
annotated-buffer)))
+                               (annotate-with-inhibit-modification-hooks
+                                (annotate-mode -1)
+                                (annotate-mode  1)
+                                (when (not buffer-was-modified-p)
+                                  (set-buffer-modified-p nil)))))))
+              (message "Load aborted by the user")))
+        (user-error (format "The file %S does not exists." new-db))))))
+
+;; end of switching database
+
 (provide 'annotate)
 ;;; annotate.el ends here



reply via email to

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