Emacs 打印缓冲区自动换行为 PDF
我使用此函数将缓冲区的内容打印到 PDF
(从我的 .emacs 文件:)
(defun print-to-pdf ()
(interactive)
(ps-spool-buffer-with-faces)
(switch-to-buffer "*PostScript*")
(write-file "/tmp/tmp.ps")
(kill-buffer "tmp.ps")
(setq cmd (concat "ps2pdf14 /tmp/tmp.ps /home/user/" (buffer-name) ".pdf"))
(shell-command cmd)
(shell-command "rm /tmp/tmp.ps")
(message (concat "Saved to: /home/user/" (buffer-name) ".pdf"))
)
但是,我无法找到一种方法来启用或应用视觉行次要模式到它之前的 PostScript 缓冲区写入磁盘以便在输出中启用自动换行。
I use this function for printing a buffer's content to PDF
(from my .emacs file:)
(defun print-to-pdf ()
(interactive)
(ps-spool-buffer-with-faces)
(switch-to-buffer "*PostScript*")
(write-file "/tmp/tmp.ps")
(kill-buffer "tmp.ps")
(setq cmd (concat "ps2pdf14 /tmp/tmp.ps /home/user/" (buffer-name) ".pdf"))
(shell-command cmd)
(shell-command "rm /tmp/tmp.ps")
(message (concat "Saved to: /home/user/" (buffer-name) ".pdf"))
)
I cannot, however, find a way to enable or apply the visual-line minor mode to the PostScript buffer before it gets written to disk so to enable word wrap in the output.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使视觉行模式受到尊重的问题是它插入“软换行符”(它会被 PS 渲染器忽略)。解决方案是用硬换行符替换它们。我认为下面的代码可以满足您的要求。请注意,我们在临时缓冲区中调用harden-newlines,以免弄乱当前文档。另外,我已将输出目的地更改为始终位于
/tmp/print.pdf
中。似乎......在没有任何警告的情况下覆盖/home
中的文档是不明智的!之后您可以随时移动 PDF。不管怎样,给你吧。这是你想要的吗?
The problem with getting visual line mode to be respected is that it inserts "soft newlines" (which get ignored by the PS renderer). A solution is to replace these with hard newlines. The code below does what you want, I think. Note that we call harden-newlines in a temporary buffer so as not to mess up the current document. Also, I've changed the output destination to always land in
/tmp/print.pdf
. It seems... unwise to overwrite documents in your/home
without any sort of warning! You can always move the PDF afterwards.Anyway, here you go. Is this what you wanted?