Open yilkalargaw opened 6 years ago
Isn't magit a bit redundant? :P
For dired
, I can't figure out how you'd do that normally. telephone-line
is just using the contents of vc-mode
, which is described here: https://www.gnu.org/software/emacs/manual/html_node/emacs/VC-Mode-Line.html but there's no mention of dired. From a cursory googling, it looks like this isn't generally a supported feature?
I guess show me what resource you found, at least.
I was thinking of reading the .git/HEAD file if the pwd(i.e. present working directory) contains a .git folder.
Sorry that was a dumb comment because it will require checking the vc type of the current directory and traverse up the directory until you find the .git file (i.e. if the version control system is git) I think the vc-dir command does that and might be a better option but it opens the results in a new buffer.
It might give out some warnings when not in a git repository but I am able to get information about the git directory like this I was wondering I could do some kind of regexp to extract the branch.
(apply 'string ;; being a novice in emacs lisp I used these two lines to
(string-to-list ;; remove the font-lock related data about the text
(vc-call-backend (elt vc-handled-backends 6)
'dir-extra-headers
(expand-file-name "."))))
I would like to hear your opinion and some help on where to get started. I wonder if it is possible to suppress the warnings though.
This kinda functionality would be outside the scope of telephone-line
-- it should be it's own package, there's just so much here to provide that'd help even people who don't use telephone-line
That said, if there was a package providing this sort of thing, I'd totally add integration for it to telephone-line
. Such a package might already exist, though?
As for help with particular implementation, I'm not really sure I could help with vc-
stuff too far since I haven't really touched it much myself. If you're concerned about getting it to work well with telephone-line
, it's not really that hard -- just make sure you have a function that returns a (propertized) string of what you want in the mode-line. You'd think that goes without saying, but many of the package integrations I've worked on don't provide such a function; they just directly write to mode-line-format
, so I need to copy-paste out bits to rebuild it from scratch, lol.
The emacs vc-dir function already provides all we need to know about a directory. I just replicated the functionality to avoid opening a new buffer. The following function already returns the propertized string used for vc-dir buffer.
(vc-call-backend 'Git 'dir-extra-headers (expand-file-name "."))
What I am unsure about is how to display only the branch part in the telephone-line when I visit the directory using dired. I do not think wrapping a single line into a package is necessary. But if it could somehow be integrated into the mode-line it would be awesome.
Maybe this package https://github.com/10sr/git-ps1-mode-el can help us get the text we want to display :)
I actually defined my own segment like this using only vc-backend from the default emacs.
(telephone-line-defsegment* telephone-vc-dir-segment ()
(elt
(mapcar (function (lambda (c) (replace-regexp-in-string "[\t ]" "" c)))
(split-string
(apply 'string ;; being a novice in emacs lisp I used these two lines to
(string-to-list ;; remove the font-lock related data about the text
(vc-call-backend (elt vc-handled-backends 6)
'dir-extra-headers
(expand-file-name ".")))) "\n")) 0))
It works well for buffers like dired, eshell, magit etc. I am thinking about adding a conditional to check for modes before loading and sending a pull request in telephone-line-segments.el
Will try it when I get a chance!
It's quite slow on Windows and shows some errors here and there. The former might have to do with git being slow in general on Win.
telephone-line(i.e. the most awsomely awesomest modline) shows git branch only if we open files in a repository. I was unable to see the git branch for other modes like dired, eshell or magit. I think it is can be implemented since the feature is already there all it needs to is current-directory dependent rather than current-file dependent. I wanted to implement it myself but I did not know where to start.