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, #<window 12>

- `2` (`spacemacs/buffer-transient-state/move-buffer-window-no-follow-2`)
>Wrong type argument: window-live-p, #<window 14>

- `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).
This commit is contained in:
duianto 2020-10-10 22:48:38 +02:00 committed by GitHub
parent b5e74cd463
commit 0f65b000da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 19 deletions

View File

@ -1363,6 +1363,7 @@ Other:
- Fixed ~SPC h f~ =helm-spacemacs-help-faq= (thanks to duianto) - Fixed ~SPC h f~ =helm-spacemacs-help-faq= (thanks to duianto)
- Fixed =cl= package deprecated =letf= (thanks to duianto) - Fixed =cl= package deprecated =letf= (thanks to duianto)
- Fixed origami bindings in normal mode (thanks to Tomasz Kowal) - 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) - Set =evil-undo-system= to =undo-tree= (thanks to duianto)
*** Layer changes and fixes *** Layer changes and fixes
**** Agda **** Agda

View File

@ -261,30 +261,35 @@ Dedicated (locked) windows are left untouched."
"Moves a buffer to a window, using the spacemacs numbering. follow-focus-p "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" controls whether focus moves to new window (with buffer), or stays on current"
(interactive) (interactive)
(let ((b (current-buffer)) (if (> windownum (length (window-list)))
(w1 (selected-window)) (message "No window numbered %s" windownum)
(w2 (winum-get-window-by-number windownum))) (let ((b (current-buffer))
(unless (eq w1 w2) (w1 (selected-window))
(set-window-buffer w2 b) (w2 (winum-get-window-by-number windownum)))
(switch-to-prev-buffer) (unless (eq w1 w2)
(unrecord-window-buffer w1 b))) (set-window-buffer w2 b)
(when follow-focus-p (select-window (winum-get-window-by-number windownum)))) (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) (defun spacemacs/swap-buffers-to-window (windownum follow-focus-p)
"Swaps visible buffers between active window and selected window. "Swaps visible buffers between active window and selected window.
follow-focus-p controls whether focus moves to new window (with buffer), or follow-focus-p controls whether focus moves to new window (with buffer), or
stays on current" stays on current"
(interactive) (interactive)
(let* ((b1 (current-buffer)) (if (> windownum (length (window-list)))
(w1 (selected-window)) (message "No window numbered %s" windownum)
(w2 (winum-get-window-by-number windownum)) (let* ((b1 (current-buffer))
(b2 (window-buffer w2))) (w1 (selected-window))
(unless (eq w1 w2) (w2 (winum-get-window-by-number windownum))
(set-window-buffer w1 b2) (b2 (window-buffer w2)))
(set-window-buffer w2 b1) (unless (eq w1 w2)
(unrecord-window-buffer w1 b1) (set-window-buffer w1 b2)
(unrecord-window-buffer w2 b2))) (set-window-buffer w2 b1)
(when follow-focus-p (winum-select-window-by-number windownum))) (unrecord-window-buffer w1 b1)
(unrecord-window-buffer w2 b2)))
(when follow-focus-p (winum-select-window-by-number windownum))))
(dotimes (i 9) (dotimes (i 9)
(let ((n (+ i 1))) (let ((n (+ i 1)))

View File

@ -431,7 +431,7 @@
(progn (progn
(setq winum-auto-assign-0-to-minibuffer nil (setq winum-auto-assign-0-to-minibuffer nil
winum-auto-setup-mode-line nil winum-auto-setup-mode-line nil
winum-ignored-buffers '(" *which-key*")) winum-ignored-buffers '(" *LV*" " *which-key*"))
(spacemacs/set-leader-keys (spacemacs/set-leader-keys
"`" 'winum-select-window-by-number "`" 'winum-select-window-by-number
"²" 'winum-select-window-by-number "²" 'winum-select-window-by-number