-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add classes for cards and positions #102
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
;;; org-fc-card.el --- Representation of a card. -*- 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: | ||
;; | ||
;; A single card. | ||
;; | ||
;;; Code: | ||
|
||
(require 'eieio) | ||
(require 'org-fc-position) | ||
|
||
(defclass org-fc-card () | ||
((created | ||
:initform nil | ||
:initarg :created | ||
:type list | ||
:custom (repeat integer) | ||
:documentation "The time at which this card was created.") | ||
(filetitle | ||
:initform "" | ||
:initarg :filetitle | ||
:type string | ||
:documentation "The title of the file which contains this card.") | ||
(tags | ||
:initform nil | ||
:initarg :tags | ||
:type list | ||
:custom (repeat string) | ||
:documentation "The tags on this card.") | ||
(id | ||
:initform "" | ||
:initarg :id | ||
:type string | ||
:documentation "The org-id for this card.") | ||
(inherited-tags | ||
:initform "" | ||
:initarg :inherited-tags | ||
:type string | ||
:documentation "Inherited tags in the form :taga:tagb:." | ||
) | ||
(local-tags | ||
:initform "" | ||
:initarg :local-tags | ||
:type string | ||
:documentation "Tags on the card itself in the form :taga:tagb:.") | ||
(path | ||
:initform "" | ||
:initarg :path | ||
:type string | ||
:documentation "Full path to the file which contains this card.") | ||
(positions | ||
:initform nil | ||
:initarg :positions | ||
:type list | ||
:documentation "The `org-fc-position's for this card.") | ||
(suspended | ||
:initform nil | ||
:initarg :suspended | ||
:type boolean | ||
:documentation "t when the card is suspended; nil otherwise.") | ||
(title | ||
:initform nil | ||
:initarg :title | ||
:type (or null string)) | ||
(type | ||
:initform nil | ||
:initarg :type | ||
:type symbol | ||
:documentation "The org-fc-* card type (e.g. double or cloze)."))) | ||
|
||
(cl-defmethod org-fc-card--to-positions ((card org-fc-card card)) | ||
"Return list of `org-fc-position' extracted from CARD." | ||
(mapcar | ||
(lambda (pos) | ||
(let ((box (plist-get pos :box)) | ||
(ease (plist-get pos :ease)) | ||
(interval (plist-get pos :interval)) | ||
(pos-pos (plist-get pos :position)) | ||
(due (plist-get pos :due))) | ||
(org-fc-position | ||
:box box | ||
:card card | ||
:due due | ||
:ease ease | ||
:interval interval | ||
:pos pos-pos))) | ||
(oref card positions))) | ||
|
||
(defun org-fc-cards--to-positions (cards) | ||
"Convert a list of CARDS (`org-fc-card's) to a list of `org-fc-positions's." | ||
(cl-loop for card in cards | ||
append (org-fc-card--to-positions card))) | ||
|
||
(provide 'org-fc-card) | ||
;;; org-fc-card.el ends here |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
;;; org-fc-position.el --- Representation of a position -*- lexical-binding: t; -*- | ||
;; | ||
;; Copyright (C) 2022 Cash Weaver | ||
;; | ||
;; Author: Cash Weaver <cashbweaver@gmail.com> | ||
;; Maintainer: Cash Weaver <cashbweaver@gmail.com> | ||
;; Created: September 26, 2022 | ||
;; Modified: September 26, 2022 | ||
;; Version: 0.0.1 | ||
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp | ||
;; Homepage: https://github.com/cashweaver/org-fc-position | ||
;; Package-Requires: ((emacs "24.3")) | ||
;; | ||
;; This file is not part of GNU Emacs. | ||
;; | ||
;;; Commentary: | ||
;; | ||
;; A position is a single "view" of a card. | ||
;; | ||
;;; Code: | ||
|
||
(require 'eieio) | ||
(require 'dash) | ||
|
||
(defclass org-fc-position () | ||
((box | ||
:initform 0 | ||
:initarg :box | ||
:type (integer -1 *) | ||
:documentation "The positions's current Leitner system box.") | ||
(card | ||
:initform nil | ||
:initarg :card | ||
:documentation "The `org-fc-card' which contains this position.") | ||
(due | ||
:initform nil | ||
:initarg :due | ||
:type list | ||
:custom (repeat integer) | ||
:documentation "The time at which this position is due.") | ||
(ease | ||
:initform 0 | ||
:initarg :ease | ||
:type (or float integer) | ||
:documentation "The ease factor.") | ||
(interval | ||
:initform 0 | ||
:initarg :interval | ||
:type (or float integer) | ||
:documentation "The interval, in days.") | ||
(pos | ||
:initform "" | ||
:initarg :pos | ||
:type (or integer string) | ||
:documentation "The name of the position (e.g. \"front\" for double/normal or \"0\" for cloze).")) | ||
"Represents a single position.") | ||
|
||
(cl-defmethod org-fc-position--is-due ((pos org-fc-position)) | ||
"Return t if POS is due; else nil." | ||
(time-less-p (oref pos due) (current-time))) | ||
|
||
(defun org-fc-positions--filter-due (positions) | ||
"Filter POSITIONS to include only enabled and due positions." | ||
(let ((due-enabled-positions (cl-loop for pos in positions | ||
when (and (not (oref (oref pos card) suspended)) | ||
(org-fc-position--is-due pos)) | ||
collect pos))) | ||
(if org-fc-bury-siblings | ||
(org-fc-positions--one-per-card due-enabled-positions) | ||
due-enabled-positions))) | ||
|
||
(defun org-fc-positions--one-per-card (positions) | ||
"Return filtered list of POSITIONS; only one position per card." | ||
(let ((-compare-fn (lambda (a b) | ||
(equal (oref (oref a card) id) | ||
(oref (oref b card) id))))) | ||
(-distinct positions))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been thinking about this, my original motivation was to avoid adding an dependency Another question is whether we want to use the anaphoric functions, too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think there is a anaphoric counterpart for
Would you like me to swap the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't take what I wrote as a critique of your code. The point I'm trying to make is that the increase in expressiveness of any library or complex macro ( That's ok as long as there's kind of “before jumping into the code, check out these docs” disclaimer, I'm fine with adding dash and using all the features it provides, Not sure about how existing code should be handled, |
||
|
||
(provide 'org-fc-position) | ||
;;; org-fc-position.el ends here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to specify a type that is a list of another
defclass
-type. I found some reference code which had:However, Emacs didn't throw any errors when I set the value to a list of non-
custom-type
s.