-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
treemacs-git-mode not working #152
Comments
Ok looks like I've to manually refresh the treemacs buffer for it to show git related modifications. I've |
The answer is twofold:
|
Can use
Oh I didn't realize |
Makes things much easier on my part. I figured filewatch-mode is something you either turn on from the start or not at all.
That's a stopgap solution at best.
I'll get around this eventually, but first it requires a) magit's cooperation and b) me finishing my current project, which is teaching treemacs to display multiple file trees at once. |
You can keep a watch on the |
I ran a short test - just watched .git and checked what changes it produces. Adding an untracked file - one of the actions that treemacs cannot react to now - didn't do much other than produce a whole lot of of changes to index.lock. The index would also get locked every time I fire So for this use-case I could not detect the event I need to react to and only burdened myself with additional interference.
A checkout should not be an issue. Anything that changes actual files will be detected. The problem is when git does somethinh that does change the underlying file system. AFAIK that should be limited to adding untracked files and making commits. |
Should we really care about untracked files? |
What I can suggest is run a
Watching for the whole project directory might be a thing which can help out in such situations but it will also count on the ignored files. |
Should we really care about untracked files?
Yes, of course. Appropriately displaying ignored, changed, added,
untracked or conflicted files is the entire point of git-mode.
Watching for the whole project directory might be a thing which might
also help out in such situations
It sounds like you don't know how filewatch-mode works. Watching the
entire project directory for filesystem changes - or, more accurately,
the visible parts - is exactly what it does. Your three points are
likewise just a subset of everything treemacs already pays attention to.
The problem lies only in detecting those events that make no changes to
the underlying file system. That's the part I'll need magit hooks for.
|
What is the thing that doesn't make changes to the underlying file system but is important for us to watch? |
For example making a commit. That'll change a bunch of your files from being modified to being clean again. |
For that we can watch for changes in the |
Not really. As already said above, adding an untracked file does nothing but produce a dozen index.lock changes (in addition to the general interference every time I fire git status). That's not a good indication for anything. |
Are we out of options? |
When I tackle this issue next I'll ask magit to provide the necessary hooks for treemacs to use. I've no good solution for directly working with the command line. |
I did some talking over at magit/magit#3496 and I now have enough material to close those gaps when using magit. It'll involve some non-trivial additions, so I'll be publishing a treemacs-magit package soon. |
I've created a new issue specifically for dealing with integrating magit: #223 |
Hi, I'm seeing all sorts of weird behavior regarding the file watcher. My treemacs configuration is: (use-package treemacs
:config
(treemacs-filewatch-mode 1)
(treemacs-git-mode 'simple)
:bind ("C-c t" . treemacs))
(use-package treemacs-magit
:after (treemacs magit))
I created a simple repository with just one file. I repeatedly made changes to this single file and committed them to the repo. Each time I made a change it wasn't reflected in treemacs until I explicitly refreshed its buffer by pressing Now, if I disable magit integration treemacs isn't auto-refreshed in any case. So maybe the case that was working before was just because of some magit event (no pun intended). Nevertheless, if I add a file to the directory from the terminal, it immediately gets reflected in treemacs, so some sync is indeed happening. |
Did a little debugging:
Tracing |
I did this simple experiment: (defun my-watcher (event) (message "Not in my watch: %s" event))
(file-notify-add-watch "/tmp/some-dir" '(change) #'my-watcher) and again:
Maybe it's a bug in emacs-28, I don't know, I'm on macOS Big Sur. |
Well, indeed it makes sense according to the docstring:
If I instead track
Maybe treemacs is not watching individual files? I don't know, I need to sleep now, I'll try to dig deeper later, HIH. |
Just one more thing, the docstring quoted above contradicts https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Notifications.html:
|
According to https://news.ycombinator.com/item?id=9063910 the difference I noticed is in fact a difference between kqueue (BSD/macOS) and inotify (Linux). Also: https://stackoverflow.com/a/30019533/2012920 But this is the only disclaimer the elisp manual does wrt kqueue:
So nothing about file changes. Either the feature is misdocumented or there is a bug. If there is a bug then there doesn't seem to be an easy cure, at least if we are to believe what was said in the ycombinator thread. PS: I reported this to emacs bug tracker. |
Eli Zaretski answered that this should be considered a bug in macOS and not in emacs. I believe it's not a bug in macOS but a characteristic of kqueue, although I agree that it's better to leave emacs alone (except that the documentation should still be fixed) See for example this remark in the documentation of fswatch [1]:
The implications are rather negative. fswatch also provides:
But I don't see any implementation of
I'll keep you updated. |
Yesterday I got to learn that shells on macos are so bungled that a simple Anyway, I'll go with option number one. Filewatch is complex enough as it is, and I have plans to refactor some chunks anyway - I am not going to build a second implementation for an operating system I do not even use. |
Ok, no problem, just don't throw the baby with the bathwater, filewatch for file adding/removal works just fine, the integration with git is more problematic since it depends on content change notification, so I would just disable the git/magit modules. Regarding Apple, sadly I'm a refugee after > 20 years in Linux. My last 3 years, since laptops started to ship with FHD screens and external monitors become UHD, have been so painful in Linux that I decided to stay away until Wayland gets its act together (maybe in 20 years, who knows, I'll probably be dead by then). ATM there is no real support for mixed/fractional scaling factors, except for xrandr hacks, and some video drivers are in bad shape. Not that I'm blaming anyone, hardware is complex, changes fast and there is no big money in the Linux desktop. At the time I also left Emacs because of the lack of support for HiDPI, hopefully the pgtk backend will fix that. That said, in this case I think it's unfair to blame Apple because kqueue is a general BSD thing. |
No throwing, the plan is to keep the status quo.
I'll direct some of my disappointment towards BSD then 🤷 |
Ok, no problem, just don't throw the baby with the bathwater, filewatch for file adding/removal works just fine
No throwing, the plan is to keep the status quo.
Ok, but please add a warning with red flashing lights in the README :)
|
Good point. I'll add proper warnings tomorrow. |
Warnings are added now. |
Here's a little workaround that forcely refreshes treemacs after each file save. Dirty and inefficient, but kinda works. Should be placed in (after! treemacs
(defun treemacs--force-refresh ()
"Forcely refreshes all the projects"
(treemacs-run-in-every-buffer
(treemacs-save-position
(dolist (project (treemacs-workspace->projects workspace))
(treemacs-project->refresh! project)))))
(add-hook 'after-save-hook 'treemacs--force-refresh)) |
Updating every single project on every save is quite expensive and can lead to stutters if treemacs is showing a lot of files. The much cheaper option is to only update the file that was changed: (defun treemacs--force-git-update-current-file ()
(-let [file (treemacs-canonical-path buffer-file-name)]
(treemacs-run-in-every-buffer
(when (treemacs-is-path file :in-workspace)
(treemacs-update-single-file-git-state file))))) |
Here is my treemacs config: https://github.com/CSRaghunandan/.emacs.d/blob/master/setup-files/setup-treemacs.el
emacs version:
GNU Emacs 26.0.91 (build 1, x86_64-apple-darwin16.7.0, NS appkit-1504.83 Version 10.12.6 (Build 16G1212)) of 2018-02-26
treemacs version:
20180221.1229
After modifying or adding any new files, I'm not seeing any changes to faces for the modified/added files. Any idea why this is happening?
The text was updated successfully, but these errors were encountered: