From: Damon Permezel <permezel@me.com>
To: Matt Price <moptop99@gmail.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: table --> org-drill
Date: Thu, 25 Apr 2019 18:14:37 +1000 [thread overview]
Message-ID: <E1EF4895-FAFD-480B-9FFD-5A7D28160D7C@me.com> (raw)
In-Reply-To: <50108959-2F57-417B-8962-D6E02E2C84EA@me.com>
[-- Attachment #1.1: Type: text/plain, Size: 1789 bytes --]
> On 2019-Apr-24, at 23:57, Damon Permezel <permezel@me.com> 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 #1.2: Type: text/html, Size: 7521 bytes --]
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2019-04-25 8:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-22 13:18 table --> org-drill Matt Price
2019-04-24 13:54 ` Damon Permezel
2019-04-24 13:57 ` Damon Permezel
2019-04-25 8:14 ` Damon Permezel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1EF4895-FAFD-480B-9FFD-5A7D28160D7C@me.com \
--to=permezel@me.com \
--cc=emacs-orgmode@gnu.org \
--cc=moptop99@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).