Browse Source

Added org-drill and jam-mode

I added a hacky copy to drill thing which is probably only useful for me
master
Macoy Madson 3 years ago
parent
commit
828ddc10a4
  1. 5
      Emacs/dotEmacs.el
  2. 97
      Emacs/drill-customizations.el
  3. 272
      Emacs/jam-mode.el
  4. 3496
      Emacs/org-drill.el
  5. 177
      Emacs/org-learn.el
  6. 3
      Emacs/syntaxes.el

5
Emacs/dotEmacs.el

@ -172,6 +172,9 @@
;; Various customizations for Org mode
(load-user-file "org-customizations.el")
;; Org-drill and associated customizations
(load-user-file "drill-customizations.el")
;; Make it easier to create and switch desktops
(load-user-file "desktop-management.el")
@ -276,6 +279,8 @@ static char *gnus-pointer[] = {
\"###########.######\" };") t)
'(large-file-warning-threshold 60000000)
'(linum-format " %7i ")
'(org-modules
'(org-bbdb org-bibtex org-docview org-gnus org-info org-irc org-mhe org-rmail org-w3m org-drill))
'(org-support-shift-select t)
'(package-archives
(quote

97
Emacs/drill-customizations.el

@ -0,0 +1,97 @@
;; Macoy's hacky setup for using Org-drill
;; Org drill
(load-user-file "org-learn.el")
(load-user-file "org-drill.el")
(setq macoy-org-drill-file "~/Dropbox/Org/Japanese/macoy-drill.org")
(defun macoy-org-drill-convert-subtree-to-twosided ()
(interactive)
;; Convert every item to whatever the subtree requested
(while (outline-next-heading)
;; Standard vocab card; convert to org-drill double-sided format
(org-insert-heading)
(org-set-property "DRILL_CARD_TYPE" "twosided")
(insert "w :drill:")
(outline-next-heading)
(org-demote-subtree)
(skip-chars-forward "\* ")
(insert "a\n")
(next-line)
(org-insert-heading)
(insert "b\n")
)
)
;; I used org-drill-copy-entry-to-other-buffer as a reference
(defun macoy-org-drill-add-subtree ()
"Copies org subtree at point to `macoy-org-drill-file` and converts
it to the appropriate org-drill format based on the subtree's tags."
(interactive)
(let ((subtree-tags (org-get-local-tags)))
(org-copy-subtree)
(switch-to-buffer "*Macoy-Drill-Convert*")
(with-current-buffer "*Macoy-Drill-Convert*"
(org-mode)
;; Override the level because we don't care about levels in drill,
;; but want to see them in non-drill notes
(org-paste-subtree 1)
(macoy-org-drill-convert-subtree-to-twosided)
(append-to-file nil nil macoy-org-drill-file)
)
;; (org-toggle-tag "drill" 'on)
;; ;; Convert every item to whatever the subtree requested
;; (while (outline-next-heading)
;; ;; Standard vocab card; convert to org-drill double-sided format
;; (when (member "vocab" subtree-tags)
;; ;; (org-toggle-tag "vocab" 'on)
;; (org-insert-subheading
;; )
;; )
;; )
)
)
;; (defun macoy-test-org-element ()
;; (interactive)
;; ;; ;; (message "%s" (org-element-parse-buffer))
;; ;; (message "%s" (org-element-interpret-data
;; ;; (org-element-map (org-element-parse-buffer) 'item
;; ;; (lambda (item)
;; ;; ;; (when (member "vocab" (org-element-property :tags item))
;; ;; ;; item
;; ;; ;; )
;; ;; (message "whahhahta")
;; ;; item
;; ;; )
;; ;; ))
;; ;; )
;; (org-copy-subtree)
;; (message "%s" (org-element-map
;; (with-temp-buffer
;; (org-paste-subtree 0)
;; (org-element-parse-buffer))
;; '(headline section)
;; 'identity))
;; (message "interpreted: %s" (org-element-interpret-data (org-element-map
;; (with-temp-buffer
;; (insert (and kill-ring (current-kill 0)))
;; (org-element-parse-buffer))
;; '(headline section)
;; 'identity)))
;; (message "clipboard: %s" (setq tree (and kill-ring (current-kill 0))))
;; ;; This is the correct way it looks like, although org-paste-subtree 0 should be used instead of the kill-ring stuff I think
;; ;; http://ergoemacs.org/emacs/elisp_parse_org_mode.html
;; ;; How do I edit??
;; (message "just parse: %s" (with-temp-buffer
;; (insert (and kill-ring (current-kill 0)))
;; (org-element-interpret-data (org-element-parse-buffer))))
;; )

272
Emacs/jam-mode.el

@ -0,0 +1,272 @@
;; *****************************************************************************
;;
;; jam-mode.el
;; Font-lock support for Jam files
;;
;; Copyright (C) 2003, 2004, Rob Walker <address@hidden>
;; http://www.tenfoot.org.uk/emacs/
;; 12 May 2004 - 0.3 - Fix keyword quoting, XEmacs support
;; 22 Mar 2003 - 0.2 - Autoload
;; 04 Mar 2003 - 0.1 - Added imenu support and basic indentation
;;
;; Copyright (C) 2000, Eric Scouten
;; Started Sat, 05 Aug 2000
;;
;; *****************************************************************************
;;
;; This 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, or (at your
;; option)
;; any later version.
;;
;; jam-mode.el 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; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;; *****************************************************************************
;;
;; To add font-lock support for Jam files, simply add the line
;; (require 'jam-mode) to your .emacs file. Make sure generic-mode.el
;; is visible in your load-path as well.
;;
;; *****************************************************************************
;; Generic-mode is a meta-mode which can be used to define small modes
;; which provide basic comment and font-lock support. Jam-mode depends
;; on
;; this mode.
;; generic.el for GNU emacs, generic-mode.el for XEmacs
(if (string-match "XEmacs\\|Lucid" emacs-version)
(require 'generic-mode)
(require 'generic))
(defun jam-mode-quote-keywords (keywords)
"Returns a list of expressions that match each element in KEYWORDS.
For generic-mode, each element is quoted. For generic, each element is
unchanged."
(if (featurep 'generic-mode)
(mapcar 'regexp-quote keywords)
keywords))
;;;###autoload
(define-generic-mode 'jam-mode
; Jam comments always start with '#'
(list ?# )
; Jam keywords (defined later)
nil
; Extra stuff to colorize
(list
; Jam keywords
(generic-make-keywords-list
(list "actions" "bind" "case" "default" "else" "existing" "for" "if"
"ignore" "in" "include" "local" "on" "piecemeal" "quietly" "rule"
"switch"
"together" "updated")
'font-lock-keyword-face)
; Jam built-in variables
(generic-make-keywords-list
(list
"JAMDATE" "JAMSHELL" "JAMUNAME" "JAMVERSION" "MAC" "NT" "OS" "OS2"
"OSPLAT" "OSVER" "UNIX" "VMS")
'font-lock-constant-face)
; Jam built-in targets
(generic-make-keywords-list
(list
"ALWAYS" "DEPENDS" "ECHO" "INCLUDES" "LEAVES" "LOCATE" "NOCARE"
"NOTFILE" "NOUPDATE" "SEARCH" "TEMPORARY")
'font-lock-builtin-face)
; Jam built-in targets (warnings)
(generic-make-keywords-list
(list
"EXIT")
'font-lock-warning-face)
; Jambase rules
(generic-make-keywords-list
(jam-mode-quote-keywords
(list
"Archive" "As" "Bulk" "Cc" "CcMv" "C++" "Chgrp" "Chmod"
"Chown" "Clean" "CreLib"
"Depends" "File" "Fortran" "GenFile" "GenFile1" "HardLink"
"HdrRule" "Install" "InstallBin" "InstallFile"
"InstallInto" "InstallLib" "InstallMan"
"InstallShell" "Lex" "Library" "LibraryFromObjects" "Link"
"LinkLibraries"
"Main" "MainFromObjects" "MakeLocate" "MkDir" "MkDir1"
"Object" "ObjectC++Flags"
"ObjectCcFlags" "ObjectHdrs" "Objects" "Ranlib" "RmTemps"
"Setuid" "SubDir"
"SubDirC++Flags" "SubDirCcFlags" "SubDirHdrs" "SubInclude"
"Shell" "Undefines"
"UserObject" "Yacc" "Yacc1" "BULK" "FILE" "HDRRULE"
"INSTALL" "INSTALLBIN" "INSTALLLIB"
"INSTALLMAN" "LIBRARY" "LIBS" "LINK" "MAIN" "SETUID"
"SHELL" "UNDEFINES"
"addDirName" "makeCommon" "makeDirName" "makeGrist"
"makeGristedName" "makeRelPath"
"makeString" "makeSubDir" "makeSuffixed" "unmakeDir"))
'font-lock-function-name-face)
; Jambase built-in targets
(generic-make-keywords-list
(list
"all" "clean" "dirs" "exe" "files" "first" "install" "lib" "obj"
"shell" "uninstall")
'font-lock-builtin-face)
; Jambase built-in variables
(generic-make-keywords-list
(jam-mode-quote-keywords
(list
"ALL_LOCATE_TARGET" "AR" "ARFLAGS" "AS" "ASFLAGS" "AWK"
"BCCROOT" "BINDIR" "CC" "CCFLAGS"
"C++" "C++FLAGS" "CHMOD" "CP" "CRELIB" "CW" "CWGUSI"
"CWMAC" "CWMSL" "DOT" "DOTDOT"
"EXEMODE" "FILEMODE" "FORTRAN" "FORTRANFLAGS" "GROUP"
"HDRGRIST" "HDRPATTERN" "HDRRULE"
"HDRS" "HDRSCAN" "HDRSEARCH" "INSTALL" "JAMFILE" "JAMRULES"
"LEX" "LIBDIR" "LINK"
"LINKFLAGS" "LINKLIBS" "LOCATE_SOURCE" "LOCATE_TARGET" "LN"
"MACINC" "MANDIR" "MKDIR"
"MODE" "MSLIB" "MSLINK" "MSIMPLIB" "MSRC" "MSVC" "MSVCNT"
"MV" "NEEDLIBS" "NOARSCAN"
"OSFULL" "OPTIM" "OWNER" "RANLIB" "RCP" "RELOCATE" "RM"
"RSH" "RUNVMS" "SEARCH_SOURCE"
"SED" "SHELLHEADER" "SHELLMODE" "SLASH" "SLASHINC"
"SOURCE_GRIST" "STDHDRS" "STDLIBPATH"
"SUBDIR" "SUBDIRASFLAGS" "SUBDIRC++FLAGS" "SUBDIRCCFLAGS"
"SUBDIRHDRS" "SUBDIR_TOKENS"
"SUFEXE" "SUFLIB" "SUFOBJ" "UNDEFFLAG" "UNDEFS" "WATCOM"
"YACC" "YACCFLAGS" "YACCFILES"))
'font-lock-function-name-face)
; Jam variable references $(foo)
'("$(\\([^ :\\[()\t\r\n]+\\)[)\\[:]" 1 font-lock-variable-name-face))
; Apply this mode to all files called Jamfile, Jamrules or Jambase
(list "\\(Jamfile\\|Jamrules\\|Jambase\\)\\'")
; Attach setup function so we can modify syntax table.
(list 'jam-mode-setup-function)
; Brief description
"Generic mode for Jam rules files")
(defun jam-mode-setup-function ()
(modify-syntax-entry ?_ "w")
(modify-syntax-entry ?. "w")
(modify-syntax-entry ?/ "w")
(modify-syntax-entry ?+ "w")
(modify-syntax-entry ?# "<")
(modify-syntax-entry ?\n ">")
(setq imenu-generic-expression
'(("Rules" "^rule\\s-+\\([A-Za-z0-9_]+\\)" 1)
("Actions" "^actions\\s-+\\([A-Za-z0-9_]+\\)" 1)))
(imenu-add-to-menubar "Jam")
(make-local-variable 'indent-line-function)
(setq indent-line-function 'jam-indent-line)
(run-hooks 'jam-mode-hook)
)
(defvar jam-mode-hook nil)
(defvar jam-indent-size 2
"Amount to indent by in jam-mode")
(defvar jam-case-align-to-colon t
"Whether to align case statements to the colons")
(defun jam-indent-line (&optional whole-exp)
"Indent current line"
(interactive)
(let ((indent (jam-indent-level))
(pos (- (point-max) (point))) beg)
(beginning-of-line)
(setq beg (point))
(skip-chars-forward " \t")
(if (zerop (- indent (current-column)))
nil
(delete-region beg (point))
(indent-to indent))
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))
))
(defun jam-goto-block-start ()
"Goto the start of the block containing point (or beginning of buffer if not in a block)"
(let ((l 1))
(while (and (not (bobp)) (> l 0))
(skip-chars-backward "^{}")
(unless (bobp)
(backward-char)
(setq l (cond
((eq (char-after) ?{) (1- l))
((eq (char-after) ?}) (1+ l))
)))
)
(bobp))
)
(defun jam-indent-level ()
(save-excursion
(let ((p (point))
ind
(is-block-start nil)
(is-block-end nil)
(is-case nil)
(is-switch nil)
switch-ind)
;; see what's on this line
(beginning-of-line)
(setq is-block-end (looking-at "^[^{\n]*}\\s-*$"))
(setq is-block-start (looking-at ".*{\\s-*$"))
(setq is-case (looking-at "\\s-*case.*:"))
;; goto start of current block (0 if at top level)
(if (jam-goto-block-start)
(setq ind 0)
(setq ind (+ (current-indentation) jam-indent-size)))
;; increase indent in switch statements (not cases)
(setq is-switch (re-search-backward "^\\s-*switch" (- (point)
100) t))
(when (and is-switch (not (or is-block-end is-case)))
(goto-char p)
(setq ind (if (and jam-case-align-to-colon
(re-search-backward
"^\\s-*case.*?\\(:\\)"))
(+ (- (match-beginning 1) (match-beginning 0))
jam-indent-size)
(+ ind jam-indent-size)))
)
;; indentation of this line is jam-indent-size more than that of the
;; previous block
(cond (is-block-start ind)
(is-block-end (- ind jam-indent-size))
(is-case ind)
(t ind)
)
)))
(provide 'jam-mode)
;; jam-mode.el ends here

3496
Emacs/org-drill.el

File diff suppressed because it is too large

177
Emacs/org-learn.el

@ -0,0 +1,177 @@
;;; org-learn.el --- Implements SuperMemo's incremental learning algorithm
;; Copyright (C) 2009-2012 Free Software Foundation, Inc.
;; Author: John Wiegley <johnw at gnu dot org>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 6.32trans
;;
;; This file is not part of GNU Emacs.
;;
;; GNU Emacs 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.
;; GNU Emacs 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 not, see <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;; The file implements the learning algorithm described at
;; http://supermemo.com/english/ol/sm5.htm, which is a system for reading
;; material according to "spaced repetition". See
;; http://en.wikipedia.org/wiki/Spaced_repetition for more details.
;;
;; To use, turn on state logging and schedule some piece of information you
;; want to read. Then in the agenda buffer type
(require 'org)
(eval-when-compile
(require 'cl))
(defgroup org-learn nil
"Options concerning the learning code in Org-mode."
:tag "Org Learn"
:group 'org-progress)
(defcustom org-learn-always-reschedule nil
"If non-nil, always reschedule items, even if retention was \"perfect\"."
:type 'boolean
:group 'org-learn)
(defcustom org-learn-fraction 0.5
"Controls the rate at which EF is increased or decreased.
Must be a number between 0 and 1 (the greater it is the faster
the changes of the OF matrix)."
:type 'float
:group 'org-learn)
(defun initial-optimal-factor (n ef)
(if (= 1 n)
4
ef))
(defun get-optimal-factor (n ef of-matrix)
(let ((factors (assoc n of-matrix)))
(or (and factors
(let ((ef-of (assoc ef (cdr factors))))
(and ef-of (cdr ef-of))))
(initial-optimal-factor n ef))))
(defun set-optimal-factor (n ef of-matrix of)
(let ((factors (assoc n of-matrix)))
(if factors
(let ((ef-of (assoc ef (cdr factors))))
(if ef-of
(setcdr ef-of of)
(push (cons ef of) (cdr factors))))
(push (cons n (list (cons ef of))) of-matrix)))
of-matrix)
(defun inter-repetition-interval (n ef &optional of-matrix)
(let ((of (get-optimal-factor n ef of-matrix)))
(if (= 1 n)
of
(* of (inter-repetition-interval (1- n) ef of-matrix)))))
(defun modify-e-factor (ef quality)
(if (< ef 1.3)
1.3
(+ ef (- 0.1 (* (- 5 quality) (+ 0.08 (* (- 5 quality) 0.02)))))))
(defun modify-of (of q fraction)
(let ((temp (* of (+ 0.72 (* q 0.07)))))
(+ (* (- 1 fraction) of) (* fraction temp))))
(defun calculate-new-optimal-factor (interval-used quality used-of
old-of fraction)
"This implements the SM-5 learning algorithm in Lisp.
INTERVAL-USED is the last interval used for the item in question.
QUALITY is the quality of the repetition response.
USED-OF is the optimal factor used in calculation of the last
interval used for the item in question.
OLD-OF is the previous value of the OF entry corresponding to the
relevant repetition number and the E-Factor of the item.
FRACTION is a number belonging to the range (0,1) determining the
rate of modifications (the greater it is the faster the changes
of the OF matrix).
Returns the newly calculated value of the considered entry of the
OF matrix."
(let (;; the value proposed for the modifier in case of q=5
(mod5 (/ (1+ interval-used) interval-used))
;; the value proposed for the modifier in case of q=2
(mod2 (/ (1- interval-used) interval-used))
;; the number determining how many times the OF value will
;; increase or decrease
modifier)
(if (< mod5 1.05)
(setq mod5 1.05))
(if (< mod2 0.75)
(setq mod5 0.75))
(if (> quality 4)
(setq modifier (1+ (* (- mod5 1) (- quality 4))))
(setq modifier (- 1 (* (/ (- 1 mod2) 2) (- 4 quality)))))
(if (< modifier 0.05)
(setq modifier 0.05))
(setq new-of (* used-of modifier))
(if (> quality 4)
(if (< new-of old-of)
(setq new-of old-of)))
(if (< quality 4)
(if (> new-of old-of)
(setq new-of old-of)))
(setq new-of (+ (* new-of fraction) (* old-of (- 1 fraction))))
(if (< new-of 1.2)
(setq new-of 1.2)
new-of)))
(defvar initial-repetition-state '(-1 1 2.5 nil))
(defun determine-next-interval (n ef quality of-matrix)
(assert (> n 0))
(assert (and (>= quality 0) (<= quality 5)))
(if (< quality 3)
(list (inter-repetition-interval n ef) (1+ n) ef nil)
(let ((next-ef (modify-e-factor ef quality)))
(setq of-matrix
(set-optimal-factor n next-ef of-matrix
(modify-of (get-optimal-factor n ef of-matrix)
quality org-learn-fraction))
ef next-ef)
;; For a zero-based quality of 4 or 5, don't repeat
(if (and (>= quality 4)
(not org-learn-always-reschedule))
(list 0 (1+ n) ef of-matrix)
(list (inter-repetition-interval n ef of-matrix) (1+ n)
ef of-matrix)))))
(defun org-smart-reschedule (quality)
(interactive "nHow well did you remember the information (on a scale of 0-5)? ")
(let* ((learn-str (org-entry-get (point) "LEARN_DATA"))
(learn-data (or (and learn-str
(read learn-str))
(copy-list initial-repetition-state)))
closed-dates)
(setq learn-data
(determine-next-interval (nth 1 learn-data)
(nth 2 learn-data)
quality
(nth 3 learn-data)))
(org-entry-put (point) "LEARN_DATA" (prin1-to-string learn-data))
(if (= 0 (nth 0 learn-data))
(org-schedule t)
(org-schedule nil (time-add (current-time)
(days-to-time (nth 0 learn-data)))))))
(provide 'org-learn)
;;; org-learn.el ends here

3
Emacs/syntaxes.el

@ -25,6 +25,9 @@
)
)
;; Jam
(load-user-file "jam-mode.el")
;;
;; Custom syntax definitions
;;

Loading…
Cancel
Save