I have very annoying problem, after I run M-x compile time to time cursor jump from middle of buffer to the first line.

I want to find out culprit (I found mode who responsible for this, but I want to know what exactly function is causing this).

At first I just replace goto-char with my-goto-char, but it didn't show culprit - nobody calls (goto-char 1), after that I set hook on scrolling:

(defun my-bad()
  (message "something bad happens")

(defun debug--on-window-scroll (wnd new-start)
  (if wnd
      (progn (message "wnd %s, new-start %d %s" wnd new-start (buffer-name (window-buffer wnd)))
       (when (and (string= (buffer-name (window-buffer wnd)) "parsing.rs")  (= new-start 1))
(add-hook 'window-scroll-functions 'debug--on-window-scroll)

my-bad was called, but debuger show only:

Debugger entered--entering a function:
* my-bad()
  (progn (my-bad))
  (if (and (string= (buffer-name (window-buffer wnd)) "parsing.rs") (= new-start 1)) (progn (my-bad)))
  (progn (message "wnd %s, new-start %d %s" wnd new-start (buffer-name (window-buffer wnd))) (if (and (string= (buffer-name (window-buffer wnd)) "parsing.rs") (= new-start 1)) (progn (my-bad))))
  (if wnd (progn (message "wnd %s, new-start %d %s" wnd new-start (buffer-name (window-buffer wnd))) (if (and (string= (buffer-name (window-buffer wnd)) "parsing.rs") (= new-start 1)) (progn (my-bad)))))
  debug--on-window-scroll(#<window 3 on parsing.rs> 1)
  redisplay_internal\ \(C\ function\)()

so I still have no idea who scroll buffer to the first line, any idea how to find culprit who responsible for scrolling to the first line of specific buffer?

  • Does this happen with emacs -q -- no user configuration? If not, then the easiest solution is to recursively bisect your user configuration by commenting stuff out until you find the culprit. If it happens with emacs -q, then any number of forum participants should be able to help. goto-char will not trigger the window-scroll-functions hook: lists.gnu.org/archive/html/bug-gnu-emacs/2016-02/msg00952.html – lawlist Aug 15 '17 at 16:23
  • @lawlist Sorry if it is not clear from my question, I know mode who cause this, I want to know exact function and line of code that cause of this. – fghj Aug 15 '17 at 16:29
  • If we cannot see the function that has the problem or know the exact circumstances to recreate it for ourselves, how could anyone answer this question blindfolded? Perhaps someone in the audience has a "crystal ball" .... – lawlist Aug 15 '17 at 16:35
  • @lawlist I do understand you, this is question about debugging techinique, not about solving exact problem. In other words where put breakpoint to catch all buffer/window scroll events, how to see full bactrace and so on. Why you want to see around ~2000 lines of code of mode to answer to this question? – fghj Aug 15 '17 at 16:53
  • I cannot think of a way to do this in Lisp other than to insert messages or stops in the code; e.g., I frequently put something in the Lisp code like (error "stop") and then move that either up or down in the code until I find the exact location of certain behavior -- that way you can pin-point exactly when the window gets scrolled. Perhaps gdb would help and you could build Emacs with --enable-checking='glyphs' and launch Emacs from the terminal and when you are ready to step through a series of events, type M-x trace-redisplay. Perhaps others will have some additional ideas. – lawlist Aug 15 '17 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.