From mboxrd@z Thu Jan 1 00:00:00 1970 From: dmg Subject: how to select a source code block and print it to a postscript file Date: Sat, 9 Sep 2017 02:25:15 -0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a11416d3ae41bb60558be47bb" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqc1Y-0003Bt-Lk for emacs-orgmode@gnu.org; Sat, 09 Sep 2017 05:26:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dqc1X-0005GN-C2 for emacs-orgmode@gnu.org; Sat, 09 Sep 2017 05:26:00 -0400 Received: from mail-vk0-x232.google.com ([2607:f8b0:400c:c05::232]:36872) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dqc1X-0005FH-4t for emacs-orgmode@gnu.org; Sat, 09 Sep 2017 05:25:59 -0400 Received: by mail-vk0-x232.google.com with SMTP id c82so5626337vkd.4 for ; Sat, 09 Sep 2017 02:25:57 -0700 (PDT) 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: emacs-orgmode --001a11416d3ae41bb60558be47bb Content-Type: text/plain; charset="UTF-8" hi everybody, I teach programming and I have been using org-mode for a couple years to do it. I absolutely love it. Lately I have been thinking that I would like to be able to draw on the source code using xournal (using a tablet) To do that, I need to generate a pdf. But I don't want to generate the PDF of the entire file, just of the block I am currently positioned at. I wrote the following code, but it feels clumsy, and I am not a very good emacs-lisp programmer. I put it together by extracting code here and there. Is there a better way to run ps-print-buffer (or ps-print-region) on the current block? I am currently using the :tangle parameter as a filename to be created (adding the extension .ps) the script I am running takes the postscript file, generate a pdf, and then runs xournal on it. thank you in advance for any suggestions, (defun org-src-xournal () "show the source code in xournal as a PDF" (interactive) (save-restriction (save-excursion (let* ((case-fold-search t) (tangle-file (or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info 'light)))) (user-error "Point is not in a source code block or it does not have a tangle name"))) (blockp (org-between-regexps-p "^[ \t]*#\\+begin_.*" "^[ \t]*#\\+end_.*")) (ps-file (concat tangle-file ".ps")) ) (message "Exporting: %s" ps-file) (if blockp (let ((block-start (progn (goto-char (car blockp)) (next-line) (point) )) (block-end (progn (goto-char (cdr blockp)) (previous-line) (point) )) ) (narrow-to-region block-start block-end)) (user-error "Not in a block")) (ps-print-buffer-with-faces ps-file) (shell-command (concat "code-xournal " ps-file "&")) ) ))) -- --dmg --- Daniel M. German http://turingmachine.org --001a11416d3ae41bb60558be47bb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
hi everybody,
<= br>
I teach programming and I have been using org-m= ode for a couple years to do it. I absolutely love it.
Lately I have been thinking that I would like to be able to draw on the= source code using xournal
(using a tablet)

To do that, I need to generat= e a pdf. But I don't want to generate the PDF of the entire file,
=
just of the block I am currently positioned at. I wrote = the following code, but it feels clumsy, and
I am n= ot a very good emacs-lisp programmer. I put it together by extracting code = here and there.

Is the= re a better way to run ps-print-buffer (or ps-print-region) on the current = block?
I am currently using the :tangle parameter a= s a filename to be created (adding the extension .ps)

the script I am running takes the postscrip= t file, generate a pdf, and then runs xournal on it.

thank you in advance for any suggestions,

(defun org-src-xournal ()
=C2=A0 &qu= ot;show the source code in xournal as a PDF"
=C2=A0 (interactive)
=C2=A0 (sav= e-restriction
=C2=A0 =C2=A0 (save-excursi= on
=C2=A0 =C2=A0 =C2=A0 (let* ((case-fold= -search t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (tangle-file
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(or (cdr (assq :tangle (nth 2 (org-babel-= get-src-block-info 'light))))
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(user-error "Po= int is not in a source code block or it does not have a tangle name"))= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (blockp (org-between-regexps-p "^[ \t]*#\\+begin_.*"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"^[ \t]*#\\+end_.*"))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (ps-file (c= oncat tangle-file ".ps"))
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 )
= =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 (message "Exporting: %s" ps-file)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (if blockp
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((bloc= k-start=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn (goto-char (car blockp))<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (next-line)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (point)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 (block-end
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn (goto= -char (cdr blockp))
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (previous-li= ne)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (point)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 ))
=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (narrow-to-region bloc= k-start block-end))
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (user-error "Not in a block"))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (ps-print-buffer-with-faces ps-fi= le)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (shell-co= mmand (concat "code-xournal " ps-file "&"))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 )
=C2=A0 =C2=A0 =C2=A0 )))

--
--dmg

---
Daniel M. = German
http://tur= ingmachine.org
--001a11416d3ae41bb60558be47bb--