Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collaboration support. #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions org-fc-collaborate.el
Original file line number Diff line number Diff line change
@@ -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 <emacs@leonrische.me>
;; 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 <https://www.gnu.org/licenses/>.

;;; 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
14 changes: 11 additions & 3 deletions org-fc-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions org-fc-review.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

Expand Down
9 changes: 8 additions & 1 deletion org-fc-type-cloze.el
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion org-fc-type-double.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion org-fc-type-normal.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
8 changes: 7 additions & 1 deletion org-fc-type-text-input.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion org-fc-type-vocab.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion org-fc.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

(require 'org-fc-core)
(require 'org-fc-compat)
(require 'org-fc-collaborate)

(require 'org-fc-awk)
(require 'org-fc-algo-sm2)

(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)
Expand Down