From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Wolfgang Jenkner Newsgroups: gmane.emacs.bugs Subject: bug#21067: 25.0.50; [PATCH] With mercurial, vc-print-log puts point at eob Date: Wed, 15 Jul 2015 13:09:22 +0200 Message-ID: <85lheh8ekr.fsf@iznogoud.viz> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1436984723 24757 80.91.229.3 (15 Jul 2015 18:25:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 15 Jul 2015 18:25:23 +0000 (UTC) To: 21067@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 15 20:25:12 2015 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 1ZFRMk-00065P-D8 for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 Jul 2015 20:25:10 +0200 Original-Received: from localhost ([::1]:37007 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFRMj-0000PN-MR for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 Jul 2015 14:25:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFRMf-0000MK-Uy for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2015 14:25:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFRMc-0004R2-La for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2015 14:25:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48889) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFRMc-0004QU-Eb for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2015 14:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZFRMb-00039s-Un for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2015 14:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Wolfgang Jenkner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 Jul 2015 18:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 21067 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.143698465412077 (code B ref -1); Wed, 15 Jul 2015 18:25:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Jul 2015 18:24:14 +0000 Original-Received: from localhost ([127.0.0.1]:50335 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZFRLp-00038i-N4 for submit@debbugs.gnu.org; Wed, 15 Jul 2015 14:24:14 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49317) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZFRLm-00038U-N7 for submit@debbugs.gnu.org; Wed, 15 Jul 2015 14:24:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFRLg-0003nW-Dl for submit@debbugs.gnu.org; Wed, 15 Jul 2015 14:24:05 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:57370) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFRLg-0003nQ-Au for submit@debbugs.gnu.org; Wed, 15 Jul 2015 14:24:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFRLb-0000GJ-KL for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2015 14:24:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFRLV-0003j0-Fm for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2015 14:23:59 -0400 Original-Received: from b2bfep13.mx.upcmail.net ([62.179.121.58]:35355) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFRLV-0003h7-5J for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2015 14:23:53 -0400 Original-Received: from edge11.upcmail.net ([192.168.13.81]) by b2bfep13.mx.upcmail.net (InterMail vM.8.01.05.11 201-2260-151-128-20120928) with ESMTP id <20150715182349.YLRK2939.b2bfep13-int.chello.at@edge11.upcmail.net> for ; Wed, 15 Jul 2015 20:23:49 +0200 Original-Received: from iznogoud.viz ([91.119.221.196]) by edge11.upcmail.net with edge id siPp1q0084EqxsT0BiPpjU; Wed, 15 Jul 2015 20:23:49 +0200 X-SourceIP: 91.119.221.196 Original-Received: from wolfgang by iznogoud.viz with local (Exim 4.85 (FreeBSD)) (envelope-from ) id 1ZFRLQ-0002NZ-SU for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2015 20:23:48 +0200 User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.0.50 (berkeley-unix) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). 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:104978 Archived-At: Call vc-dir for some repo under hg version control and then type l in the resulting *vc-dir* buffer. As expected, this produces a *vc-change-log* buffer with the most recent change at the beginning. However, point is at the end of the buffer. I would expect point to be put next to the most recent commit, as it is the case for, e.g., git. Note that explicitly selecting a revision (typing C-u l) does work. The different behaviour is due to the hg log subprocess being run synchronously while the git subprocess is run asynchronously. For an async process the following happens: vc-process-filter inserts each output chunk at the process mark and updates the latter; vc-run-delayed has advised the sentinel to go to the process mark and insert additional stuff (buttons) when the process is finished. All those insertions happen inside save-excursion forms. However, the sentinel sets point to the value of vc-sentinel-movepoint (if non-nil). For a sync process the following happens: The output is inserted and additional stuff set up with vc-run-delayed is inserted at point. Those insertions don't happen inside save-excursion forms and vc-sentinel-movepoint is ignored. Now, while it is true that the name of vc-sentinel-movepoint doesn't sound like it was meant for synchronous processes anyway, it is also true that generic functions like vc-print-log and callees don't know whether the subprocess will be run synchronously or asynchronously. So I wonder whether it wouldn't be worthwile to make their job easier (and thereby avoid bugs like the one described above) by handling async and sync processes alike in this respect. The condition for this to work is that backend functions don't expect point to be preserved, except, of course, if it is actually their purpose to compute point (like for vc-git-show-log-entry). Here's a patch. -- >8 -- Subject: [PATCH] Handle point for sync vc processes like for async ones * lisp/vc/vc-dispatcher.el (vc--process-sentinel): Cut some code. (vc-exec-after): Move it here. Remove comment which has not been matching the code for a while. (vc-do-command): Use save-excursion around the sync process call. --- lisp/vc/vc-dispatcher.el | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el index ec55867..4f44d35 100644 --- a/lisp/vc/vc-dispatcher.el +++ b/lisp/vc/vc-dispatcher.el @@ -199,25 +199,7 @@ Another is that undo information is not kept." ;; Leave mode-line uncluttered, normally. (unless (eq 'exit status) (format " (%s)" status)))) - (let (vc-sentinel-movepoint - (m (process-mark p))) - ;; Normally, we want async code such as sentinels to not move point. - (save-excursion - (goto-char m) - ;; Each sentinel may move point and the next one should be run - ;; at that new point. We could get the same result by having - ;; each sentinel read&set process-mark, but since `cmd' needs - ;; to work both for async and sync processes, this would be - ;; difficult to achieve. - (vc-exec-after code) - (move-marker m (point))) - ;; But sometimes the sentinels really want to move point. - (when vc-sentinel-movepoint - (let ((win (get-buffer-window (current-buffer) 0))) - (if (not win) - (goto-char vc-sentinel-movepoint) - (with-selected-window win - (goto-char vc-sentinel-movepoint)))))))))) + (vc-exec-after code))))) (defun vc-set-mode-line-busy-indicator () (setq mode-line-process @@ -241,7 +223,20 @@ CODE should be a function of no arguments." ((or (null proc) (eq (process-status proc) 'exit)) ;; Make sure we've read the process's output before going further. (when proc (accept-process-output proc)) - (if (functionp code) (funcall code) (eval code))) + (let (vc-sentinel-movepoint) + ;; Normally, we want code to not move point. + (save-excursion + (let ((m (when proc (process-mark proc)))) + (goto-char (or m (point-max))) + (if (functionp code) (funcall code) (eval code)) + (when m (move-marker m (point))))) + ;; But sometimes the sentinels really want to move point. + (when vc-sentinel-movepoint + (let ((win (get-buffer-window (current-buffer) 0))) + (if (not win) + (goto-char vc-sentinel-movepoint) + (with-selected-window win + (goto-char vc-sentinel-movepoint))))))) ;; If a process is running, add CODE to the sentinel ((eq (process-status proc) 'run) (vc-set-mode-line-busy-indicator) @@ -337,7 +332,9 @@ case, and the process object in the asynchronous case." (when vc-command-messages (message "Running %s in foreground..." full-command)) (let ((buffer-undo-list t)) - (setq status (apply 'process-file command nil t nil squeezed))) + ;; Use `save-excursion' like `vc-process-filter' does. + (setq status (save-excursion + (apply 'process-file command nil t nil squeezed)))) (when (and (not (eq t okstatus)) (or (not (integerp status)) (and okstatus (< okstatus status)))) -- 2.4.5