diff --git a/org-fc-collaborate.el b/org-fc-collaborate.el new file mode 100644 index 0000000..df0db39 --- /dev/null +++ b/org-fc-collaborate.el @@ -0,0 +1,52 @@ +;;; org-fc-collaborate.el --- Functions for sharing cards without user data -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 Leon Rische + +;; Author: Leon Rische +;; Url: https://www.leonrische.me/pages/org_flashcards.html +;; Package-requires: ((emacs "26.3") (org "9.3")) +;; Version: 0.0.1 + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: +;; + +;; +;; +;;; Code: + +(require 'org-fc-core) + +(defun org-fc-strip-all-review-data () + "Delete review data from every drill card." + (interactive) + (when (yes-or-no-p + "Delete review data from all items in org-fc directories: are you sure?") + (dolist (card (org-fc-index org-fc-context-all)) + (let* ((path (plist-get card :path)) + (id (plist-get card :id)) + (type (plist-get card :type))) + (with-current-buffer (find-file path) + (goto-char (point-min)) + (org-fc-id-goto id path) + (funcall (org-fc-type-reset-fn type))))) + (message "Done.")) + ) + +;;; Footer + +(provide 'org-fc-collaborate) + +;;; org-fc-collaborate.el ends here diff --git a/org-fc-core.el b/org-fc-core.el index 3323f11..cf4f11e 100644 --- a/org-fc-core.el +++ b/org-fc-core.el @@ -300,14 +300,15 @@ Should only be used by the init functions of card TYPEs." Entries should be lists (name handler-fn update-fn). Use `org-fc-register-type' for adding card types.") -(defun org-fc-register-type (name setup-fn flip-fn update-fn) +(defun org-fc-register-type (name setup-fn flip-fn update-fn reset-fn) "Register a new card type. Argument NAME Name of the new type. Argument SETUP-FN Function for initializing a new card of this type. Argument FLIP-FN Function for flipping a card during review. -Argument UPDATE-FN Function to update a card when it's contents have changed." +Argument UPDATE-FN Function to update a card when it's contents have changed. +Argument RESET-FN Functin to reset review data for a card for sharing." (push - (list name setup-fn flip-fn update-fn) + (list name setup-fn flip-fn update-fn reset-fn) org-fc-types)) (defun org-fc-type-setup-fn (type) @@ -331,6 +332,13 @@ Argument UPDATE-FN Function to update a card when it's contents have changed." (cl-third entry) (error "No such flashcard type: %s" type)))) +(defun org-fc-type-reset-fn (type) + "Get the reset function for a card of TYPE." + (let ((entry (alist-get type org-fc-types nil nil #'string=))) + (if entry + (cl-fourth entry) + (error "No such flashcard type: %s" type)))) + ;;; Working with Overlays / Hiding Text ;;;; Showing / Hiding Overlays diff --git a/org-fc-review.el b/org-fc-review.el index f41baeb..db623d7 100644 --- a/org-fc-review.el +++ b/org-fc-review.el @@ -404,17 +404,17 @@ END is the start of the line with :END: on it." ('sm2-v1 (org-fc-algo-sm2-initial-review-data position)) ('sm2-v2 (org-fc-algo-sm2-initial-review-data position)))) -(defun org-fc-review-data-update (positions) +(defun org-fc-review-data-update (positions &optional reset) "Update review data to POSITIONS. If a doesn't exist already, it is initialized with default values. Entries in the table not contained in POSITIONS are -removed." +removed. If RESET flag is set, review data will be reset for sharing." (let ((old-data (org-fc-review-data-get))) (org-fc-review-data-set (mapcar (lambda (pos) (or - (assoc pos old-data #'string=) + (and (not reset) (assoc pos old-data #'string=)) (org-fc-review-data-default pos))) positions)))) diff --git a/org-fc-type-cloze.el b/org-fc-type-cloze.el index 78b76ee..aa87c85 100644 --- a/org-fc-type-cloze.el +++ b/org-fc-type-cloze.el @@ -200,11 +200,18 @@ Processes all holes in the card text." (format "%s" (1- hole-id))) (org-fc-review-data-update (reverse ids)))) +(defun org-fc-type-cloze-reset () + "Reset review data for a cloze card." + (interactive) + (let* ((hole-id (1+ (org-fc-type-cloze-max-hole-id))) ids) + (org-fc-review-data-update (reverse ids) 't))) + (org-fc-register-type 'cloze 'org-fc-type-cloze-setup 'org-fc-type-cloze-flip - 'org-fc-type-cloze-update) + 'org-fc-type-cloze-update + 'org-fc-type-cloze-reset) ;;; Footer diff --git a/org-fc-type-double.el b/org-fc-type-double.el index 81c7568..ccb13c8 100644 --- a/org-fc-type-double.el +++ b/org-fc-type-double.el @@ -37,6 +37,11 @@ (org-fc--init-card "double") (org-fc-review-data-update '("front" "back"))) +(defun org-fc-type-double-reset () + "Reset review data for the double type." + (interactive) + (org-fc-review-data-update '("front" "back") 't)) + (defun org-fc-type-double-setup (position) "Prepare POSITION of a double card for review." (pcase position @@ -66,7 +71,8 @@ 'double 'org-fc-type-double-setup 'org-fc-type-double-flip - 'org-fc-noop) + 'org-fc-noop + 'org-fc-type-double-reset) ;;; Footer diff --git a/org-fc-type-normal.el b/org-fc-type-normal.el index 2325e3e..a7084f9 100644 --- a/org-fc-type-normal.el +++ b/org-fc-type-normal.el @@ -32,6 +32,11 @@ (org-fc--init-card "normal") (org-fc-review-data-update '("front"))) +(defun org-fc-type-normal-reset () + "Reset review metadata for this card" + (interactive) + (org-fc-review-data-update '("front") 't)) + (defun org-fc-type-normal-setup (_position) "Prepare a normal card for review." (interactive) @@ -58,7 +63,8 @@ 'normal 'org-fc-type-normal-setup 'org-fc-type-normal-flip - 'org-fc-noop) + 'org-fc-noop + 'org-fc-type-normal-reset) ;;; Footer diff --git a/org-fc-type-text-input.el b/org-fc-type-text-input.el index 4def806..5d0f7cd 100644 --- a/org-fc-type-text-input.el +++ b/org-fc-type-text-input.el @@ -59,6 +59,11 @@ function is expected to be called with point on a heading." (org-fc--init-card "text-input") (org-fc-review-data-update '("front"))) +(defun org-fc-type-text-input-reset () + "Mark headline as card of the text-input type." + (interactive) + (org-fc-review-data-update '("front") 't)) + (defun org-fc-type-text-input-setup (_position) "Prepare a text-input card for review." (interactive) @@ -103,7 +108,8 @@ function is expected to be called with point on a heading." 'text-input 'org-fc-type-text-input-setup nil - 'org-fc-noop) + 'org-fc-noop + 'org-fc-type-text-input-reset) ;;; Footer diff --git a/org-fc-type-vocab.el b/org-fc-type-vocab.el index 6740851..ed22166 100644 --- a/org-fc-type-vocab.el +++ b/org-fc-type-vocab.el @@ -50,6 +50,11 @@ (org-fc--init-card "vocab") (org-fc-review-data-update '("front" "back"))) +(defun org-fc-type-vocab-reset () + "Reset review data for a vocab card." + (interactive) + (org-fc-review-data-update '("front" "back")) 't) + (defun org-fc-type-vocab-setup (position) "Prepare POSITION of a vocab card for review." (pcase position @@ -119,7 +124,8 @@ 'vocab 'org-fc-type-vocab-setup 'org-fc-type-vocab-flip - 'org-fc-noop) + 'org-fc-noop + 'org-fc-type-vocab-reset) ;;; Footer diff --git a/org-fc.el b/org-fc.el index f763607..eaec51a 100644 --- a/org-fc.el +++ b/org-fc.el @@ -28,6 +28,7 @@ (require 'org-fc-core) (require 'org-fc-compat) +(require 'org-fc-collaborate) (require 'org-fc-awk) (require 'org-fc-algo-sm2) @@ -35,7 +36,6 @@ (require 'org-fc-review) (require 'org-fc-dashboard) (require 'org-fc-cache) - (require 'org-fc-type-normal) (require 'org-fc-type-double) (require 'org-fc-type-text-input)