;; flashcard.el -- Help humans memorize by making a buffer mimic flashcards. ;; $Id: flashcard.el 1.2 1999/02/16 20:38:13 Timothy Exp $ ;; This file is not part of Emacs ;; COPYRIGHT NOTICE ;; ;; Copyright (C) 1999 Tim Christian ;; ;; 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 2 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 GNU Emacs. If you did not, write to the Free Software Foundation, ;; Inc., 675 Mass Ave., Cambridge, MA 02139, USA. ;; ;; INSTALLATION ;; ;; Put this file on your load-path and add the following to ~/.emacs: ;; (autoload 'tjc-flashcard "flashcard" "Process flashcard entry file" t) ;; (autoload 'tjc-make-flashcard-entry "flashcard" "Make flashcard entry" t) ;; ;; You may want to bind the routines to keys, like this: ;; (global-set-key "\C-ce" 'tjc-make-flashcard-entry) ;; (global-set-key "\C-cf" 'tjc-flashcard) ;; ;; USAGE ;; ;; Create new buffer and execute tjc-make-flashcard-entry to add ;; flash card entries. After you finish making entries, execute ;; tjc-flashcard to process the file as a series of flashcards. ;; ;; INSPIRATION ;; ;; I wanted a routine that would enable me to learn other ;; spoken/written (not programming) languages. Emacs, with its ;; wonderful multi-national support and editing capabilities ;; (iso-accents-mode), (iso-accents-customize) made an ideal vehicle ;; for entering in the text to learn and running a program to quiz ;; human. ;; (defun tjc-flashcard (flashcard-file) "Act like a flash card system. Show user information, wait for user to demonstrate readiness to see corresponding information. If what user thought was correct was correct, then no need to show this card anymore." (interactive "fEnter the flashcard filename: ") (require 'cookie1) (let* ((flashcard-buffer-name "*flashcards*") (cookie-preload-msg (concat "Loading " flashcard-file "...")) (cookie-postload-msg (concat "Loading " flashcard-file "...done")) (flashcards (cookie-snarf flashcard-file cookie-preload-msg cookie-postload-msg)) (known 0) (unknown 1)) (shuffle-vector flashcards) (if (y-or-n-p "Reverse (flip) the order? ") (progn (setq known 1 unknown 0))) (switch-to-buffer flashcard-buffer-name) (let* ((total (length flashcards)) (done (make-bool-vector total nil)) (run 0) (qanda "") (correct 0) (remaining 0) (quit nil) (message-log "") (index 0) (resp 0)) (while (and (< correct total) (not quit)) (setq index 0) (while (and (< index total) (not quit)) (when (not (elt done index)) (erase-buffer) (setq remaining (- total correct)) (insert (format "[%s] " flashcard-file)) (insert (format "[Total:%d] [Correct:%d] [ToDo:%d] [Run:%d]\n" total correct remaining run)) (insert-char ?= (- (window-width) 1)) (newline) (setq qanda (split-string (elt flashcards index) "\n")) (insert (elt qanda known)) (insert-char ?- (- (window-width) 1)) (newline) (setq resp (read-char (concat message-log "Press key for next answer..."))) (insert (elt qanda unknown)) (setq resp (read-char "Correct? [y,n,r,q] ")) (cond ((or (eq resp ?y) (eq resp ?Y)) (setq message-log "Got previous one correct! ") (aset done index t) (setq correct (1+ correct))) ((or (eq resp ?q) (eq resp ?Q)) (kill-buffer flashcard-buffer-name) (setq quit t)) ((or (eq resp ?r) (eq resp ?R)) (message "Recursive edit mode. C-M-c (exit-recursive-edit) to return to flashcard.") (recursive-edit) (message "Re-doing last question.") (sleep-for 2) (setq index (1- index))) (t (setq message-log "Try previous one again later. "))) (sit-for 0)) (setq index (1+ index))) (setq run (1+ run) message-log (concat message-log "End of a run. ")) (sit-for 0)) (if (not quit) (insert "\n******** Congrats, you did them all correctly! ********\n"))))) (defun tjc-make-flashcard-entry nil "Build a flashcard entry in a buffer for use by tjc-flashcard." (interactive) (goto-char (point-max)) ; When we are in a new buffer, make a header comment. ; Less than 3 chars in should be sufficient to determine if new file. (when (< (point-max) 4) (insert "Creation: ") (when (not (eq user-mail-address nil)) (insert user-mail-address ", ")) (insert (format-time-string "%a %b %d %T %Z %Y") "\n" "Comment: " (read-string "Your comment about this file: ") "\n\n" "Flashcard entry:\n" "\tPlace things on one \"side\" of the \"card\" before the ^B.\n" "\tPlace things on the other \"side\" of the \"card\" after the ^B.\n" "\tThe ^@ symbols separate \"cards.\"\n" "\tUse tjc-make-flashcard-entry to add new \"cards\" to this buffer.\n" "Flashcard processing:\n" "\tAfter you finish making entries, save the buffer to a file.\n" "\tUse tjc-flashcard to process that file like flashcards.\n\n" "Anything before the following ^@ is a comment.\n")) ; Make sure we are on a new line. (if (eq next-line-add-newlines nil) (newline)) ; Place for the first and next entries (insert "\n\n\n") (goto-char (- (point-max) 5)) (save-buffer))