- (when minimap-bufname
- (let ((win (get-buffer-window minimap-bufname))
- start end pt ov)
- (when win
- (setq start (window-start)
- end (window-end)
- pt (point)
- ov)
- (with-selected-window win
- (unless (and (not force)
- (= minimap-start start)
- (= minimap-end end))
- (move-overlay minimap-active-overlay start end)
- (setq minimap-start start
- minimap-end end)
- (minimap-recenter (line-number-at-pos (/ (+ end start) 2))
- (/ (- (line-number-at-pos end)
- (line-number-at-pos start))
- 2)))
- (goto-char pt)
- (when minimap-always-recenter
- (recenter (round (/ (window-height) 2)))))))))
+ (interactive)
+ ;; If we are in the minibuffer, do nothing.
+ (unless (active-minibuffer-window)
+ (if (minimap-active-current-buffer-p)
+ ;; We are still in the same buffer, so just update the minimap.
+ (let ((win (minimap-get-window))
+ (start (window-start))
+ (end (window-end))
+ (pt (point)))
+ (when (and (null win)
+ minimap-recreate-window)
+ ;; The minimap window is no longer visible, so create it again...
+ (setq win (minimap-create-window))
+ ;; ...and switch to existing minimap buffer.
+ (with-selected-window win
+ (when (window-dedicated-p)
+ (set-window-dedicated-p nil nil))
+ (switch-to-buffer minimap-buffer-name t t)
+ (when minimap-dedicated-window
+ (set-window-dedicated-p nil t))))
+ (with-selected-window win
+ ;; Make sure the base overlay spans the whole buffer.
+ (unless (and (= (overlay-start minimap-base-overlay) (point-min))
+ (= (overlay-end minimap-base-overlay) (point-max)))
+ (move-overlay minimap-base-overlay (point-min) (point-max)))
+ (unless (and (not force)
+ (= minimap-start start)
+ (= minimap-end end))
+ ;; Update the overlay.
+ (move-overlay minimap-active-overlay start end)
+ (setq minimap-start start
+ minimap-end end)
+ (minimap-recenter (line-number-at-pos (/ (+ end start) 2))
+ (/ (- (line-number-at-pos end)
+ (line-number-at-pos start))
+ 2)))
+ (goto-char pt)
+ (when minimap-always-recenter
+ (recenter (round (/ (window-height) 2)))))
+ ;; Redisplay
+ (sit-for 0))
+ ;; The buffer was switched, check if the minimap should switch, too.
+ (if (and minimap-major-modes
+ (apply 'derived-mode-p minimap-major-modes))
+ (progn
+ ;; Create window if necessary...
+ (unless (minimap-get-window)
+ (minimap-create-window))
+ ;; ...and re-create minimap with new buffer...
+ (minimap-new-minimap)
+ ;; Redisplay
+ (sit-for 0)
+ ;; ...and call update again.
+ (minimap-update t))
+ ;; Otherwise, delete window if the user so wishes.
+ (when (and (minimap-get-window)
+ minimap-automatically-delete-window)
+ ;; We wait a tiny bit before deleting the window, since we
+ ;; might only be temporarily in another buffer.
+ (run-with-timer 0.3 nil
+ (lambda ()
+ (when (and (null (minimap-active-current-buffer-p))
+ (minimap-get-window))
+ (delete-window (minimap-get-window))))))))))