unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: martin rudalics <rudalics@gmx.at>
Cc: 35860@debbugs.gnu.org
Subject: bug#35860: Delayed window positioning after buffer display
Date: Tue, 11 Jun 2019 23:53:00 +0300	[thread overview]
Message-ID: <875zpb4zdw.fsf@mail.linkov.net> (raw)
In-Reply-To: <2347769f-9ab3-c1b6-699e-4e89a7d8eb1c@gmx.at> (martin rudalics's message of "Sat, 25 May 2019 09:58:14 +0200")

[-- Attachment #1: Type: text/plain, Size: 638 bytes --]

>> 0. emacs -Q
>> 1. C-h l
>>
>> Then point in the *Help* buffer should be at the bottom,
>> but when setting switch-to-buffer-preserve-window-point to nil
>> instead of using set-marker, point still is at the top of the buffer.
>
> I'm confused.  Here point in the *Help* buffer is always at bottom
> regardless of how 'switch-to-buffer-preserve-window-point' is set.

Dmitry reverted my patch in bug#35624 because of no progress here,
so I needed to implement this quickly.  It generalizes
help-window-point-marker to a more general variable useful
not only in the Help buffer but everywhere, and all my tests show
that it works well:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: window-start-and-point.patch --]
[-- Type: text/x-diff, Size: 5371 bytes --]

diff --git a/lisp/help.el b/lisp/help.el
index 42ff375565..c046fe6a49 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -37,15 +37,7 @@
 (add-hook 'temp-buffer-setup-hook 'help-mode-setup)
 (add-hook 'temp-buffer-show-hook 'help-mode-finish)
 
-;; `help-window-point-marker' is a marker you can move to a valid
-;; position of the buffer shown in the help window in order to override
-;; the standard positioning mechanism (`point-min') chosen by
-;; `with-output-to-temp-buffer' and `with-temp-buffer-window'.
-;; `with-help-window' has this point nowhere before exiting.  Currently
-;; used by `view-lossage' to assert that the last keystrokes are always
-;; visible.
-(defvar help-window-point-marker (make-marker)
-  "Marker to override default `window-point' in help windows.")
+(defvaralias 'help-window-point-marker 'window-point)
 
 (defvar help-window-old-frame nil
   "Frame selected at the time `with-help-window' is invoked.")
@@ -481,7 +473,8 @@ view-lossage
           (comment-indent)
 	  (forward-line 1)))
       ;; Show point near the end of "lossage", as we did in Emacs 24.
-      (set-marker help-window-point-marker (point)))))
+      (setq window-point (point))
+      (setq window-start (save-excursion (forward-line (- 5 (window-height))) (point))))))
 
 \f
 ;; Key bindings
@@ -1249,12 +1242,6 @@ help-window-setup
 	 (frame (window-frame window)))
 
     (when help-buffer
-      ;; Handle `help-window-point-marker'.
-      (when (eq (marker-buffer help-window-point-marker) help-buffer)
-	(set-window-point window help-window-point-marker)
-	;; Reset `help-window-point-marker'.
-	(set-marker help-window-point-marker nil))
-
       ;; If the help window appears on another frame, select it if
       ;; `help-window-select' is non-nil and give that frame input focus
       ;; too.  See also Bug#19012.
@@ -1327,7 +1314,7 @@ help-window-setup
 ;; (3) An option (customizable via `help-window-select') to select the
 ;;     help window automatically.
 
-;; (4) A marker (`help-window-point-marker') to move point in the help
+;; (4) A marker (`window-point') to move point in the help
 ;;     window to an arbitrary buffer position.
 (defmacro with-help-window (buffer-or-name &rest body)
   "Evaluate BODY, send output to BUFFER-OR-NAME and show in a help window.
@@ -1339,9 +1326,9 @@ with-help-window
 Most of this is done by `help-window-setup', which see."
   (declare (indent 1) (debug t))
   `(progn
-     ;; Make `help-window-point-marker' point nowhere.  The only place
+     ;; Make `window-point' point nowhere.  The only place
      ;; where this should be set to a buffer position is within BODY.
-     (set-marker help-window-point-marker nil)
+     (when window-point (setq window-point nil))
      (let ((temp-buffer-window-setup-hook
 	    (cons 'help-mode-setup temp-buffer-window-setup-hook))
 	   (temp-buffer-window-show-hook
diff --git a/lisp/window.el b/lisp/window.el
index 69b1299dbd..e2796cecba 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -6795,6 +6795,22 @@ window--even-window-sizes
            (/ (- (window-total-height window) (window-total-height)) 2))
         (error nil))))))
 
+(defvar window-point nil
+  "Marker to override default `window-point' in help windows.
+`window-point' is a buffer-local marker you can move to a valid position of
+the buffer shown in the window in order to override the standard
+positioning mechanism (`point-min') chosen by window displaying functions.")
+(make-variable-buffer-local 'window-point)
+(put 'window-point 'permanent-local t)
+
+(defvar window-start nil
+  "Marker to override default `window-start' in help windows.
+`window-start' is a buffer-local marker you can move to a valid position of
+the buffer shown in the window in order to override the standard
+positioning mechanism (`point-min') chosen by window displaying functions.")
+(make-variable-buffer-local 'window-start)
+(put 'window-start 'permanent-local t)
+
 (defun window--display-buffer (buffer window type &optional alist)
   "Display BUFFER in WINDOW.
 WINDOW must be a live window chosen by a buffer display action
@@ -6913,6 +6929,15 @@ window--display-buffer
 	(when (consp preserve-size)
 	  (window-preserve-size window t (car preserve-size))
 	  (window-preserve-size window nil (cdr preserve-size)))))
+
+      (when window-start
+        (set-window-start window window-start)
+        (setq window-start nil))
+
+      (when window-point
+        (set-window-point window window-point)
+        (setq window-point nil))
+
       ;; Assign any window parameters specified.
       (let ((parameters (cdr (assq 'window-parameters alist))))
         (dolist (parameter parameters)
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 61c13026cc..20a67dd6a7 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1017,9 +1017,11 @@ vc-git-print-log
     ;; If the buffer exists from a previous invocation it might be
     ;; read-only.
     (let ((inhibit-read-only t))
-      (with-current-buffer
-          buffer
-	(apply 'vc-git-command buffer
+      (with-current-buffer buffer
+	(insert (propertize "(Press 'd' here to see the diff against the current working revision)\n"
+                            'font-lock-face 'shadow))
+        (setq window-start (point))
+        (apply 'vc-git-command buffer
 	       'async files
 	       (append
 		'("log" "--no-color")

  parent reply	other threads:[~2019-06-11 20:53 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22 20:32 bug#35860: Delayed window positioning after buffer display Juri Linkov
2019-05-23  4:34 ` Eli Zaretskii
2019-05-23 20:56   ` Juri Linkov
2019-05-24  6:32     ` Eli Zaretskii
2019-05-24 18:34       ` Juri Linkov
2019-05-25  7:58         ` martin rudalics
2019-05-27 19:49           ` Juri Linkov
2019-06-11 20:53           ` Juri Linkov [this message]
2019-06-13  8:44             ` martin rudalics
2019-06-13 20:24               ` Juri Linkov
2019-06-14 19:14                 ` Juri Linkov
2019-06-15  8:17                   ` martin rudalics
2019-06-15 22:44                     ` Juri Linkov
2019-06-16  8:16                       ` martin rudalics
2019-06-16 19:32                         ` Juri Linkov
2019-06-17  8:23                           ` martin rudalics
2019-06-17 20:33                             ` Juri Linkov
2019-06-18  8:19                               ` martin rudalics
2019-06-18 21:02                                 ` Juri Linkov
2019-06-19  9:14                                   ` martin rudalics
2019-06-19 21:34                                 ` Juri Linkov
2019-06-20  7:41                                   ` martin rudalics
2019-06-15  8:17                 ` martin rudalics

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875zpb4zdw.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=35860@debbugs.gnu.org \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).