diff options
| author | Juanma Barranquero | 2022-12-06 13:44:09 +0100 |
|---|---|---|
| committer | Juanma Barranquero | 2022-12-06 13:46:51 +0100 |
| commit | 80df980e4100297942775eae4f89c5ccabe03afc (patch) | |
| tree | 0154f9408d4aab02dd5dd14c75806a9ac2bf86e4 | |
| parent | f803203088c26e8906ae28e9b27cc6afa37fb8cb (diff) | |
| download | emacs-80df980e4100297942775eae4f89c5ccabe03afc.tar.gz emacs-80df980e4100297942775eae4f89c5ccabe03afc.zip | |
* lisp/bs.el: Adapt to modern display-buffer-alist window setup
* lisp/bs.el (bs--window-config-coming-from): Delete.
(bs-default-action-list): New user customizable option.
(bs--restore-window-config): Delete.
(bs-kill, bs-select, bs-select-other-window)
(bs-select-other-frame): Use `quit-window' instead.
(bs--show-with-configuration): Use `pop-to-buffer' to display
the "*buffer-selection*" buffer.
| -rw-r--r-- | lisp/bs.el | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/lisp/bs.el b/lisp/bs.el index 1fd31fb3b85..f880f3973a3 100644 --- a/lisp/bs.el +++ b/lisp/bs.el | |||
| @@ -420,9 +420,6 @@ naming a sort behavior. Default is \"by nothing\" which means no sorting." | |||
| 420 | Non-nil means to show all buffers. Otherwise show buffers | 420 | Non-nil means to show all buffers. Otherwise show buffers |
| 421 | defined by current configuration `bs-current-configuration'.") | 421 | defined by current configuration `bs-current-configuration'.") |
| 422 | 422 | ||
| 423 | (defvar bs--window-config-coming-from nil | ||
| 424 | "Window configuration before starting Buffer Selection Menu.") | ||
| 425 | |||
| 426 | (defvar bs--intern-show-never "^ \\|\\*buffer-selection\\*" | 423 | (defvar bs--intern-show-never "^ \\|\\*buffer-selection\\*" |
| 427 | "Regular expression specifying which buffers never to show. | 424 | "Regular expression specifying which buffers never to show. |
| 428 | A buffer whose name matches this regular expression will never be | 425 | A buffer whose name matches this regular expression will never be |
| @@ -491,7 +488,23 @@ Used internally, only.") | |||
| 491 | "<mouse-2>" #'bs-mouse-select | 488 | "<mouse-2>" #'bs-mouse-select |
| 492 | "<mouse-3>" #'bs-mouse-select-other-frame) | 489 | "<mouse-3>" #'bs-mouse-select-other-frame) |
| 493 | 490 | ||
| 494 | ;; ---------------------------------------------------------------------- | 491 | (defcustom bs-default-action-list '((display-buffer-reuse-window |
| 492 | display-buffer-below-selected) | ||
| 493 | (window-height . bs-max-window-height)) | ||
| 494 | "Default action list for showing the '*bs-selection*' buffer. | ||
| 495 | |||
| 496 | This list will be passed to `pop-to-buffer' as its ACTION argument. | ||
| 497 | It should be a cons cell (FUNCTIONS . ALIST), where FUNCTIONS is | ||
| 498 | an action function or a list of action functions and ALIST is an | ||
| 499 | action alist. Each such action function should accept two | ||
| 500 | arguments: a buffer to display and an alist of the same form as | ||
| 501 | ALIST. See `display-buffer' for details." | ||
| 502 | :type display-buffer--action-custom-type | ||
| 503 | :risky t | ||
| 504 | :version "30.1" | ||
| 505 | :group 'bs) | ||
| 506 | |||
| 507 | ; ---------------------------------------------------------------------- | ||
| 495 | ;; Functions | 508 | ;; Functions |
| 496 | ;; ---------------------------------------------------------------------- | 509 | ;; ---------------------------------------------------------------------- |
| 497 | 510 | ||
| @@ -668,20 +681,11 @@ apply it. | |||
| 668 | (add-hook 'kill-buffer-hook 'bs--remove-hooks nil t) | 681 | (add-hook 'kill-buffer-hook 'bs--remove-hooks nil t) |
| 669 | (add-hook 'change-major-mode-hook 'bs--remove-hooks nil t)) | 682 | (add-hook 'change-major-mode-hook 'bs--remove-hooks nil t)) |
| 670 | 683 | ||
| 671 | (defun bs--restore-window-config () | ||
| 672 | "Restore window configuration on the current frame." | ||
| 673 | (when bs--window-config-coming-from | ||
| 674 | (let ((frame (selected-frame))) | ||
| 675 | (unwind-protect | ||
| 676 | (set-window-configuration bs--window-config-coming-from) | ||
| 677 | (select-frame frame))) | ||
| 678 | (setq bs--window-config-coming-from nil))) | ||
| 679 | |||
| 680 | (defun bs-kill () | 684 | (defun bs-kill () |
| 681 | "Let buffer disappear and reset window configuration." | 685 | "Let buffer disappear and reset window configuration." |
| 682 | (interactive) | 686 | (interactive) |
| 683 | (bury-buffer (current-buffer)) | 687 | (bury-buffer (current-buffer)) |
| 684 | (bs--restore-window-config)) | 688 | (quit-window)) |
| 685 | 689 | ||
| 686 | (defun bs-abort () | 690 | (defun bs-abort () |
| 687 | "Ding and leave Buffer Selection Menu without a selection." | 691 | "Ding and leave Buffer Selection Menu without a selection." |
| @@ -742,7 +746,7 @@ Leave Buffer Selection Menu." | |||
| 742 | (interactive) | 746 | (interactive) |
| 743 | (let ((buffer (bs--current-buffer))) | 747 | (let ((buffer (bs--current-buffer))) |
| 744 | (bury-buffer (current-buffer)) | 748 | (bury-buffer (current-buffer)) |
| 745 | (bs--restore-window-config) | 749 | (quit-window) |
| 746 | (switch-to-buffer buffer) | 750 | (switch-to-buffer buffer) |
| 747 | (when bs--marked-buffers | 751 | (when bs--marked-buffers |
| 748 | ;; Some marked buffers for selection | 752 | ;; Some marked buffers for selection |
| @@ -765,7 +769,7 @@ Leave Buffer Selection Menu." | |||
| 765 | (interactive) | 769 | (interactive) |
| 766 | (let ((buffer (bs--current-buffer))) | 770 | (let ((buffer (bs--current-buffer))) |
| 767 | (bury-buffer (current-buffer)) | 771 | (bury-buffer (current-buffer)) |
| 768 | (bs--restore-window-config) | 772 | (quit-window) |
| 769 | (switch-to-buffer-other-window buffer))) | 773 | (switch-to-buffer-other-window buffer))) |
| 770 | 774 | ||
| 771 | (defun bs-tmp-select-other-window () | 775 | (defun bs-tmp-select-other-window () |
| @@ -781,7 +785,7 @@ Leave Buffer Selection Menu." | |||
| 781 | (interactive) | 785 | (interactive) |
| 782 | (let ((buffer (bs--current-buffer))) | 786 | (let ((buffer (bs--current-buffer))) |
| 783 | (bury-buffer (current-buffer)) | 787 | (bury-buffer (current-buffer)) |
| 784 | (bs--restore-window-config) | 788 | (quit-window) |
| 785 | (switch-to-buffer-other-frame buffer))) | 789 | (switch-to-buffer-other-frame buffer))) |
| 786 | 790 | ||
| 787 | (defun bs-mouse-select-other-frame (event) | 791 | (defun bs-mouse-select-other-frame (event) |
| @@ -1438,21 +1442,11 @@ for buffer selection." | |||
| 1438 | ;; Only when not in buffer *buffer-selection* | 1442 | ;; Only when not in buffer *buffer-selection* |
| 1439 | ;; we have to set the buffer we started the command | 1443 | ;; we have to set the buffer we started the command |
| 1440 | (setq bs--buffer-coming-from (current-buffer))) | 1444 | (setq bs--buffer-coming-from (current-buffer))) |
| 1441 | (let ((liste (bs-buffer-list)) | 1445 | (let ((window-combination-limit 'window-size)) |
| 1442 | (active-window (get-window-with-predicate | 1446 | (pop-to-buffer (get-buffer-create "*buffer-selection*") |
| 1443 | (lambda (w) | 1447 | bs-default-action-list)) |
| 1444 | (string= (buffer-name (window-buffer w)) | 1448 | (bs-show-in-buffer (bs-buffer-list)) |
| 1445 | "*buffer-selection*")) | 1449 | (bs-message-without-log "%s" (bs--current-config-message)))) |
| 1446 | nil (selected-frame)))) | ||
| 1447 | (if active-window | ||
| 1448 | (select-window active-window) | ||
| 1449 | (bs--restore-window-config) | ||
| 1450 | (setq bs--window-config-coming-from (current-window-configuration)) | ||
| 1451 | (when (> (window-height) 7) | ||
| 1452 | ;; Errors would mess with the window configuration (bug#10882). | ||
| 1453 | (ignore-errors (select-window (split-window-below))))) | ||
| 1454 | (bs-show-in-buffer liste) | ||
| 1455 | (bs-message-without-log "%s" (bs--current-config-message))))) | ||
| 1456 | 1450 | ||
| 1457 | (defun bs--configuration-name-for-prefix-arg (prefix) | 1451 | (defun bs--configuration-name-for-prefix-arg (prefix) |
| 1458 | "Convert prefix argument PREFIX to a name of a buffer configuration. | 1452 | "Convert prefix argument PREFIX to a name of a buffer configuration. |