Follow mode causing an Emacs process to use 100% CPU while treemacs is open and the cursor is not in treemacs. I've already reported this issue in the Spacemacs repo. Let me repost the reproduction steps here.
Reproduction guide 馃悶
SPC p tSPC 1To reproduce this, please make sure that the follow mode is on.
I remember fixing something like this - months ago. There's also been a much more limited case that's been fixed in magit.
So: how up-to-date is your treemacs, and does it happen for all files?
I can confirm it with treemacs 20190302.2236. Happens for any files, even Fundamental mode and within projects not under source control.
FYI profiler-report https://gist.github.com/antonalekseev/2346db9e7d48e6ba93233122fd47ecf1
Tracking this down isn't going to be easy. There two things you can try:
First start with just treemacs and a basic config - as basic as it gets when you're on spacemacs - and see if the problem still persists then. Maybe it's an incompatibility with another package (in the case of magit it was a combination of timers and temp buffers).
If that doesn't work try the following code:
(let ((n 0))
(add-hook 'buffer-list-update-hook
(defun trace-follow-hook ()
(cl-incf n)
(when (= n 100)
(setf n 0)
(backtrace)))))
It must be evaluated in a buffer with lexical scope. The problem seems to be that something, or a combination of some things, is calling buffer-list-update-hook. The code above will issue a backtrace on every 100th such call. Adjust the number as necessary to keep your emacs from getting stuck. You should see a pattern of calls all coming from the same place. Disable the tracing with (fset #'trace-follow-hook #'ignore).
I've also tried to reproduce this issue with my other machine, but I've no problem with follow mode on while typing in pane 1. Here is the current version of treemacs in my other machine which doesn't have a problem.
Treemacs version: [Treemacs] v2.4-2019.02.01 @ 26.1
(auto-completion better-defaults docker emacs-lisp git go html ivy javascript osx python ruby rust shell-scripts version-control yaml elixir)
@Alexander-Miller I will try your method tonight with my problematic machine.
@Alexander-Miller the problem persist with minimal config. I tried with removing all layers, not sure if that's basic enough.
Anyway, I have got a backtrace log when CPU burning is happening (Took me a while to make backtrace thing works 馃槀).
I see a lot of these redisplay_internal calls along with spacemacs/title-prepare.
run-hooks(buffer-list-update-hook)
get-buffer-create(" *temp*")
generate-new-buffer(" *temp*")
format-spec("%I@%S" ((97) (116) (83 . "Rose.local") (73 . "Emacs") (85 . "zentetsuken") (98 . "%b") (102 . "%f") (70 . "%F") (42 . "%*") (43 . "%+") (115 . "%s") (108 . "%l") (99 . "%c") (112 . "%p") (80 . "%P") (109 . "%m") (110 . "%n") (122 . "%z") (90 . "%Z") (91 . "%[") (93 . "%]") (37 . "%%") (45 . "%-")))
(let* ((project-name (if (string-match-p "%t" title-format) (progn (if (boundp (quote spacemacs--buffer-project-name)) spacemacs--buffer-project-name (set (make-local-variable ...) (if ... ... "-")))))) (abbreviated-file-name (if (string-match-p "%a" title-format) (progn (if (boundp (quote spacemacs--buffer-abbreviated-filename)) spacemacs--buffer-abbreviated-filename (set (make-local-variable ...) (abbreviate-file-name ...)))))) (fs (format-spec-make 97 abbreviated-file-name 116 project-name 83 system-name 73 invocation-name 85 (or (getenv "USER") "") 98 "%b" 102 "%f" 70 "%F" 42 "%*" 43 "%+" 115 "%s" 108 "%l" 99 "%c" 112 "%p" 80 "%P" 109 "%m" 110 "%n" 122 "%z" 90 "%Z" 91 "%[" 93 "%]" 37 "%%" 45 "%-"))) (format-spec title-format fs))
(progn (let* ((project-name (if (string-match-p "%t" title-format) (progn (if (boundp ...) spacemacs--buffer-project-name (set ... ...))))) (abbreviated-file-name (if (string-match-p "%a" title-format) (progn (if (boundp ...) spacemacs--buffer-abbreviated-filename (set ... ...))))) (fs (format-spec-make 97 abbreviated-file-name 116 project-name 83 system-name 73 invocation-name 85 (or (getenv "USER") "") 98 "%b" 102 "%f" 70 "%F" 42 "%*" 43 "%+" 115 "%s" 108 "%l" 99 "%c" 112 "%p" 80 "%P" 109 "%m" 110 "%n" 122 "%z" 90 "%Z" 91 "%[" 93 "%]" 37 "%%" 45 "%-"))) (format-spec title-format fs)))
(unwind-protect (progn (let* ((project-name (if (string-match-p "%t" title-format) (progn (if ... spacemacs--buffer-project-name ...)))) (abbreviated-file-name (if (string-match-p "%a" title-format) (progn (if ... spacemacs--buffer-abbreviated-filename ...)))) (fs (format-spec-make 97 abbreviated-file-name 116 project-name 83 system-name 73 invocation-name 85 (or (getenv "USER") "") 98 "%b" 102 "%f" 70 "%F" 42 "%*" 43 "%+" 115 "%s" 108 "%l" 99 "%c" 112 "%p" 80 "%P" 109 "%m" 110 "%n" 122 "%z" 90 "%Z" 91 "%[" 93 "%]" 37 "%%" 45 "%-"))) (format-spec title-format fs))) (set-match-data save-match-data-internal (quote evaporate)))
(let ((save-match-data-internal (match-data))) (unwind-protect (progn (let* ((project-name (if (string-match-p "%t" title-format) (progn ...))) (abbreviated-file-name (if (string-match-p "%a" title-format) (progn ...))) (fs (format-spec-make 97 abbreviated-file-name 116 project-name 83 system-name 73 invocation-name 85 (or ... "") 98 "%b" 102 "%f" 70 "%F" 42 "%*" 43 "%+" 115 "%s" 108 "%l" 99 "%c" 112 "%p" 80 "%P" 109 "%m" 110 "%n" 122 "%z" 90 "%Z" 91 "%[" 93 "%]" 37 "%%" 45 "%-"))) (format-spec title-format fs))) (set-match-data save-match-data-internal (quote evaporate))))
spacemacs/title-prepare("%I@%S")
eval((spacemacs/title-prepare dotspacemacs-frame-title-format))
redisplay_internal\ \(C\ function\)()
I've zero knowledge about this. Do you have any idea?
Okay, here's this thing goes: follow-mode fires, so makes a move via with-selected-window. Changing the selected window causes the frame title to be recalculated. That recalculation uses a temp buffer. Creating that temp buffer stupidly fires buffer-list-update-hook, which is what follow-mode is listening to, so we start back at step 1, et cetera ad infinitum.
Try changing your frame title format while I think of something.
Previous analysis is incomplete: the real culprits are the modelines. doom and powerline both advise select-window. I'll try and open PRs for both.
I've also raised the issue with upstream at https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34765.
The PRs in powerline and doom-mode-line have been merged. Take a look whether updating them fixes the problem.
The update fixes the issue for me. Closing the issue.
For everyone else that still has the problem:
Doom-Modeline doesn't necessarily update itself immediately. I fixed it by deleting ~/.emacs.d/elpa/26.1/develop/doom-modeline-20190323.602/ and restarting emacs.
Still using 100% cpu even after uninstalling doom-modeline.
Most helpful comment
https://github.com/milkypostman/powerline/pull/168
https://github.com/seagle0128/doom-modeline/pull/135
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34765