Skip to content

Commit

Permalink
Fix `window-size-change-function' for emacs > 26
Browse files Browse the repository at this point in the history
  • Loading branch information
akermu committed Apr 28, 2019
1 parent 756b944 commit 6adcedf
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions vterm.el
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ for different shell"
(setq-local scroll-conservatively 101)
(setq-local scroll-margin 0)

(add-hook 'window-size-change-functions #'vterm--window-size-change t t)
(if (version< emacs-version "27")
(add-hook 'window-size-change-functions #'vterm--window-size-change-26 t t)
(add-hook 'window-size-change-functions #'vterm--window-size-change t t))
(let ((process-environment (append '("TERM=xterm"
"INSIDE_EMACS=vterm"
"LINES"
Expand Down Expand Up @@ -310,19 +312,26 @@ Argument EVENT process event."
(run-hook-with-args 'vterm-exit-functions
(if (buffer-live-p buf) buf nil))))

(defun vterm--window-size-change (frame)
(defun vterm--window-size-change-26 (frame)
"Callback triggered by a size change of the FRAME.
Feeds the size change to the virtual terminal."
This is only used, when variable `emacs-version' < 27. Calls
`vterm--window-size-change' for every window of FRAME."
(dolist (window (window-list frame))
(with-current-buffer (window-buffer window)
(when (and (processp vterm--process)
(process-live-p vterm--process))
(let ((height (window-body-height window))
(width (window-body-width window))
(inhibit-read-only t))
(set-process-window-size vterm--process height width)
(vterm--set-size vterm--term height width))))))
(vterm--window-size-change window)))

(defun vterm--window-size-change (window)
"Callback triggered by a size change of the WINDOW.
Feeds the size change to the virtual terminal."
(with-current-buffer (window-buffer window)
(when (and (processp vterm--process)
(process-live-p vterm--process))
(let ((height (window-body-height window))
(width (window-body-width window))
(inhibit-read-only t))
(set-process-window-size vterm--process height width)
(vterm--set-size vterm--term height width)))))

(defun vterm--delete-lines (line-num count &optional delete-whole-line)
"Delete COUNT lines from LINE-NUM.
Expand Down

0 comments on commit 6adcedf

Please sign in to comment.