From mboxrd@z Thu Jan 1 00:00:00 1970 From: Damon Permezel Subject: Re: table --> org-drill Date: Thu, 25 Apr 2019 18:14:37 +1000 Message-ID: References: <50108959-2F57-417B-8962-D6E02E2C84EA@me.com> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Content-Type: multipart/signed; boundary="Apple-Mail=_2C2AFD10-0434-4768-9E95-784DD04A2BB0"; protocol="application/pgp-signature"; micalg=pgp-sha256 Return-path: Received: from eggs.gnu.org ([209.51.188.92]:50506) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJZWn-0005ob-Cu for emacs-orgmode@gnu.org; Thu, 25 Apr 2019 04:14:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJZWm-0002od-8Q for emacs-orgmode@gnu.org; Thu, 25 Apr 2019 04:14:45 -0400 Received: from mr85p00im-zteg06011601.me.com ([17.58.23.186]:49242) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hJZWl-0002o5-Al for emacs-orgmode@gnu.org; Thu, 25 Apr 2019 04:14:44 -0400 In-Reply-To: <50108959-2F57-417B-8962-D6E02E2C84EA@me.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Matt Price Cc: Org Mode --Apple-Mail=_2C2AFD10-0434-4768-9E95-784DD04A2BB0 Content-Type: multipart/alternative; boundary="Apple-Mail=_5FBF8B99-1D54-4864-B8B1-7811038973F9" --Apple-Mail=_5FBF8B99-1D54-4864-B8B1-7811038973F9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 2019-Apr-24, at 23:57, Damon Permezel wrote: >=20 > 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=E2=80=99m sure there are more=E2=80=A6. >=20 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 (=3D (following-char) ?#)) (not (=3D (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)))) --Apple-Mail=_5FBF8B99-1D54-4864-B8B1-7811038973F9 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

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=E2=80=99m sure there are more=E2=80=A6.


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 (=3D (following-char) ?#))
  (not (=3D = (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))))

= --Apple-Mail=_5FBF8B99-1D54-4864-B8B1-7811038973F9-- --Apple-Mail=_2C2AFD10-0434-4768-9E95-784DD04A2BB0 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEXHL/yfpKJqfg/xxnsnwZRAPzw7sFAlzBbG0ACgkQsnwZRAPz w7uXJg/+JRLCFUcflOBmrc67Ylsw6ZdixGJGJqHoMN27LyMQYjPBR9+1QsJGPaJr qz6hqCJErwVUAkVOWvCCizNc05Pr+452nDfNak3iI6hHsvKuZRBAl9trhE6WyuaW sEeIWy6s5P49ZkRFHTNxTS/u7L8PyEXIl6hOMO1itby9J4wcb20kpGIaI6O7H+U1 FfY8mASXmHyyWgBg1Hu6eyikvY2wlMLAPQKJ5/47uCHIBnbk3BN8RIgLyVOC3omV 1+CglPQWKGWeD0CITpQcqSjODrGpv4TWI5S7A5VA+dj2OAJfOWYE4obKTV8e6I0C 2LKLq2O6Qu+VHhAjxdb+SYHWMj78fZZXZdYrNWEtjKRsfnC6FQT4Nk6UqqULAi/n WosmhhU78zJAv4/YdOVLahCO+giY+44d48ZGuAfttFWO9y2a1S9TkFptpHnsDxYi u5YIIPeVrR+XeYXHkEG9ZA1dih8u7d0KwWM98/Jk6H/4yeywLDZLrcKwbktz+NlR NVplFWez3fWLcdjmK9wmvK8QQRPwgsjbK28IPSkgJBW3XWM+LYYNjmIF+JkBiV23 gyQILNpx0ji56gyhAw2a1rKAs5tGx/Yznj/E/gWjYQ2VXgM+RAkw4RA26KFGiFCU h7jCww50GlwgI2F2uXQVrO/u48SQo/PlLSZx3+yqcQd2Y+htHY4= =D2na -----END PGP SIGNATURE----- --Apple-Mail=_2C2AFD10-0434-4768-9E95-784DD04A2BB0--