emacs-pdf

Emacs library to print buffer to PDF file.
Log | Files | Refs | README

commit 910fb088a5c4bc49aba4b531461d6cb666dcfe5c
parent 269e80f5f685b1988f27f8820e4a9ceab213272d
Author: Tomas Hlavaty <tom@logand.com>
Date:   Wed, 26 Oct 2022 00:18:00 +0200

use cl-lib

Diffstat:
Memacs-pdf.el | 52++++++++++++++++++++++++++--------------------------
1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/emacs-pdf.el b/emacs-pdf.el @@ -22,7 +22,7 @@ ;;; ;;; Some variables can be customized in pdf and ps groups. -(require 'cl) +(require 'cl-lib) (require 'printing) (defcustom pdf-line-height-factor 1.2 @@ -119,16 +119,16 @@ the end of the file ends the printable region." "Serialize cons tree x as PDF octets into the current buffer." (let (objs xrefpos) (cl-labels ((rec (x) - (etypecase x + (cl-etypecase x (integer (insert (format "\n%d" x))) (symbol (insert (format "\n%s" x))) (string (insert "\n(") - (loop + (cl-loop for c across x - do (case c + do (cl-case c (?\\ (insert "\\\\")) (?\( (insert "\\(")) (?\) (insert "\\)")) @@ -137,7 +137,7 @@ the end of the file ends the printable region." (real (insert (format "\n%f" x))) (cons - (ecase (car x) + (cl-ecase (car x) (pdf (insert "%PDF-1.4") (insert @@ -153,14 +153,14 @@ the end of the file ends the printable region." (insert (format "\n%d %d" 0 (1+ (length objs)))) (insert "\n0000000000 65535 f\r") (dolist (obj (setq objs (nreverse objs))) - (destructuring-bind (a b pos &rest c) obj + (cl-destructuring-bind (a b pos &rest c) obj (ignore a) (insert (format "\n%010d %05d n\r" pos b)))) (insert "\ntrailer") (rec `(pdf-dic /Size ,(1+ (length objs)) ,@(cdr x)))) (pdf-stream - (destructuring-bind (a &rest b) (cdr x) + (cl-destructuring-bind (a &rest b) (cdr x) (let ((x (with-temp-buffer (set-buffer-multibyte nil) (mapc #'rec b) @@ -172,7 +172,7 @@ the end of the file ends the printable region." (insert x) (insert "\nendstream")))) (pdf-obj - (destructuring-bind (a b &rest c) (cdr x) + (cl-destructuring-bind (a b &rest c) (cdr x) (push `(,a ,b ,(point)) objs) (insert (format "\n%d %d obj" a b)) (mapc #'rec c) @@ -186,35 +186,35 @@ the end of the file ends the printable region." (mapc #'rec (cdr x)) (insert "\n]")) (pdf-ref - (destructuring-bind (a b) (cdr x) + (cl-destructuring-bind (a b) (cdr x) (insert (format "\n%d %d R" a b))))))))) (set-buffer-multibyte nil) (rec x)))) (defun pdf-brook-collect (brook) "Collect all values pulled from brook." - (loop + (cl-loop with z = nil while (setq z (funcall brook)) collect z)) (defun pdf-brook-appending (brook) "Append all values pulled from brook." - (loop + (cl-loop with z = nil while (setq z (funcall brook)) appending z)) (defun pdf-brook-count (brook) "Count all values in brook." - (loop + (cl-loop with z = nil while (setq z (funcall brook)) count z)) (defun pdf-brook (x) "Make new brook from x." - (etypecase x + (cl-etypecase x (list (lambda () (pop x))))) @@ -225,12 +225,12 @@ the end of the file ends the printable region." (defun pdf-flat-brook (&rest brooks) "Compose brooks left to right, depth-first." (lambda () - (block loop + (cl-block loop (while brooks (let ((z (funcall (car brooks)))) (cond ((functionp z) (push z brooks)) - (z (return-from loop z)) + (z (cl-return-from loop z)) (t (pop brooks)))))))) ;;(pdf-brook-collect (pdf-flat-brook (pdf-brook '(1 2 3)) (pdf-brook '(4 5 6)))) @@ -293,7 +293,7 @@ header or footer." (dolist (x list) (when x (insert - (etypecase x + (cl-etypecase x (function (or (funcall x) "")) (symbol (or (symbol-value x) "")) (string x)))))) @@ -319,13 +319,13 @@ header or footer." (if footer (+ line-height ps-footer-offset) 0))) (y y0)) (lambda () - (when (<= bottom-margin (decf y line-height)) + (when (<= bottom-margin (cl-decf y line-height)) (let ((line (funcall page))) (when line `(,@(when header (prog1 (pdf-line x0 y header) (setq header nil) - (decf y (+ line-height ps-header-offset)))) + (cl-decf y (+ line-height ps-header-offset)))) ,@(when footer (prog1 (pdf-line x0 ps-bottom-margin footer) (setq footer nil))) @@ -347,7 +347,7 @@ ps-paper-type and ps-landscape-mode." (let ((lines (pdf-source-line-brook substring)) (i 0)) (lambda () - (incf i) + (cl-incf i) (let ((text (pdf-page-text lines x0 y0 line-height (when ps-print-header (pdf-header-text i npages file-name)) @@ -382,7 +382,7 @@ ps-paper-type and ps-landscape-mode." (defun pdf-region (from to &optional file-name) "Save region to PDF file." (interactive "r") - (multiple-value-bind (page-width page-height) (pdf-page-dimensions) + (cl-multiple-value-bind (page-width page-height) (pdf-page-dimensions) (let* ((coding-system-for-write 'raw-text-unix) (source-file-name (or file-name (buffer-file-name) @@ -390,7 +390,7 @@ ps-paper-type and ps-landscape-mode." (file-name (concat source-file-name ".pdf")) (x0 ps-left-margin) (y0 (- page-height ps-top-margin)) - (font-size (etypecase ps-font-size + (font-size (cl-etypecase ps-font-size (number ps-font-size) (cons (if ps-landscape-mode (car ps-font-size) @@ -416,13 +416,13 @@ ps-paper-type and ps-landscape-mode." %pages (%parent `(pdf-ref -1 0))) `(pdf - (pdf-obj ,(incf oid) + (pdf-obj ,(cl-incf oid) 0 (pdf-dic /Type /Font /Subtype /Type1 /Name /F1 /BaseFont ,pdf-base-font)) - (pdf-obj ,(incf oid) + (pdf-obj ,(cl-incf oid) 0 (pdf-dic /ProcSet (pdf-vec /PDF /Text) /Font (pdf-dic /F1 (pdf-ref ,(1- oid) 0)))) @@ -430,15 +430,15 @@ ps-paper-type and ps-landscape-mode." (pdf-pages-brook substring x0 y0 line-height font-size npages source-file-name %parent - (lambda () (incf oid)) + (lambda () (cl-incf oid)) (lambda (x) (push x %pages)))) - (pdf-obj ,(setf (cadr %parent) (incf oid)) + (pdf-obj ,(setf (cadr %parent) (cl-incf oid)) 0 (pdf-dic /Type /Pages /Count ,(length %pages) /Kids (pdf-vec ,@(nreverse %pages)) /MediaBox (pdf-vec 0 0 ,page-width ,page-height))) - (pdf-obj ,(incf oid) + (pdf-obj ,(cl-incf oid) 0 (pdf-dic /Type /Catalog /Pages (pdf-ref ,(1- oid) 0)))