6089 comments
2357 subscribers
6235 on Twitter
Subscribe! Feed reader E-mail

Japanese flashcards

This extracts all kanji in the buffer and converts them to the format
expected by flashcard.el.

(defun sacha/kanji/get-ordered-kanji-list ()
  "Return a list of characters in the buffer."
  (goto-char (point-min))
  (let (kanji-list)
    (while (not (eobp))
      (let ((c (char-after (point))))
        (when (>= c ?亜) (add-to-list 'kanji-list c)))
      (forward-char 1))
    kanji-list))

(defun sacha/kanji/to-flashcard-j2e (&optional list)
  "Return a Japanese-English flashcard set.
If LIST is non-nil, use that instead of the current buffer."
  (interactive (list (sacha/kanji/get-ordered-kanji-list)))
  (unless list (setq list (sacha/kanji/get-ordered-kanji-list)))
  (let ((result
         (with-current-buffer (find-file-noselect "/usr/share/edict/kanjidic")
           (mapconcat
            (lambda (kanji)
              (goto-char (point-min))
              (when (re-search-forward (format "^%c.*?{\\(.*\\)}" kanji) nil t)
                (format "%c : %s\n"
                        kanji
                        (replace-regexp-in-string "}\\s-+{" "," (match-string 1)))))
            list
            ""))))
    (if (interactive-p) (kill-new result) result)))

(defun sacha/flashcard-method-leitner-check-answer (card answer)
  "Check answer for correctness. Allow multiple correct answers and provide feedback."
  (if (member answer (split-string (flashcard-card-answer card) ","))
      (progn
        (flashcard-insert "Correct! Answer is:\n"
                          (propertize (flashcard-card-answer card)
                                      'face 'flashcard-answer-face
                                      'rear-nonsticky t)
                          "\n"
                          "\n")
        t)
    (flashcard-insert "The correct answer is:\n"
                      (propertize (flashcard-card-answer card)
                                  'face 'flashcard-answer-face
                                  'rear-nonsticky t)
                      "\n"
                      "\n")
    (y-or-n-p "Was your answer correct? ")))

(setq flashcard-method-check-answer-function 'sacha/flashcard-method-leitner-check-answer)
(add-to-list 'auto-mode-alist '("\\.deck\\'" . flashcard-mode))
(add-hook 'flashcard-mode-hook 'flashcard-add-scroll-to-bottom)
(add-hook 'flashcard-positive-feedback-functions 'flashcard-feedback-highlight-answer)
(add-hook 'flashcard-positive-feedback-functions 'flashcard-feedback-congratulate)
(add-hook 'flashcard-positive-feedback-functions 'flashcard-method-leitner-positive-feedback)

On Technorati: ,

Short URL: http://sachachua.com/blog/p/2555

On This Day...

  • 2013: Reading old letters and relearning how to write — a snippet from my 2006 annual letter I’m tremendously lucky to have family and friends who humour me by writing letters. [...]
  • 2012: Tip: Use visibility to motivate new habits — The urge to check things off can be a great way to start a new habit. On our recent trip [...]
  • 2011: Wrapping up projects and preparing for the next one — We’re in the final phases of our two Drupal projects. We’re writing test scripts, fixing bugs, and loading production data. [...]
  • 2010: Information gardening tasks — A large part of my work involves capturing and organizing information. It takes a surprising lot of time and thought. [...]
  • 2010: La-Z-Boy cinemas, massages, and seafood — It’s not like a trip home to the Philippines means stocking up on cheap export overruns or taking advantage [...]
  • 2009: Finally figured out how to set up a shared Git repository — After a few hours of struggling with it, I gave up on trying to get Git working over WebDAV. I [...]
  • 2007: Aha! — I’ve been thinking about picking up tennis. I’m not in shape for it yet, but I think it will be a [...]
  • 2007: I should meet more people in Canada — Hanging out with my friends here made me realize that I really do need to go and meet more people in [...]
  • 2007: Can’t work on map-enabled prototype — Slow Internet connectivity means that prototyping with Google Maps will be a royal pain. What else can I focus on? Maybe [...]
  • 2005: Testing testing testing — Hmm. This shouldn’t pass by a plan page at all.
  • 2005: Proof of concept: Deleting private tasks — It’s easy to tweak Planner. For example, the following two lines of code delete all lines that contain {{private}} before publishing. [...]
  • 2005: planner-multi-read-name — I read through crm.el on the train. Now that I have an idea as to how completing reads work, I think [...]
  • 2005: Cat — 55 words — “Your cat’s vicious.” “Neko?” I stroked the cat sleeping on my lap. She yawned, stretched, and curled up around my hand. “Absolutely antisocial.” [...]
  • 2005: More hacks for mangling Japanese CSV — This is for use with kdrill. (defun sacha/kanji/get-ordered-kanji-list () (let (kanji-list) (while (not (eobp)) [...]
  • 2004: Kernel configuration — http://sacha.free.net.ph/notebook/personal/lifebook.config
  • 2004: Backlog of expenses — 2004.01.10 +120.00 money:expenses/entertainment LOTR 2004.01.10 -120.00 money:assets/cash LOTR 2004.01.10 +200.00 money:expenses/entertainment Timezone card 2004.01.10 -200.00 money:assets/cash Timezone card 2004.01.10 +75.00 money:expenses/dining Baked potato bacon and cheese (approximately) 2004.01.10 -200.00 money:assets/cash Baked potato bacon and cheese (approximately)
  • 2004: Reflections from the other day — How ashen my father was under the harsh fluorescent lights, I thought, as I pulled a chair up and offered to [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!