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)
|
("I" " insert note" anki-editor-insert-note :level 1)
|
||||||
("T" " set note type" anki-editor-set-note-type :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"
|
[["Push"
|
||||||
("." " note at point " anki-editor-push-note-at-point :level 2)
|
("." " note at point " anki-editor-push-note-at-point :level 2)
|
||||||
("n" " new notes " anki-editor-push-new-notes :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
|
(anki-editor-push-notes scope
|
||||||
(concat anki-editor-prop-failure-reason "<>\"\"")))
|
(concat anki-editor-prop-failure-reason "<>\"\"")))
|
||||||
|
|
||||||
(defun anki-editor-delete-notes (noteids)
|
(defun anki-editor-delete-note-at-point (&optional prefix)
|
||||||
"Delete notes in NOTEIDS or the note at point."
|
"Delete the note at point from Anki.
|
||||||
(interactive (list (list (org-entry-get nil anki-editor-prop-note-id))))
|
With PREFIX also delete it from Org."
|
||||||
(when (or (not (called-interactively-p 'interactive))
|
(interactive "P")
|
||||||
(yes-or-no-p
|
(save-excursion
|
||||||
(format (concat "Do you really want to delete note %s? "
|
(let (note-type note-id)
|
||||||
"This can't be undone.")
|
(while
|
||||||
(nth 0 noteids))))
|
(and (org-back-to-heading)
|
||||||
(anki-editor-api-call-result 'deleteNotes
|
(not (setq note-type
|
||||||
:notes noteids)
|
(org-entry-get nil anki-editor-prop-note-type)))
|
||||||
(org-entry-delete nil anki-editor-prop-note-id)
|
(org-up-heading-safe)))
|
||||||
(when (called-interactively-p 'interactive)
|
(when (not note-type)
|
||||||
(message "Deleted note %s" (nth 0 noteids)))))
|
(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 (list note-id))
|
||||||
|
(org-entry-delete nil anki-editor-prop-note-id)
|
||||||
|
(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)
|
(defun anki-editor-insert-note (&optional prefix note-type)
|
||||||
"Insert a note interactively.
|
"Insert a note interactively.
|
||||||
|
|
Loading…
Reference in a new issue