Question

I want to display the current Git branch I am on within the header when I print via postscrpt but cannot figure out how to do that.

It appears in the mode-line, from what appears to be (vc-mode vc-mode) but adding that to ps-left-header doesn't work.

Can anyone help?

Was it helpful?

Solution

You've almost got what you need, I think. If you put a symbol in the ps-left-header list, then that symbol gets funcalled. Although I couldn't find this in the documentation, it seems that it gets called with the buffer that you're printing as the current buffer.

Now, the variable vc-mode is a buffer-local variable that gets set to something useful by the code that deals with the mode line. In fact, it generally looks something like " Git-master" (with the leading space) so you'll probably want to transform it somewhat. Also, it comes with lots of text properties we don't need. Suppose that you've written a more useful version of this:

(defun vc-mode-as-string () (substring-no-properties vc-mode))

Then I think you can just add the symbol vc-mode-as-string to ps-left-header to get what you want. Maybe vc-mode-as-string should also check that vc-mode is a string and return "" otherwise. (I've just checked and the variable is always bound, but is nil when there's no version control)

To do a "quick and dirty" check when writing this, I used the following in IELM:

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"

("app.cc" is a buffer that is under version control on my Emacs at the moment).

Hopefully these hints should be enough for you to build what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top