unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tsdh@gnu.org>
To: martin rudalics <rudalics@gmx.at>
Cc: Ingo Lohmar <i.lohmar@gmail.com>, emacs-devel@gnu.org
Subject: Re: include new package wconf.el in GNU ELPA
Date: Fri, 31 Jul 2015 15:39:32 +0200	[thread overview]
Message-ID: <87h9okh2ej.fsf@gnu.org> (raw)
In-Reply-To: <55BB463D.4080202@gmx.at> (martin rudalics's message of "Fri, 31 Jul 2015 11:56:13 +0200")

martin rudalics <rudalics@gmx.at> writes:

>> They use `goto-char' in the window which is selected after setting
>> the window configuration, so I guess it's the buffer's point.
>
> I still don't get what you want instead.
>
>>    (let ((bufpoints (mapcar
>> 		    (lambda (buf)
>> 		      (cons buf (with-selected-window (get-buffer-window buf)
>> 				  (point))))
>> 		    (cl-remove-if-not #'get-buffer-window
>> 				      (buffer-list (selected-frame)))))
>
> All you can possibly want here are window-points, the positions of the
> cursor in any window shown before or after setting the configuration.
> Calling `buffer-list' makes no sense.

Ok, so is this better?

--8<---------------cut here---------------start------------->8---
;; Keep window selection and point
(defun th/window-config-keep-points-and-selected-window (old config)
  (let ((bufpoints (mapcar (lambda (win)
			     (cons (window-buffer win) (window-point win)))
			   (window-list (selected-frame))))
	(selected-buf (current-buffer)))
    (funcall old config)
    ;; Do our magic only if called interactively.
    (when (and (memq this-command '(jump-to-register winner-undo winner-redo))
	       (called-interactively-p 'interactive))
      ;; Restore selected window
      (when-let ((w (get-buffer-window selected-buf)))
	(select-window w))
      ;; The setting of point is not performed by `set-window-configuration'
      ;; itself but by `jump-to-register' or the winner functions.
      (run-with-timer 0.139 nil
		      (lambda ()
			(dolist (bp bufpoints)
			  (when-let ((w (get-buffer-window (car bp))))
			    (set-window-point win (cdr bp)))))))))

(advice-add #'set-window-configuration :around
	    #'th/window-config-keep-points-and-selected-window)
--8<---------------cut here---------------end--------------->8---

It seems to do what I had in mind.

>> But that's also really bad.  For example, `edebug' uses
>> `set-window-configuration' internally, so point always jumps back
>> after each edebug step.
>
> `set-window-configuration' should be used only "internally".  It's
> main design goal is that the user should _not_ be aware of its
> existence.
>
> Maybe you could use `window-state-get' and `window-state-put' instead.

You mean, get the state of all windows in the current window
configuration, then switch to the other, and then put the state back for
all windows of buffers that were also displayed in the previous WC?

Bye,
Tassilo



  reply	other threads:[~2015-07-31 13:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-30 15:31 include new package wconf.el in GNU ELPA Ingo Lohmar
2015-07-30 18:57 ` Dmitry Gutov
2015-07-30 19:17 ` Tassilo Horn
2015-07-30 20:58   ` Ingo Lohmar
2015-07-31  5:35     ` Tassilo Horn
2015-07-31  7:10       ` martin rudalics
2015-07-31  8:27         ` Tassilo Horn
2015-07-31  9:56           ` martin rudalics
2015-07-31 13:39             ` Tassilo Horn [this message]
2015-08-01 10:50               ` martin rudalics
2015-08-03  7:45                 ` Tassilo Horn
2015-07-31  9:24       ` Ingo Lohmar
2015-07-31  7:10   ` martin rudalics
2015-07-31  8:37     ` Tassilo Horn
2015-07-31  9:56       ` martin rudalics
2015-07-31 13:56         ` Tassilo Horn
2015-08-01 10:50           ` 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=87h9okh2ej.fsf@gnu.org \
    --to=tsdh@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=i.lohmar@gmail.com \
    --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).