2

I am using magit (2.2.2) with emacs 25. magit is very good BUT I want the status dot in the modeline (like psvn does).

p svn example

I try to use https://github.com/tsgates/git-emacs/blob/master/git-modeline.el with this configuration:

  (autoload 'git--update-all-state-marks "git-modeline" nil t)
  (add-hook 'find-file-hook 'git-status-in-modeline)
  (defun git-status-in-modeline ()
    (if (and vc-mode (string-match "^ Git" (substring-no-properties vc-mode)))
        (git--update-all-state-marks)))

When I open a file (under git) it doesn't work but if I do (revert-buffer) it works. Why the second time but not the first ? Any Idea to progress ?

Thanks for any help.

2
  • Try appending git-status-in-modeline to find-file-hook by passing the third optional argument to add-hook as t - (add-hook 'find-file-hook 'git-status-in-modeline t) Commented Sep 4, 2015 at 17:07
  • Glad I could help. Converted the comment to an answer Commented Sep 30, 2015 at 2:30

2 Answers 2

3

The code git-status-in-modeline assumes vc has already been activated in the buffer it is working in. The issue was that the function was added to the start of find-file-hook, as such it was run before vc-find-file-hook (function which sets up vc-mode for a file) had any chance of setting up vc-mode in the file. Appending git-status-in-modeline (so that it runs after vc-find-file-hook) solves the problem

(add-hook 'find-file-hook 'git-status-in-modeline t)
3

I can imagine two ways this could be implemented. (1) Process each buffer individually - get the state of the file, then update the mode-line. (2) Compile a list of buffers and their files, get the status of the files, loop over the buffers to update their mode-lines.

A quick look at the source indicates that this snippet does the latter. And the public function seems to be git--update-all-state-marks, even though its name indicates otherwise (it uses the "private" prefix git--).

So you have this function to a hook which is run once "when something changed in the repository", not to a hook which is run once per file/buffer.

In the case of Magit magit-pre-refresh-hook should work. It is run after Magit did run a command and right before it refreshes the current Magit buffer. If the Magit command was invoked from a file-visiting buffer, then it is not run (but now that I think about it, I might change that). In any case you can always refresh the status dots by explicitly triggering an update by pressing g in any Magit buffer.


You might want to encourage the author to cleanup the code and to release this as a proper package in its own right. With documentation and everything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.