branch: elpa/annotate commit 9cdc2a90fbcad5904a900957b8cf9bd2868f6cb2 Author: cage <cage@localhost> Commit: cage <cage@invalid>
- added prompt to confirm deletion also when deleting annotation's text; - updated README.org. --- README.org | 31 +++++++++++++++++++++++-------- annotate.el | 23 ++++++++++++++++------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/README.org b/README.org index eabe5b8ec6..0d3cfea760 100644 --- a/README.org +++ b/README.org @@ -22,8 +22,8 @@ is active, ~C-c C-a~ will create, edit, or delete annotations. With an active region, ~C-c C-a~ creates a new annotation for that region. With no active region, ~C-c C-a~ will create an annotation for the word under point. If point is on an annotated region, ~C-c C-a~ -will edit that annotation instead of creating a new one. Clearing the -annotation deletes them. +will edit that annotation instead of creating a new one. Typing ~C-c +C-d~ or clearing the annotation deletes them. Use ~C-c ]~ to jump to the next annotation and ~C-c [~ to jump to the previous annotation. @@ -76,6 +76,10 @@ can take advantage of its packages generated files management. will edit that annotation instead of creating a new one. Clearing the annotation deletes them. + If ~annotate-annotation-confirm-deletion~ is non nil (the default) + a confirmation action is asked to the user before actually remove + the annotation. + If point is the newline character and the customizable variable ~annotate-endline-annotate-whole-line~ is not nil (default is non nil) the whole line is annotated (or the next if the line is @@ -87,14 +91,25 @@ can take advantage of its packages generated files management. will signal an error. **** related customizable variable - - ~annotate-endline-annotate-whole-line~ - - ~annotate-highlight~; - - ~annotate-highlight-secondary~; - - ~annotate-annotation~; - - ~annotate-annotation-secondary~; - ~annotate-annotation-column~; + - ~annotate-annotation-confirm-deletion~; - ~annotate-annotation-max-size-not-place-new-line~; - - ~annotate-annotation-position-policy~. + - ~annotate-annotation-position-policy~; + - ~annotate-annotation-secondary~; + - ~annotate-annotation~; + - ~annotate-endline-annotate-whole-line~; + - ~annotate-highlight-secondary~; + - ~annotate-highlight~. + +*** ~C-c C-d~ + Delete an annotation under point, if such annotation exists. + + If ~annotate-annotation-confirm-deletion~ is non nil (the default) + a confirmation action is asked to the user before actually remove + the annotation. + +**** related customizable variable + - ~annotate-annotation-confirm-deletion~. *** ~C-c ]~ (function annotate-goto-next-annotation) Jump to the next annotation. diff --git a/annotate.el b/annotate.el index 038e7bc198..b9de71e708 100644 --- a/annotate.el +++ b/annotate.el @@ -2084,22 +2084,29 @@ from a chain where `annotation' belong." (defun annotate--delete-annotation-chain-prevent-modification (annotation) "Delete an annotation chain backing up and restoring modification -status of the buffer before deltion occured." +status of the buffer before deletion occured. + +This function is not part of the public API." (annotate-ensure-annotation (annotation) (annotate-with-restore-modified-bit (annotate--delete-annotation-chain annotation)))) +(defun annotate--confirm-annotation-delete () + "Prompt user for delete confirmation. +This function is not part of the public API." + (let ((confirm-message "Delete this annotation? [y/N] ")) + (or (not annotate-annotation-confirm-deletion) + (string= (read-from-minibuffer (format confirm-message + annotate-file)) + "y")))) + (cl-defun annotate-delete-annotation (&optional (point (point))) "Command to delete an annotation, `point' is the buffer position where to look for annotation (default the cursor point)." (interactive) (when-let ((annotation (annotate-annotation-at point))) - (let* ((confirm-message "Delete this annotation? [y/N] ") - (delete-confirmed-p (or (not annotate-annotation-confirm-deletion) - (string= (read-from-minibuffer (format confirm-message - annotate-file)) - "y")))) + (let* ((delete-confirmed-p (annotate--confirm-annotation-delete))) (when delete-confirmed-p (annotate--delete-annotation-prevent-modification annotation))))) @@ -2119,7 +2126,9 @@ point)." ((null annotation-text)) ;; annotation was erased: ((string= "" annotation-text) - (annotate--delete-annotation-prevent-modification highlight)) + (let* ((delete-confirmed-p (annotate--confirm-annotation-delete))) + (when delete-confirmed-p + (annotate--delete-annotation-prevent-modification highlight)))) ;; annotation was changed: (t (change highlight)))))))