branch: elpa/annotate commit 8ac52808e82274b1a905200b06602e3d901f018f Author: cage <cage-invalid@invalid> Commit: cage <cage-invalid@invalid>
- added a couple of functions to allow an user to change the file that contains the database of annotation, and reload all the annotated buffers. --- annotate.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/annotate.el b/annotate.el index e138fa924e..b690608e6d 100644 --- a/annotate.el +++ b/annotate.el @@ -2489,5 +2489,51 @@ 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 + (annotate-with-inhibit-modification-hooks + (annotate-mode -1) + (annotate-mode 1))))) + (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