January 11, 2005

More hacks for mangling Japanese CSV

January 11, 2005 - Categories: emacs, japanese

This is for use with kdrill.

(defun sacha/kanji/get-ordered-kanji-list ()
  (let (kanji-list)
    (while (not (eobp))
      (let ((c (char-after (point))))
        (cond
         ((= c ?\"))
         ((= c ?\n))
         ((= c ?:) (forward-line 1) (forward-char -1))
         (t (add-to-list 'kanji-list c))))
      (forward-char 1))
    kanji-list))

(defun sacha/kanji/ordered-usefile-to-kill ()
  (interactive)
  ;; Look up kanji in kanjidic
  (let ((list (sacha/kanji/get-ordered-kanji-list)))
    (kill-new
     (with-current-buffer (find-file-noselect "/usr/share/edict/kanjidic")
       (mapconcat
        (lambda (kanji)
          (goto-char (point-min))
          (when (search-forward (char-to-string kanji) nil t)
            (skip-syntax-forward " ")
            (buffer-substring-no-properties (point) (and (skip-syntax-forward "^ ") (point)))))
        list
        "\n")))))

On Technorati: ,

Japanese flashcards

January 11, 2005 - Categories: emacs, japanese

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: ,

Cat — 55 words

January 11, 2005 - Categories: Uncategorized

“Your cat’s vicious.”

“Neko?” I stroked the cat sleeping on my lap. She yawned, stretched,
and curled up around my hand.

“Absolutely antisocial.” He shivered. “Psycho. Pure evil.”

“Nonsense. She’s a darling.” I leaned in and whispered, “Just let her
think she’s boss.”

A hiss and a deep scratch told me I wasn’t quiet enough.

- In response to the “ABSOLUTELY ANTISOCIAL” prompt on the flashxer mailing list

On Technorati: ,

planner-multi-read-name

January 11, 2005 - Categories: emacs, planner

I read through crm.el on the train. Now that I have an idea as to how
completing reads work, I think I’ve gotten spaces in multiple page
names to work. I’m still having problems—TAB complains that something
is read-only—but this looks promising.

../emacs/dev/planner/planner-multi.el

On Technorati: ,

Proof of concept: Deleting private tasks

January 11, 2005 - Categories: emacs, planner

It’s easy to tweak Planner. For example, the following two lines of
code delete all lines that contain {{private}} before publishing. Your
planner pages will be fine, but the published HTML won’t contain them.

(add-to-list 'planner-publishing-markup (lambda () (delete-matching-lines "{{private}}")))
(planner-update-wiki-project)

Fun, isn’t it?

On Technorati: ,

Testing testing testing

January 11, 2005 - Categories: !Uncategorized

Hmm. This shouldn’t pass by a plan page at all.