Add anki-editor-delete-note-at-point
It improves upon `anki-editor-delete-notes` when deleting note at point, allowing aribtrary position in the note when calling it, and also allowing deletion in Org. `anki-editor-delete-notes` is removed.
This commit is contained in:
parent
6ae4420e2a
commit
0928dd6465
2 changed files with 34 additions and 14 deletions
|
@ -46,7 +46,7 @@
|
|||
[""
|
||||
("I" " insert note" anki-editor-insert-note :level 1)
|
||||
("T" " set note type" anki-editor-set-note-type :level 1)
|
||||
("d" " delete note" anki-editor-delete-notes :level 1)]]
|
||||
("d" " delete note" anki-editor-delete-note-at-point :level 1)]]
|
||||
[["Push"
|
||||
("." " note at point " anki-editor-push-note-at-point :level 2)
|
||||
("n" " new notes " anki-editor-push-new-notes :level 2)
|
||||
|
|
|
@ -1083,19 +1083,39 @@ matching non-empty `ANKI_FAILURE_REASON' properties."
|
|||
(anki-editor-push-notes scope
|
||||
(concat anki-editor-prop-failure-reason "<>\"\"")))
|
||||
|
||||
(defun anki-editor-delete-notes (noteids)
|
||||
"Delete notes in NOTEIDS or the note at point."
|
||||
(interactive (list (list (org-entry-get nil anki-editor-prop-note-id))))
|
||||
(when (or (not (called-interactively-p 'interactive))
|
||||
(yes-or-no-p
|
||||
(format (concat "Do you really want to delete note %s? "
|
||||
"This can't be undone.")
|
||||
(nth 0 noteids))))
|
||||
(defun anki-editor-delete-note-at-point (&optional prefix)
|
||||
"Delete the note at point from Anki.
|
||||
With PREFIX also delete it from Org."
|
||||
(interactive "P")
|
||||
(save-excursion
|
||||
(let (note-type note-id)
|
||||
(while
|
||||
(and (org-back-to-heading)
|
||||
(not (setq note-type
|
||||
(org-entry-get nil anki-editor-prop-note-type)))
|
||||
(org-up-heading-safe)))
|
||||
(when (not note-type)
|
||||
(user-error "No note to delete found"))
|
||||
(setq note-id (condition-case nil
|
||||
(string-to-number
|
||||
(org-entry-get nil anki-editor-prop-note-id))
|
||||
(error nil)))
|
||||
(if (not note-id)
|
||||
(if prefix
|
||||
(message "Note at point is not in Anki (no note-id)")
|
||||
(user-error "Note at point is not in Anki (no note-id)"))
|
||||
(when (yes-or-no-p
|
||||
(format (concat "Do you really want to delete note %s "
|
||||
"from Anki?")
|
||||
note-id))
|
||||
(anki-editor-api-call-result 'deleteNotes
|
||||
:notes noteids)
|
||||
:notes (list note-id))
|
||||
(org-entry-delete nil anki-editor-prop-note-id)
|
||||
(when (called-interactively-p 'interactive)
|
||||
(message "Deleted note %s" (nth 0 noteids)))))
|
||||
(message "Deleted note %s from Anki" note-id)))
|
||||
(when prefix
|
||||
(org-mark-subtree)
|
||||
(kill-region nil nil t)
|
||||
(message "Deleted note at point from Org")))))
|
||||
|
||||
(defun anki-editor-insert-note (&optional prefix note-type)
|
||||
"Insert a note interactively.
|
||||
|
|
Loading…
Reference in a new issue