From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Engster Newsgroups: gmane.emacs.bugs Subject: bug#15045: Point jumps inappropriately around time of Semantic lexing Date: Thu, 08 Aug 2013 19:21:12 +0200 Message-ID: <87eha4t7xz.fsf@engster.org> References: <87pptptk9n.fsf@engster.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1375982541 10771 80.91.229.3 (8 Aug 2013 17:22:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 8 Aug 2013 17:22:21 +0000 (UTC) Cc: Barry OReilly , 15045@debbugs.gnu.org, "Eric M. Ludlam" To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 08 19:22:22 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V7Tuk-0000MR-PJ for geb-bug-gnu-emacs@m.gmane.org; Thu, 08 Aug 2013 19:22:18 +0200 Original-Received: from localhost ([::1]:52780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7Tuk-0006gQ-9p for geb-bug-gnu-emacs@m.gmane.org; Thu, 08 Aug 2013 13:22:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7Tub-0006fS-14 for bug-gnu-emacs@gnu.org; Thu, 08 Aug 2013 13:22:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V7TuV-0000Af-0h for bug-gnu-emacs@gnu.org; Thu, 08 Aug 2013 13:22:08 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:53409) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7TuU-0000Ab-Th for bug-gnu-emacs@gnu.org; Thu, 08 Aug 2013 13:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1V7TuU-0003Ah-Fy for bug-gnu-emacs@gnu.org; Thu, 08 Aug 2013 13:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: David Engster Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 08 Aug 2013 17:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15045 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 15045-submit@debbugs.gnu.org id=B15045.137598248312079 (code B ref 15045); Thu, 08 Aug 2013 17:22:02 +0000 Original-Received: (at 15045) by debbugs.gnu.org; 8 Aug 2013 17:21:23 +0000 Original-Received: from localhost ([127.0.0.1]:47725 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1V7Ttq-00038e-C0 for submit@debbugs.gnu.org; Thu, 08 Aug 2013 13:21:23 -0400 Original-Received: from randomsample.de ([83.169.19.17]:43770) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1V7Ttm-00038A-HJ for 15045@debbugs.gnu.org; Thu, 08 Aug 2013 13:21:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=randomsample.de; s=a; h=Content-Type:MIME-Version:Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From; bh=/tMC9Uv610l+ABjDFkns0PMcRxCmfk02SmaPoRJ1Pv8=; b=bL12v/i6F83nDItUG4WgEb+W5JmAq7xaZP3fnBrm6SD779JVuhrVlub1t6BFjzYVa64yc+mu9ZrFS5PAkYqEkUyGJ77bMTp1MXncQ7rQp03QO178wqeYko+3qEVOTneB; Original-Received: from dslc-082-083-054-159.pools.arcor-ip.net ([82.83.54.159] helo=spaten) by randomsample.de with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1V7Tth-00031V-PW; Thu, 08 Aug 2013 19:21:14 +0200 In-Reply-To: <87pptptk9n.fsf@engster.org> (David Engster's message of "Wed, 07 Aug 2013 20:42:44 +0200") User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:77090 Archived-At: --=-=-= Content-Type: text/plain [Adding Eric to CC] David Engster writes: > Stefan Monnier writes: >>> The short of it is that I occasionally witness point jump to elsewhere >>> in the buffer while I'm editing and then back again. >> >> So it's "displayed at A" then "displayed at B" then "displayed at >> A again"? what happens between each one of those 3 displays? >> >> If "nothing", then I suspect there's something like a `sit-for' >> somewhere that causes a redisplay in the middle of the command (i.e. in >> the middle of a save-excursion). > > I sometimes see this as well, and yes, "nothing" happens between those > three displays. I also think there's a redisplay triggered by another > background task while Semantic does its idle parsing stuff. I think I tracked this down. I first instrumented `sit-for' to see which background tasks trigger it. On my machine, this happens by two things: `jit-lock-deferred-fontify', and `display-time-event-handler'. The display-time handler is called twice per minute: I have (display-time) in my .emacs, and every full minute the time gets updated in the mode-line. Also, it is called in the gnus-after-get-new-news-hook, and since I check for new mails in the background, it gets called through this, too. It's kinda hard to trigger this problem through jit-lock, since its idle time is much smaller than the one from Semantic. So I disabled it and tried to trigger the jump by stopping typing at roughly XX:XX:59. The semantic idle function kicks in after 1 second, and lo and behold, I saw a jump. It's still difficult to reproduce, but I managed to get two backtraces in the past hour, which are attached. As you can see, the display-time-event-handler does indeed interrupt the lexing phase. It does a `sit-for', the display jumps. Not sure what happens after that. Does the semantic-idle function resume? Anyway, somehow point gets back to its original position, and through `trace-redisplay', I saw the following on stderr: 0x7f35178 (test.cpp): same window start 0x7f35178 (test.cpp): 1 redisplay_preserve_echo_area (2) redisplay_internal 0 0x7f35178 (test.cpp): try_scrolling redisplay_preserve_echo_area (8) redisplay_internal 0 0x7f35178 (test.cpp): same window start 0x7f35178 (test.cpp): 1 0x7f35178 (test.cpp): try_scrolling redisplay_preserve_echo_area (8) I guess this just says that redisplay made point visible by scrolling, right? You might wonder how the display-time-event-handler can interrupt the Semantic lexer. In the two backtraces, you see that it calls `accept-process-output' and `input-pending-p'. This is hidden inside the macro `semantic-throw-on-input', which can be called in code wrapped inside `semantic-exit-on-input'; it's our poor-man's 'yield'. It's used extensively in the idle function code, and it's just there to do a non-local exit in case the user does something. However, now I know that it also allows other timers to run. If you look in the `define-lex' macro, you see that it calls `semantic-throw-on-input' after each identified token. The problem is that it does not restore the cursor position before that, so I guess the fix is simply to change this call to (save-excursion (goto-char starting-position) (semantic-throw-on-input 'lex)) Obviously, we will have to check all other calls to `semantic-throw-on-input' for this as well. However, I also wonder if display-time-event-handler couldn't just call `force-mode-line-update'; or does this repaint the whole display as well? -David --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=backtr1.txt sit-for(0) display-time-event-handler() apply(display-time-event-handler nil) byte-code("[snipped]" [timer apply 5 6] 4) timer-event-handler([t 20995 27860 0 60 display-time-event-handler nil nil 0]) accept-process-output() semantic-c-lexer(2886 7946 nil nil) semantic-lex(2886 7946 nil) semantic-parse-region-default(2886 7946 nil nil nil) semantic-parse-region-c-mode(2886 7946 nil nil nil) semantic-parse-region(2886 7946 nil) semantic-edits-incremental-parser-1() byte-code("[snipped]" [err message "incremental parser error: %S" error-message-string t] 4)))] 3) semantic-parse-changes-default() semantic-parse-changes() semantic-fetch-tags() byte-code("[snipped]" [semantic-fetch-tags nil] 1) semantic-idle-scheduler-refresh-tags() byte-code("[snipped]") semantic-idle-core-handler() semantic-idle-scheduler-function() apply(semantic-idle-scheduler-function nil) timer-event-handler([t 0 1 0 t semantic-idle-scheduler-function nil idle 0]) --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=backtr2.txt sit-for(0) display-time-event-handler() apply(display-time-event-handler nil) byte-code("[snipped]" [timer apply 5 6] 4) timer-event-handler([t 20995 36800 0 60 display-time-event-handler nil nil 0]) input-pending-p() semantic-c-lexer(2939 7944 nil nil) semantic-lex(2939 7944 nil) semantic-parse-region-default(2939 7944 bovine-inner-scope nil t) semantic-parse-region-c-mode(2939 7944 bovine-inner-scope nil t) semantic-parse-region(2939 7944 bovine-inner-scope nil t) semantic-get-local-variables-default() semantic-get-local-variables-c++-mode() semantic-get-local-variables() semantic-get-all-local-variables-default(nil) semantic-get-all-local-variables() byte-code("[snipped]" [scopecache eieio-oset localvar semantic-get-all-local-variables] 4) semantic-calculate-scope(7797) semantic-analyze-current-context-default(7797) semantic-analyze-current-context(7797) byte-code("[snipped]" [semantic-analyze-current-context] 2) semantic-idle-summary-current-symbol-info-context() semantic-idle-summary-current-symbol-info-default() semantic-idle-summary-current-symbol-info-c-mode() semantic-idle-summary-current-symbol-info() semantic-idle-summary-idle-function() funcall(semantic-idle-summary-idle-function) --=-=-=--