|
From: | Damon Permezel |
Subject: | Re: [O] table --> org-drill |
Date: | Thu, 25 Apr 2019 18:14:37 +1000 |
This version is somewhat better. It skips comment lines and org headers lines, plus fixes a few bugs, while introducing an equal measure of new ones + 1. (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 (end-of-line) (point))) (tsv (vector)) (prev nil)) (narrow-to-region beg end) (goto-char beg) (when (and (not (= (following-char) ?#)) (not (= (following-char) ?*))) (setq prev beg) (while (< (point) end) (when (looking-at "\t") (setq tsv (vconcat tsv (vector (buffer-substring prev (point))))) (setq prev (+ 1 (point)))) (forward-word)) (setq tsv (vconcat tsv (vector (buffer-substring prev (point)))))) tsv )))) (defun txt-to-drill (arg) "convert TSV to drill" (interactive "p") (let ((query (concat "*** Query :drill:\n" " :PROPERTIES:\n" " :END:\n")) (answer (concat "**** Answer\n"))) (while (> arg 0) (setq arg (- arg 1)) (let ((tsv (txt-to-TSV))) (if (> (length tsv) 1) (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] |