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

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

[nongnu] elpa/annotate 3973946e5a 1/3: - added procedures to generate an


From: ELPA Syncer
Subject: [nongnu] elpa/annotate 3973946e5a 1/3: - added procedures to generate and use a single database for each annotated file.
Date: Fri, 3 Jun 2022 06:58:01 -0400 (EDT)

branch: elpa/annotate
commit 3973946e5a837513a02aae01e3d4e64606ce9dc8
Author: cage <cage@invalid>
Commit: cage <cage@invalid>

    - added procedures to generate and use a single database for each annotated 
file.
---
 annotate.el | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/annotate.el b/annotate.el
index b97a496761..c4e9fd8707 100644
--- a/annotate.el
+++ b/annotate.el
@@ -82,6 +82,17 @@ See https://github.com/bastibe/annotate.el/ for 
documentation."
   "File where annotations are stored."
   :type 'file)
 
+(defcustom annotate-file-buffer-local nil
+ "If non nil (default `nil'), for each annotated file `filename', a database
+`filename.notes', containing the annotations, is generated in the
+same directory that contains `filename'."
+  :type 'string)
+
+(defcustom annotate-buffer-local-database-extension "notes"
+ "The extension appended to the annotated filename to get the
+name of the local database annotation"
+  :type 'string)
+
 (defface annotate-highlight
   '((t (:underline "coral")))
   "Face for annotation highlights.")
@@ -437,8 +448,25 @@ modified (for example a newline is inserted)."
 note that the argument `FRAME' is ignored"
   (font-lock-flush))
 
+(defun annotate--filepath->local-database-name (filepath)
+ "Generates the file path of the local database form `FILEPATH'"
+  (concat (file-name-nondirectory filepath)
+          "."
+          annotate-buffer-local-database-extension))
+
+(defun annotate--maybe-database-set-buffer-local ()
+ "Sets, if user asked to do so, the annotation database to a
+local version (i.e. a different database for each annotated file"
+  (when annotate-file-buffer-local
+    (make-local-variable 'annotate-file)
+    (when-let* ((buffer-file-path (buffer-file-name))
+                (parent-directory (file-name-directory buffer-file-path))
+                (db-name (annotate--filepath->local-database-name 
buffer-file-path)))
+      (setq-local annotate-file db-name))))
+
 (defun annotate-initialize ()
   "Load annotations and set up save and display hooks."
+  (annotate--maybe-database-set-buffer-local)
   (annotate-load-annotations)
   (add-hook 'after-save-hook                  #'annotate-save-annotations t t)
   ;; This hook  is needed to  reorganize the layout of  the annotation



reply via email to

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