recenter after visiting file (with savehist-mode)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

recenter after visiting file (with savehist-mode)

Jarosław Rzeszótko-2
I am trying to get Emacs to recenter the window around point after opening a file with savehist-mode. I tried adding an :after advise to save-place-find-file-hook, I tried setting a global display-buffer function, but no matter what I try I keep getting the dreaded:

`recenter'ing a window that does not display current-buffer.

Does anyone know any way around this?

Cheers,
Jarosław Rzeszótko
Reply | Threaded
Open this post in threaded view
|

Re: recenter after visiting file (with savehist-mode)

martin rudalics
 > I am trying to get Emacs to recenter the window around point after opening
 > a file with savehist-mode. I tried adding an :after advise to
 > save-place-find-file-hook, I tried setting a global display-buffer
 > function, but no matter what I try I keep getting the dreaded:
 >
 > `recenter'ing a window that does not display current-buffer.

You probably have to use a function like the below.

(defun recenter-window (&optional window)
   "Recenter WINDOW.
WINDOW must be a live window and defaults to the selected one."
   (let ((window (window-normalize-window window t)))
     (if (eq window (selected-window))
        (recenter)
       (with-selected-window window
        (recenter)))))

martin