emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] table --> org-drill


From: Damon Permezel
Subject: Re: [O] table --> org-drill
Date: Thu, 25 Apr 2019 18:14:37 +1000



On 2019-Apr-24, at 23:57, Damon Permezel <address@hidden> wrote:

Just noticed a bug as I was reading my post.  Just if argument-prefix is applied, it will keep trying a line with no tabs (or less than 2) and not advance the line.  I’m sure there are more….


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))))

Attachment: signature.asc
Description: Message signed with OpenPGP


reply via email to

[Prev in Thread] Current Thread [Next in Thread]