我想在通过postscrpt打印时,在标题中显示我当前所在的Git分支,但我无法找到如何实现它的方法。
它出现在模式行中,似乎是(vc-mode vc-mode),但将其添加到ps-left-header中不起作用。
有人能帮忙吗?
我认为你已经接近所需的内容了。如果在ps-left-header
列表中放置一个符号,那么该符号将被调用。虽然我在文档中找不到这个信息,但它似乎会以当前打印的缓冲区作为当前缓冲区来调用。
现在,变量vc-mode
是一个缓冲区局部变量,由处理模式行的代码设置为有用的值。实际上,它通常看起来像" Git-master"(带有前导空格),因此您可能需要对其进行一些转换。此外,它带有许多我们不需要的文本属性。假设您编写了一个更有用的版本:
(defun vc-mode-as-string () (substring-no-properties vc-mode))
vc-mode-as-string
添加到ps-left-header
中,以获得您想要的结果。也许vc-mode-as-string
还应该检查vc-mode
是否为字符串,否则返回""
。(我刚刚检查了一下,变量总是绑定的,但没有版本控制时为nil
)。ELISP> (let ((ps-left-header (cons 'vc-mode-as-string ps-left-header)))
(with-current-buffer "app.cc"
(ps-spool-buffer-with-faces)))
"Formatting...done"
;Append the Git branchname to the postscript header (defun vc-mode-as-string () (substring-no-properties vc-mode)) (setq ps-left-header (append ps-left-header '(vc-mode-as-string)))
- jimzat(defun vc-mode-as-string () (if vc-mode (substring-no-properties vc-mode) " "))
。 - jimzat
git
和ps
这样的标签会吸引非 Emacs 的受众,因此人们会对你的问题进行负面评价并可能投票关闭你的问题。 - lawlistvc-hooks.el
库中的vc-mode-line
函数看起来很有趣,特别是其中的(setq vc-mode (concat ...
部分 -- 或许这可以引导你朝正确的方向前进 -- 也就是说,检查该变量的值并查看它是否符合你想要的。 - lawlist