在Emacs函数中格式化一个标题以将缓冲区打印到PDF文件中 [英] Formatting a header in an Emacs function to print a buffer to PDF w/ line wrapping

查看:82
本文介绍了在Emacs函数中格式化一个标题以将缓冲区打印到PDF文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rupert Swarbrick提出了以下三个功能,用于打印Emacs缓冲区到PDF,其中包含了哪些行(通常情况下,使用 ps-print * 函数)。



问题是这个函数是为了实现这个换行,必须要复制当前的缓冲区。这有效地打破了 ps-print-buffer-with-faces 在生成的PDF文件中的每个页面顶部显示正确的标题的能力。



作为他解决方案的一部分,Rupert Swarbrick写了一个保留这个信息的函数。然而,最终的标题总是 HeaderLinesLeft



谁可以发现错误?

 (defun harden-newlines()
(interactive)
使缓冲区中的所有换行符变得更加
(save-excursion
(goto-char(point-min))
(while(search-forward\\\
nil t)
(backward-char)
(put-text-property点)(1+(点))'hard t)
(forward-char))))

(defun spool-buffer-given-name(name)
加载ps-print)
(let((tmp ps-left-header))
(展开保护
(progn
(setq ps-left-header
(list(lambda()name)'ps-header-dirpart))
(ps-spool-buffer-with-faces))
(setf ps-left-header tmp)))

(defun print-to-pdf()
将当前文件打印到/tmp/print.pdf
(interactive)
(let((wbuf (generate-new-buffer* Wrapped *))
(sbuf(current-buffe )
(jit-lock-fontify-now)
(save-current-buffer
(set-buffer wbuf)
(insert-buffer sbuf)
(setq fill-column 95)
(longlines-mode t)
(harden-newlines)
(message(buffer-name sbuf))
(spool-buffer-given -name(buffer-name sbuf))
(kill-buffer wbuf)
(switch-to-buffer* PostScript *)
(写入文件/tmp/print.ps )
(kill-buffer(current-buffer)))
(call-processps2pdf14nil nil
/tmp/print.ps/tmp/print.pdf )
(删除文件/tmp/print.ps)
(消息PDF保存到/tmp/print.pdf))


解决方案

尝试这样:

 code>(defun spool-buffer-given-name(name)
(let((ps-left-header(list(格式(%s)name))))
ps-spool-buffer-with-faces)))

查看变量ps-left-header的文档,这是w帽子让我了解到上述。



这是一个整洁的能力;我一定会使用它而不是ps-print。使它更像C-u M-x ps-print-buffer-with-faces这样做会很好两个缺少的功能是标题中的目录名称,并提示用户输入文件名。既不太难。


Rupert Swarbrick came up with the following three functions to print an Emacs buffer to pdf in which lines are wrapped (this is not normally the case when using ps-print* functions).

The problem is this function is that to achieve this line wrapping, a copy of the current buffer has to be made. This effectively breaks the capability of ps-print-buffer-with-faces to display a correct header on top of each page in the resulting PDF file.

As part of his solution, Rupert Swarbrick wrote a function that preserves this information. The resulting header, however, is always HeaderLinesLeft

Who can spot the mistake?

(defun harden-newlines ()
  (interactive)
  "Make all the newlines in the buffer hard."
  (save-excursion
    (goto-char (point-min))
    (while (search-forward "\n" nil t)
      (backward-char)
      (put-text-property (point) (1+ (point)) 'hard t)
      (forward-char))))

(defun spool-buffer-given-name (name)
  (load "ps-print")
  (let ((tmp ps-left-header))
    (unwind-protect
        (progn
          (setq ps-left-header
                (list (lambda () name) 'ps-header-dirpart))
          (ps-spool-buffer-with-faces))
      (setf ps-left-header tmp))))

(defun print-to-pdf ()
  "Print the current file to /tmp/print.pdf"
  (interactive)
  (let ((wbuf (generate-new-buffer "*Wrapped*"))
        (sbuf (current-buffer)))
    (jit-lock-fontify-now)
    (save-current-buffer
      (set-buffer wbuf)
      (insert-buffer sbuf)
      (setq fill-column 95)
      (longlines-mode t)
      (harden-newlines)
      (message (buffer-name sbuf))
      (spool-buffer-given-name (buffer-name sbuf))
      (kill-buffer wbuf)
      (switch-to-buffer "*PostScript*")
      (write-file "/tmp/print.ps")
      (kill-buffer (current-buffer)))
    (call-process "ps2pdf14" nil nil nil
                  "/tmp/print.ps" "/tmp/print.pdf")
    (delete-file "/tmp/print.ps")
    (message "PDF saved to /tmp/print.pdf")))

解决方案

Try this:

(defun spool-buffer-given-name (name)
  (let ((ps-left-header (list (format "(%s)" name))))
    (ps-spool-buffer-with-faces)))

See documentation for variable ps-left-header, which is what clued me in to the above.

This is a neat capability; I'll definitely use it instead of ps-print. It would be good to make it act more like C-u M-x ps-print-buffer-with-faces; two missing features are directory name in the header, and prompting the user for a filename. Neither is too difficult.

这篇关于在Emacs函数中格式化一个标题以将缓冲区打印到PDF文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆