comparison lisp/bs.el @ 73850:c089b114a8ec

(bs--redisplay): Fix typo in docstring. (bs--window-config-coming-from): Make frame-local. (bs--restore-window-config): New function. (bs-kill, bs-select, bs-select-other-window, bs-select-other-frame): Use it. (bs--show-with-configuration): Save the window configuration as a frame local var, and only if *buffer-selection* is not already visible on this frame. (bs--window-for-buffer): Return as soon as a matching buffer is found.
author Juanma Barranquero <lekktu@gmail.com>
date Thu, 09 Nov 2006 16:32:30 +0000
parents d4b7bfddf3f5
children 75ac3e7c76de
comparison
equal deleted inserted replaced
73849:9690e060fd5e 73850:c089b114a8ec
444 Non-nil means to show all buffers. Otherwise show buffers 444 Non-nil means to show all buffers. Otherwise show buffers
445 defined by current configuration `bs-current-configuration'.") 445 defined by current configuration `bs-current-configuration'.")
446 446
447 (defvar bs--window-config-coming-from nil 447 (defvar bs--window-config-coming-from nil
448 "Window configuration before starting Buffer Selection Menu.") 448 "Window configuration before starting Buffer Selection Menu.")
449 (make-variable-frame-local 'bs--window-config-coming-from)
449 450
450 (defvar bs--intern-show-never "^ \\|\\*buffer-selection\\*" 451 (defvar bs--intern-show-never "^ \\|\\*buffer-selection\\*"
451 "Regular expression specifying which buffers never to show. 452 "Regular expression specifying which buffers never to show.
452 A buffer whose name matches this regular expression will never be 453 A buffer whose name matches this regular expression will never be
453 included in the buffer list.") 454 included in the buffer list.")
582 buffer-list)) 583 buffer-list))
583 584
584 (defun bs--redisplay (&optional keep-line-p sort-description) 585 (defun bs--redisplay (&optional keep-line-p sort-description)
585 "Redisplay whole Buffer Selection Menu. 586 "Redisplay whole Buffer Selection Menu.
586 If KEEP-LINE-P is non-nil the point will stay on current line. 587 If KEEP-LINE-P is non-nil the point will stay on current line.
587 SORT-DESCRIPTION is an element of `bs-sort-functions'" 588 SORT-DESCRIPTION is an element of `bs-sort-functions'."
588 (let ((line (1+ (count-lines 1 (point))))) 589 (let ((line (1+ (count-lines 1 (point)))))
589 (bs-show-in-buffer (bs-buffer-list nil sort-description)) 590 (bs-show-in-buffer (bs-buffer-list nil sort-description))
590 (if keep-line-p 591 (if keep-line-p
591 (goto-line line)) 592 (goto-line line))
592 (beginning-of-line))) 593 (beginning-of-line)))
659 truncate-lines t 660 truncate-lines t
660 font-lock-defaults '(bs-mode-font-lock-keywords t) 661 font-lock-defaults '(bs-mode-font-lock-keywords t)
661 font-lock-verbose nil) 662 font-lock-verbose nil)
662 (run-mode-hooks 'bs-mode-hook)) 663 (run-mode-hooks 'bs-mode-hook))
663 664
665 (defun bs--restore-window-config ()
666 "Restore window configuration on the current frame."
667 (when bs--window-config-coming-from
668 (set-window-configuration bs--window-config-coming-from)
669 (setq bs--window-config-coming-from nil)))
670
664 (defun bs-kill () 671 (defun bs-kill ()
665 "Let buffer disappear and reset window-configuration." 672 "Let buffer disappear and reset window-configuration."
666 (interactive) 673 (interactive)
667 (bury-buffer (current-buffer)) 674 (bury-buffer (current-buffer))
668 (set-window-configuration bs--window-config-coming-from)) 675 (bs--restore-window-config))
669 676
670 (defun bs-abort () 677 (defun bs-abort ()
671 "Ding and leave Buffer Selection Menu without a selection." 678 "Ding and leave Buffer Selection Menu without a selection."
672 (interactive) 679 (interactive)
673 (ding) 680 (ding)
687 694
688 (defun bs--window-for-buffer (buffer-name) 695 (defun bs--window-for-buffer (buffer-name)
689 "Return a window showing a buffer with name BUFFER-NAME. 696 "Return a window showing a buffer with name BUFFER-NAME.
690 Take only windows of current frame into account. 697 Take only windows of current frame into account.
691 Return nil if there is no such buffer." 698 Return nil if there is no such buffer."
692 (let ((window nil)) 699 (catch 'window
693 (walk-windows (lambda (wind) 700 (walk-windows (lambda (w)
694 (if (string= (buffer-name (window-buffer wind)) 701 (when (string= (buffer-name (window-buffer w))
695 buffer-name) 702 buffer-name)
696 (setq window wind)))) 703 (throw 'window w))))
697 window)) 704 nil))
698 705
699 (defun bs--set-window-height () 706 (defun bs--set-window-height ()
700 "Change the height of the selected window to suit the current buffer list." 707 "Change the height of the selected window to suit the current buffer list."
701 (unless (one-window-p t) 708 (unless (one-window-p t)
702 (fit-window-to-buffer (selected-window) bs-max-window-height))) 709 (fit-window-to-buffer (selected-window) bs-max-window-height)))
734 will be selected in a window. 741 will be selected in a window.
735 Leave Buffer Selection Menu." 742 Leave Buffer Selection Menu."
736 (interactive) 743 (interactive)
737 (let ((buffer (bs--current-buffer))) 744 (let ((buffer (bs--current-buffer)))
738 (bury-buffer (current-buffer)) 745 (bury-buffer (current-buffer))
739 (set-window-configuration bs--window-config-coming-from) 746 (bs--restore-window-config)
740 (switch-to-buffer buffer) 747 (switch-to-buffer buffer)
741 (if bs--marked-buffers 748 (if bs--marked-buffers
742 ;; Some marked buffers for selection 749 ;; Some marked buffers for selection
743 (let* ((all (delq buffer bs--marked-buffers)) 750 (let* ((all (delq buffer bs--marked-buffers))
744 (height (/ (1- (frame-height)) (1+ (length all))))) 751 (height (/ (1- (frame-height)) (1+ (length all)))))
758 unless there is no other window. In this case a new window will be created. 765 unless there is no other window. In this case a new window will be created.
759 Leave Buffer Selection Menu." 766 Leave Buffer Selection Menu."
760 (interactive) 767 (interactive)
761 (let ((buffer (bs--current-buffer))) 768 (let ((buffer (bs--current-buffer)))
762 (bury-buffer (current-buffer)) 769 (bury-buffer (current-buffer))
763 (set-window-configuration bs--window-config-coming-from) 770 (bs--restore-window-config)
764 (switch-to-buffer-other-window buffer))) 771 (switch-to-buffer-other-window buffer)))
765 772
766 (defun bs-tmp-select-other-window () 773 (defun bs-tmp-select-other-window ()
767 "Make the other window select this line's buffer. 774 "Make the other window select this line's buffer.
768 The current window remains selected." 775 The current window remains selected."
774 "Select current line's buffer in new created frame. 781 "Select current line's buffer in new created frame.
775 Leave Buffer Selection Menu." 782 Leave Buffer Selection Menu."
776 (interactive) 783 (interactive)
777 (let ((buffer (bs--current-buffer))) 784 (let ((buffer (bs--current-buffer)))
778 (bury-buffer (current-buffer)) 785 (bury-buffer (current-buffer))
779 (set-window-configuration bs--window-config-coming-from) 786 (bs--restore-window-config)
780 (switch-to-buffer-other-frame buffer))) 787 (switch-to-buffer-other-frame buffer)))
781 788
782 (defun bs-mouse-select-other-frame (event) 789 (defun bs-mouse-select-other-frame (event)
783 "Select selected line's buffer in new created frame. 790 "Select selected line's buffer in new created frame.
784 Leave Buffer Selection Menu. 791 Leave Buffer Selection Menu.
1424 (bs-set-configuration name) 1431 (bs-set-configuration name)
1425 (let ((bs--show-all (or bs--show-all arg))) 1432 (let ((bs--show-all (or bs--show-all arg)))
1426 (unless (string= "*buffer-selection*" (buffer-name)) 1433 (unless (string= "*buffer-selection*" (buffer-name))
1427 ;; Only when not in buffer *buffer-selection* 1434 ;; Only when not in buffer *buffer-selection*
1428 ;; we have to set the buffer we started the command 1435 ;; we have to set the buffer we started the command
1429 (progn 1436 (setq bs--buffer-coming-from (current-buffer)))
1430 (setq bs--buffer-coming-from (current-buffer))
1431 (setq bs--window-config-coming-from (current-window-configuration))))
1432 (let ((liste (bs-buffer-list)) 1437 (let ((liste (bs-buffer-list))
1433 (active-window (bs--window-for-buffer "*buffer-selection*"))) 1438 (active-window (bs--window-for-buffer "*buffer-selection*")))
1434 (if active-window 1439 (if active-window
1435 (select-window active-window) 1440 (select-window active-window)
1436 (if (> (window-height (selected-window)) 7) 1441 (modify-frame-parameters nil
1437 (progn 1442 (list (cons 'bs--window-config-coming-from
1438 (split-window-vertically) 1443 (current-window-configuration))))
1439 (other-window 1)))) 1444 (when (> (window-height (selected-window)) 7)
1445 (split-window-vertically)
1446 (other-window 1)))
1440 (bs-show-in-buffer liste) 1447 (bs-show-in-buffer liste)
1441 (bs-message-without-log "%s" (bs--current-config-message))))) 1448 (bs-message-without-log "%s" (bs--current-config-message)))))
1442 1449
1443 (defun bs--configuration-name-for-prefix-arg (prefix-arg) 1450 (defun bs--configuration-name-for-prefix-arg (prefix-arg)
1444 "Convert prefix argument PREFIX-ARG to a name of a buffer configuration. 1451 "Convert prefix argument PREFIX-ARG to a name of a buffer configuration.