all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how to select a source code block and print it to a postscript file
@ 2017-09-09  9:25 dmg
  2017-09-09 21:57 ` dmg
  0 siblings, 1 reply; 2+ messages in thread
From: dmg @ 2017-09-09  9:25 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2139 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 5427 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-09 21:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-09  9:25 how to select a source code block and print it to a postscript file dmg
2017-09-09 21:57 ` dmg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.