unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: martin rudalics <rudalics@gmx.at>
Cc: 12253@debbugs.gnu.org
Subject: bug#12253: Restore window start position
Date: Sat, 25 Aug 2012 22:29:42 +0300	[thread overview]
Message-ID: <87r4qun7u1.fsf@mail.jurta.org> (raw)
In-Reply-To: <5038D5CA.5000502@gmx.at> (martin rudalics's message of "Sat, 25 Aug 2012 15:40:26 +0200")

> I agree.  How do you handle the case where *info* is not in the selected
> window but some other one?

We don't need to care about this case.  When used programmatically,
the caller should handle also the case when *info* is in another window,
e.g.:

  (with-current-buffer "*info*"
    ...
    (Info-history-back)
    (set-window-start (window-in-direction 'below) opoint)
    ...)

or some more specific logic when necessary.

But for the normal case, I think the following patch should be enough:

=== modified file 'lisp/info.el'
--- lisp/info.el	2012-08-21 00:12:42 +0000
+++ lisp/info.el	2012-08-25 19:29:04 +0000
@@ -40,11 +40,11 @@ (defgroup info nil
 
 (defvar Info-history nil
   "Stack of Info nodes user has visited.
-Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
+Each element of the stack is a list (FILENAME NODENAME BUFFERPOS WINDOWPOS).")
 
 (defvar Info-history-forward nil
   "Stack of Info nodes user has visited with `Info-history-back' command.
-Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
+Each element of the stack is a list (FILENAME NODENAME BUFFERPOS WINDOWPOS).")
 
 (defvar Info-history-list nil
   "List of all Info nodes user has visited.
@@ -922,7 +925,9 @@ (defun Info-find-node (filename nodename
   ;; Record the node we are leaving, if we were in one.
   (and (not no-going-back)
        Info-current-file
-       (push (list Info-current-file Info-current-node (point))
+       (push (list Info-current-file Info-current-node (point)
+		   (and (eq (window-buffer) (current-buffer))
+			(window-start)))
              Info-history))
   (Info-find-node-2 filename nodename no-going-back))
 
@@ -956,7 +961,9 @@ (defun Info-revert-find-node (filename n
 	(pline        (count-lines (point-min) (line-beginning-position)))
 	(wline        (count-lines (point-min) (window-start)))
 	(new-history  (and Info-current-file
-			   (list Info-current-file Info-current-node (point)))))
+			   (list Info-current-file Info-current-node (point)
+				 (and (eq (window-buffer) (current-buffer))
+				      (window-start))))))
     ;; When `Info-current-file' is nil, `Info-find-node-2' rereads the file.
     (setq Info-current-file nil)
     (Info-find-node filename nodename)
@@ -1226,6 +1233,8 @@ (defun Info-find-node-2 (filename nodena
         (let ((hist (car Info-history)))
           (setq Info-history (cdr Info-history))
           (Info-find-node (nth 0 hist) (nth 1 hist) t)
+          (when (and (nth 3 hist) (eq (window-buffer) (current-buffer)))
+	    (set-window-start (selected-window) (nth 3 hist) t))
           (goto-char (nth 2 hist))))))
 
 ;; Cache the contents of the (virtual) dir file, once we have merged
@@ -2002,7 +2013,7 @@ (defun Info-search (regexp &optional bou
 	       (equal ofile Info-current-file))
           (and isearch-mode isearch-wrapped
 	       (eq opoint (if isearch-forward opoint-min opoint-max)))
-	  (setq Info-history (cons (list ofile onode opoint)
+	  (setq Info-history (cons (list ofile onode opoint ostart)
 				   Info-history))))))
 
 (defun Info-search-case-sensitively ()
@@ -2208,16 +2219,21 @@ (defun Info-history-back ()
   (or Info-history
       (user-error "This is the first Info node you looked at"))
   (let ((history-forward
-	 (cons (list Info-current-file Info-current-node (point))
+	 (cons (list Info-current-file Info-current-node (point)
+		     (and (eq (window-buffer) (current-buffer))
+			  (window-start)))
 	       Info-history-forward))
-	filename nodename opoint)
+	filename nodename opoint ostart)
     (setq filename (car (car Info-history)))
     (setq nodename (car (cdr (car Info-history))))
     (setq opoint (car (cdr (cdr (car Info-history)))))
+    (setq ostart (car (cdr (cdr (cdr (car Info-history))))))
     (setq Info-history (cdr Info-history))
     (Info-find-node filename nodename)
     (setq Info-history (cdr Info-history))
     (setq Info-history-forward history-forward)
+    (when (and ostart (eq (window-buffer) (current-buffer)))
+      (set-window-start (selected-window) ostart t))
     (goto-char opoint)))
 
 (defalias 'Info-last 'Info-history-back)
@@ -2228,12 +2244,15 @@ (defun Info-history-forward ()
   (or Info-history-forward
       (user-error "This is the last Info node you looked at"))
   (let ((history-forward (cdr Info-history-forward))
-	filename nodename opoint)
+	filename nodename opoint ostart)
     (setq filename (car (car Info-history-forward)))
     (setq nodename (car (cdr (car Info-history-forward))))
     (setq opoint (car (cdr (cdr (car Info-history-forward)))))
+    (setq ostart (car (cdr (cdr (cdr (car Info-history-forward))))))
     (Info-find-node filename nodename)
     (setq Info-history-forward history-forward)
+    (when (and ostart (eq (window-buffer) (current-buffer)))
+      (set-window-start (selected-window) ostart t))
     (goto-char opoint)))
 \f
 (add-to-list 'Info-virtual-files
@@ -4307,7 +4326,7 @@ (defun Info-find-emacs-command-nodes (co
 	      (setq where
 		    (cons (list Info-current-file
 				(match-string-no-properties 2)
-				0)
+				0 0)
 			  where))
 	      (setq line-number (and (match-beginning 3)
 				     (string-to-number (match-string 3)))))





  reply	other threads:[~2012-08-25 19:29 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-21 22:17 bug#12253: Restore window start position Juri Linkov
2012-08-22  7:08 ` martin rudalics
2012-08-22 23:38   ` Juri Linkov
2012-08-23  8:48     ` martin rudalics
2012-08-23 22:00       ` Juri Linkov
2012-08-24  9:45         ` martin rudalics
2012-08-25  0:29           ` Juri Linkov
2012-08-25 13:40             ` martin rudalics
2012-08-25 19:29               ` Juri Linkov [this message]
2012-08-28  8:53                 ` Juri Linkov
2013-01-16 16:57                 ` Drew Adams
2013-01-18 22:42                   ` Drew Adams
2013-01-19 10:17                     ` Juri Linkov
2013-01-19 15:03                       ` Drew Adams
2013-03-29 16:56                         ` Drew Adams
2021-05-11 14:33                           ` Drew Adams
2021-05-11 17:53                             ` Juri Linkov
2021-05-11 18:46                               ` bug#12253: [External] : " Drew Adams
2021-05-11 19:29                                 ` Juri Linkov
2021-05-11 20:18                                   ` Drew Adams
2021-05-12  8:47                                   ` martin rudalics
2024-01-10 11:31                                     ` Stefan Kangas
2024-01-10 17:16                                       ` Juri Linkov

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=87r4qun7u1.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=12253@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).