comparison lisp/bs.el @ 79104:4801bb53c00e

(bs--window-config-coming-from): Revert 2006-11-09 change. (bs--restore-window-config): Keep the selected frame. (bs--track-window-changes, bs--remove-hooks): New functions. (bs-mode): Use `define-derived-mode'. Set hook to track window changes. (bs--show-with-configuration): Revert 2006-11-09 change. Don't reuse window unless it is visible on the selected frame. Restore window configuration (possibly in a different frame) before creating any window.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 16 Oct 2007 10:52:09 +0000
parents 467771c10c11
children e091b0e7b0c7
comparison
equal deleted inserted replaced
79103:e0cb59c9f4d4 79104:4801bb53c00e
443 Non-nil means to show all buffers. Otherwise show buffers 443 Non-nil means to show all buffers. Otherwise show buffers
444 defined by current configuration `bs-current-configuration'.") 444 defined by current configuration `bs-current-configuration'.")
445 445
446 (defvar bs--window-config-coming-from nil 446 (defvar bs--window-config-coming-from nil
447 "Window configuration before starting Buffer Selection Menu.") 447 "Window configuration before starting Buffer Selection Menu.")
448 (make-variable-frame-local 'bs--window-config-coming-from)
449 448
450 (defvar bs--intern-show-never "^ \\|\\*buffer-selection\\*" 449 (defvar bs--intern-show-never "^ \\|\\*buffer-selection\\*"
451 "Regular expression specifying which buffers never to show. 450 "Regular expression specifying which buffers never to show.
452 A buffer whose name matches this regular expression will never be 451 A buffer whose name matches this regular expression will never be
453 included in the buffer list.") 452 included in the buffer list.")
612 (if bs--show-all 611 (if bs--show-all
613 "Show all buffers." 612 "Show all buffers."
614 (format "Show buffer by configuration %S" 613 (format "Show buffer by configuration %S"
615 bs-current-configuration))) 614 bs-current-configuration)))
616 615
617 (defun bs-mode () 616 (defun bs--track-window-changes (frame)
617 "Track window changes to refresh the buffer list.
618 Used from `window-size-change-functions'."
619 (let ((win (get-buffer-window "*buffer-selection*" frame)))
620 (when win
621 (with-selected-window win
622 (bs-refresh)
623 (bs--set-window-height)))))
624
625 (defun bs--remove-hooks ()
626 "Remove `bs--track-window-changes' and auxiliary hooks."
627 (remove-hook 'window-size-change-functions 'bs--track-window-changes)
628 ;; Remove itself
629 (remove-hook 'kill-buffer-hook 'bs--remove-hooks t)
630 (remove-hook 'change-major-mode-hook 'bs--remove-hooks t))
631
632 (define-derived-mode bs-mode ()
618 "Major mode for editing a subset of Emacs' buffers. 633 "Major mode for editing a subset of Emacs' buffers.
619 \\<bs-mode-map> 634 \\<bs-mode-map>
620 Aside from two header lines each line describes one buffer. 635 Aside from two header lines each line describes one buffer.
621 Move to a line representing the buffer you want to edit and select 636 Move to a line representing the buffer you want to edit and select
622 buffer by \\[bs-select] or SPC. Abort buffer list with \\[bs-kill]. 637 buffer by \\[bs-select] or SPC. Abort buffer list with \\[bs-kill].
645 \\[bs-toggle-current-to-show] -- toggle status of appearance. 660 \\[bs-toggle-current-to-show] -- toggle status of appearance.
646 \\[bs-set-current-buffer-to-show-always] -- mark current line's buffer \ 661 \\[bs-set-current-buffer-to-show-always] -- mark current line's buffer \
647 to show always. 662 to show always.
648 \\[bs-visit-tags-table] -- call `visit-tags-table' on current line's buffer. 663 \\[bs-visit-tags-table] -- call `visit-tags-table' on current line's buffer.
649 \\[bs-help] -- display this help text." 664 \\[bs-help] -- display this help text."
650 (interactive)
651 (kill-all-local-variables)
652 (use-local-map bs-mode-map)
653 (make-local-variable 'font-lock-defaults) 665 (make-local-variable 'font-lock-defaults)
654 (make-local-variable 'font-lock-verbose) 666 (make-local-variable 'font-lock-verbose)
655 (make-local-variable 'font-lock-global-modes) 667 (make-local-variable 'font-lock-global-modes)
656 (buffer-disable-undo) 668 (buffer-disable-undo)
657 (setq major-mode 'bs-mode 669 (setq buffer-read-only t
658 mode-name "Buffer-Selection-Menu"
659 buffer-read-only t
660 truncate-lines t 670 truncate-lines t
661 show-trailing-whitespace nil 671 show-trailing-whitespace nil
662 font-lock-global-modes '(not bs-mode) 672 font-lock-global-modes '(not bs-mode)
663 font-lock-defaults '(bs-mode-font-lock-keywords t) 673 font-lock-defaults '(bs-mode-font-lock-keywords t)
664 font-lock-verbose nil) 674 font-lock-verbose nil))
665 (run-mode-hooks 'bs-mode-hook))
666 675
667 (defun bs--restore-window-config () 676 (defun bs--restore-window-config ()
668 "Restore window configuration on the current frame." 677 "Restore window configuration on the current frame."
669 (when bs--window-config-coming-from 678 (when bs--window-config-coming-from
670 (set-window-configuration bs--window-config-coming-from) 679 (let ((frame (selected-frame)))
680 (unwind-protect
681 (set-window-configuration bs--window-config-coming-from)
682 (select-frame frame)))
671 (setq bs--window-config-coming-from nil))) 683 (setq bs--window-config-coming-from nil)))
672 684
673 (defun bs-kill () 685 (defun bs-kill ()
674 "Let buffer disappear and reset window configuration." 686 "Let buffer disappear and reset window configuration."
675 (interactive) 687 (interactive)
1427 (setq bs--buffer-coming-from (current-buffer))) 1439 (setq bs--buffer-coming-from (current-buffer)))
1428 (let ((liste (bs-buffer-list)) 1440 (let ((liste (bs-buffer-list))
1429 (active-window (get-window-with-predicate 1441 (active-window (get-window-with-predicate
1430 (lambda (w) 1442 (lambda (w)
1431 (string= (buffer-name (window-buffer w)) 1443 (string= (buffer-name (window-buffer w))
1432 "*buffer-selection*"))))) 1444 "*buffer-selection*"))
1445 nil (selected-frame))))
1433 (if active-window 1446 (if active-window
1434 (select-window active-window) 1447 (select-window active-window)
1435 (modify-frame-parameters nil 1448 (bs--restore-window-config)
1436 (list (cons 'bs--window-config-coming-from 1449 (setq bs--window-config-coming-from (current-window-configuration))
1437 (current-window-configuration))))
1438 (when (> (window-height (selected-window)) 7) 1450 (when (> (window-height (selected-window)) 7)
1439 (split-window-vertically) 1451 (split-window-vertically)
1440 (other-window 1))) 1452 (other-window 1)))
1441 (bs-show-in-buffer liste) 1453 (bs-show-in-buffer liste)
1442 (bs-message-without-log "%s" (bs--current-config-message))))) 1454 (bs-message-without-log "%s" (bs--current-config-message)))))