|
From: | Damon Permezel |
Subject: | Re: [O] table --> org-drill |
Date: | Wed, 24 Apr 2019 23:54:01 +1000 |
Hi. I am trying to learn Japanese and I am creating word lists as: Kanji/Katakana <TAB> Katakana <TAB> meaning 理由 りゆう reason 地理 ちり geography 無理な むりな impossible 特に とくに especially 安い やすい cheap I just now scraped together the following to turn it into org-drill format. I have not written any elisp for probably at least 40 years so, as they say, よろしくお願いします。 You should be able to munge it for your purposes. (defun txt-to-TSV () "turn a tab-separated text line into TSV" (interactive) (save-mark-and-excursion (save-restriction (let ((beg (progn (beginning-of-line) (point))) (end (progn (forward-line) (if (looking-at "\n") (- (point) 1) (point)))) (tabs nil) (tsv (vector)) (prev nil)) (narrow-to-region beg end) (goto-char beg) (setq tabs (vector beg)) (setq prev beg) (while (< (point) end) (if (looking-at "\t") (progn (setq tabs (vconcat tabs (vector (point)))) (setq tsv (vconcat tsv (vector (buffer-substring prev (point))))) (setq prev (+ 1 (point))))) (forward-word)) (setq tabs (vconcat tabs (vector end))) (setq tsv (vconcat tsv (vector (buffer-substring prev (point))))) )) )) (defun txt-to-drill (arg) "convert TSV to drill" (interactive "p") (while (> arg 0) (setq arg (- arg 1)) (let ((tsv (txt-to-TSV)) (query (concat "*** Query :drill:\n" " :PROPERTIES:\n" " :END:\n")) (answer (concat "**** Answer\n"))) (if (> (length tsv) 2) (progn (beginning-of-line) (insert "\n" query (aref tsv 0)) (insert "\n" answer (aref tsv 1)) (let ((i 2)) (while (< i (length tsv)) (insert "\n" (aref tsv i)) (setq i (+ 1 i)))) (insert "\n") (insert "# ") (beginning-of-line) (forward-line))) )))
|
signature.asc
Description: Message signed with OpenPGP
[Prev in Thread] | Current Thread | [Next in Thread] |