emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: include new package wconf.el in GNU ELPA


From: Tassilo Horn
Subject: Re: include new package wconf.el in GNU ELPA
Date: Fri, 31 Jul 2015 15:39:32 +0200
User-agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.0.50 (gnu/linux)

martin rudalics <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]