Use a better workaround for margin display issue

This commit is contained in:
Nathaniel Nicandro 2018-01-17 20:56:42 -06:00
parent 1ee4b2b15d
commit 2d0328dde5

View file

@ -1043,13 +1043,22 @@ kernel that the REPL buffer is connected to."
(jupyter-shutdown-kernel jupyter-repl-kernel-manager))) (jupyter-shutdown-kernel jupyter-repl-kernel-manager)))
t)))) t))))
;; FIXME: Sometimes when using packages like `perspective', upon switching back ;; FIXME: This is necessary due to some interaction with other packages (I
;; to a perspective which has a REPL buffer visible, the margins will disappear ;; think). Sometimes the margins will disappear after the window configuration
;; when the `selected-window' after the switch is the REPL buffer. ;; changes which is why `window-configuration-change-hook' is not used.
(defun jupyter-repl-preserve-window-margins () (defun jupyter-repl-preserve-window-margins (&optional window)
(let ((margins (window-margins))) "Ensure that the margins of a REPL window are present.
(unless (and margins (= (car margins) jupyter-repl-prompt-margin-width)) This function is added as a hook to `pre-redisplay-functions' to
(set-window-margins nil jupyter-repl-prompt-margin-width)))) ensure that a REPL windows margins are present. If WINDOW is
showing a REPL buffer and the margins are not set to
`jupyter-repl-prompt-margin-width', set them to the proper
value."
(when (and (eq major-mode 'jupyter-repl-mode)
(let ((margins (window-margins window)))
(not (and (consp margins)
(car margins)
(= (car margins) jupyter-repl-prompt-margin-width)))))
(set-window-buffer window (current-buffer))))
;;; Completion ;;; Completion
@ -1515,7 +1524,7 @@ With a prefix argument, SHUTDOWN the kernel completely instead."
(jupyter-repl-isearch-setup) (jupyter-repl-isearch-setup)
(add-hook 'kill-buffer-query-functions #'jupyter-repl-kill-buffer-query-function nil t) (add-hook 'kill-buffer-query-functions #'jupyter-repl-kill-buffer-query-function nil t)
(add-hook 'after-change-functions 'jupyter-repl-after-buffer-change nil t) (add-hook 'after-change-functions 'jupyter-repl-after-buffer-change nil t)
(add-hook 'window-configuration-change-hook 'jupyter-repl-preserve-window-margins nil t)) (add-hook 'pre-redisplay-functions 'jupyter-repl-preserve-window-margins nil t))
(defun jupyter-repl-initialize-fontification () (defun jupyter-repl-initialize-fontification ()
(let (fld) (let (fld)