From 0f65b000da93fcb258e146ff4718dae0d2fa4378 Mon Sep 17 00:00:00 2001 From: duianto Date: Sat, 10 Oct 2020 22:48:38 +0200 Subject: [PATCH] Handle buffer move/select/swap to last win nr +1 (#14015) problem: The following error messages are shown. When trying to move, select or swap the current buffer, to a window nr greater than the total number of open windows. For example: With only one window open. `SPC b 2` >ad-Advice-select-window: Wrong type argument: window-live-p, nil In the Buffer Transient State (`SPC b .`): - `C-2` (`spacemacs/buffer-transient-state/winum-select-window-2`) >Wrong type argument: window-valid-p, # - `2` (`spacemacs/buffer-transient-state/move-buffer-window-no-follow-2`) >Wrong type argument: window-live-p, # - `M-2` (`spacemacs/buffer-transient-state/swap-buffer-window-no-follow-2`) >Wrong type argument: stringp, nil Solution: Show a descriptive message, if the target window nr is greater than the number of open windows. And ignore the LV buffer (hydra). --- CHANGELOG.develop | 1 + layers/+spacemacs/spacemacs-defaults/funcs.el | 41 +++++++++++-------- .../spacemacs-navigation/packages.el | 2 +- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.develop b/CHANGELOG.develop index 6d0fe48fc..728ab5e97 100644 --- a/CHANGELOG.develop +++ b/CHANGELOG.develop @@ -1363,6 +1363,7 @@ Other: - Fixed ~SPC h f~ =helm-spacemacs-help-faq= (thanks to duianto) - Fixed =cl= package deprecated =letf= (thanks to duianto) - Fixed origami bindings in normal mode (thanks to Tomasz Kowal) + - Handled buffer move/select/swap to last window nr +1 (thanks to duianto) - Set =evil-undo-system= to =undo-tree= (thanks to duianto) *** Layer changes and fixes **** Agda diff --git a/layers/+spacemacs/spacemacs-defaults/funcs.el b/layers/+spacemacs/spacemacs-defaults/funcs.el index 08d792702..b0592f402 100644 --- a/layers/+spacemacs/spacemacs-defaults/funcs.el +++ b/layers/+spacemacs/spacemacs-defaults/funcs.el @@ -261,30 +261,35 @@ Dedicated (locked) windows are left untouched." "Moves a buffer to a window, using the spacemacs numbering. follow-focus-p controls whether focus moves to new window (with buffer), or stays on current" (interactive) - (let ((b (current-buffer)) - (w1 (selected-window)) - (w2 (winum-get-window-by-number windownum))) - (unless (eq w1 w2) - (set-window-buffer w2 b) - (switch-to-prev-buffer) - (unrecord-window-buffer w1 b))) - (when follow-focus-p (select-window (winum-get-window-by-number windownum)))) + (if (> windownum (length (window-list))) + (message "No window numbered %s" windownum) + (let ((b (current-buffer)) + (w1 (selected-window)) + (w2 (winum-get-window-by-number windownum))) + (unless (eq w1 w2) + (set-window-buffer w2 b) + (switch-to-prev-buffer) + (unrecord-window-buffer w1 b)) + (when follow-focus-p + (select-window (winum-get-window-by-number windownum)))))) (defun spacemacs/swap-buffers-to-window (windownum follow-focus-p) "Swaps visible buffers between active window and selected window. follow-focus-p controls whether focus moves to new window (with buffer), or stays on current" (interactive) - (let* ((b1 (current-buffer)) - (w1 (selected-window)) - (w2 (winum-get-window-by-number windownum)) - (b2 (window-buffer w2))) - (unless (eq w1 w2) - (set-window-buffer w1 b2) - (set-window-buffer w2 b1) - (unrecord-window-buffer w1 b1) - (unrecord-window-buffer w2 b2))) - (when follow-focus-p (winum-select-window-by-number windownum))) + (if (> windownum (length (window-list))) + (message "No window numbered %s" windownum) + (let* ((b1 (current-buffer)) + (w1 (selected-window)) + (w2 (winum-get-window-by-number windownum)) + (b2 (window-buffer w2))) + (unless (eq w1 w2) + (set-window-buffer w1 b2) + (set-window-buffer w2 b1) + (unrecord-window-buffer w1 b1) + (unrecord-window-buffer w2 b2))) + (when follow-focus-p (winum-select-window-by-number windownum)))) (dotimes (i 9) (let ((n (+ i 1))) diff --git a/layers/+spacemacs/spacemacs-navigation/packages.el b/layers/+spacemacs/spacemacs-navigation/packages.el index c894e902f..38c999a98 100644 --- a/layers/+spacemacs/spacemacs-navigation/packages.el +++ b/layers/+spacemacs/spacemacs-navigation/packages.el @@ -431,7 +431,7 @@ (progn (setq winum-auto-assign-0-to-minibuffer nil winum-auto-setup-mode-line nil - winum-ignored-buffers '(" *which-key*")) + winum-ignored-buffers '(" *LV*" " *which-key*")) (spacemacs/set-leader-keys "`" 'winum-select-window-by-number "²" 'winum-select-window-by-number