comparison lisp/bs.el @ 91040:14c4a6aac623

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 866-879) - Merge multi-tty branch - Update from CVS - Merge from emacs--rel--22 Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-257
author Miles Bader <miles@gnu.org>
date Thu, 11 Oct 2007 16:14:00 +0000
parents f55f9811f5d7 467771c10c11
children d38543a1c0f9
comparison
equal deleted inserted replaced
91039:eefadc1e1d5e 91040:14c4a6aac623
129 129
130 ;;; History: 130 ;;; History:
131 131
132 ;;; Code: 132 ;;; Code:
133 133
134 (defvar font-lock-verbose)
135
136 ;; ---------------------------------------------------------------------- 134 ;; ----------------------------------------------------------------------
137 ;; Globals for customization 135 ;; Globals for customization
138 ;; ---------------------------------------------------------------------- 136 ;; ----------------------------------------------------------------------
139 137
140 (defgroup bs nil 138 (defgroup bs nil
242 "Function for specifying buffers which must be shown. 240 "Function for specifying buffers which must be shown.
243 The function gets one argument - the buffer to test.") 241 The function gets one argument - the buffer to test.")
244 242
245 (defvar bs-buffer-sort-function nil 243 (defvar bs-buffer-sort-function nil
246 "Sort function to sort the buffers that appear in Buffer Selection Menu. 244 "Sort function to sort the buffers that appear in Buffer Selection Menu.
247 The function gets two arguments - the buffers to compare.") 245 The function gets two arguments - the buffers to compare.
246 It must return non-nil if the first buffer should sort before the second.")
248 247
249 (defcustom bs-maximal-buffer-name-column 45 248 (defcustom bs-maximal-buffer-name-column 45
250 "*Maximum column width for buffer names. 249 "*Maximum column width for buffer names.
251 The column for buffer names has dynamic width. The width depends on 250 The column for buffer names has dynamic width. The width depends on
252 maximal and minimal length of names of buffers to show. The maximal 251 maximal and minimal length of names of buffers to show. The maximal
335 "*String added in column 1 indicating a marked buffer." 334 "*String added in column 1 indicating a marked buffer."
336 :group 'bs-appearance 335 :group 'bs-appearance
337 :type 'string) 336 :type 'string)
338 337
339 (defcustom bs-string-show-normally " " 338 (defcustom bs-string-show-normally " "
340 "*String added in column 1 indicating a unmarked buffer." 339 "*String added in column 1 indicating an unmarked buffer."
341 :group 'bs-appearance 340 :group 'bs-appearance
342 :type 'string) 341 :type 'string)
343 342
344 (defvar bs--name-entry-length 20 343 (defvar bs--name-entry-length 20
345 "Maximum length of all displayed buffer names. 344 "Maximum length of all displayed buffer names.
391 ("by mode" bs--sort-by-mode "Mode" region) 390 ("by mode" bs--sort-by-mode "Mode" region)
392 ("by filename" bs--sort-by-filename "File" region) 391 ("by filename" bs--sort-by-filename "File" region)
393 ("by nothing" nil nil nil)) 392 ("by nothing" nil nil nil))
394 "*List of all possible sorting aspects for Buffer Selection Menu. 393 "*List of all possible sorting aspects for Buffer Selection Menu.
395 You can add a new entry with a call to `bs-define-sort-function'. 394 You can add a new entry with a call to `bs-define-sort-function'.
396 Each element is a list of four elements (NAME FUNCTION REGEXP-FOR-SORTING FACE) 395 Each element is a list of four elements (NAME FUNCTION REGEXP-FOR-SORTING FACE).
397 NAME specifies the sort order defined by function FUNCTION. 396 NAME specifies the sort order defined by function FUNCTION.
398 FUNCTION nil means don't sort the buffer list. Otherwise the functions 397 FUNCTION nil means don't sort the buffer list. Otherwise the function
399 must have two parameters - the buffers to compare. 398 must have two parameters - the buffers to compare.
400 REGEXP-FOR-SORTING is a regular expression which describes the 399 REGEXP-FOR-SORTING is a regular expression which describes the
401 column title to highlight. 400 column title to highlight.
402 FACE is a face used to fontify the sorted column title. A value of nil means 401 FACE is a face used to fontify the sorted column title. A value of nil means
403 don't highlight." 402 don't highlight."
618 (defun bs-mode () 617 (defun bs-mode ()
619 "Major mode for editing a subset of Emacs' buffers. 618 "Major mode for editing a subset of Emacs' buffers.
620 \\<bs-mode-map> 619 \\<bs-mode-map>
621 Aside from two header lines each line describes one buffer. 620 Aside from two header lines each line describes one buffer.
622 Move to a line representing the buffer you want to edit and select 621 Move to a line representing the buffer you want to edit and select
623 buffer by \\[bs-select] or SPC. Abort buffer list with \\[bs-kill]. 622 buffer by \\[bs-select] or SPC. Abort buffer list with \\[bs-kill].
624 There are many key commands similar to `Buffer-menu-mode' for 623 There are many key commands similar to `Buffer-menu-mode' for
625 manipulating the buffer list and buffers. 624 manipulating the buffer list and buffers.
626 For faster navigation each digit key is a digit argument. 625 For faster navigation each digit key is a digit argument.
627 626
628 \\[bs-select] or SPACE -- select current line's buffer and other marked buffers. 627 \\[bs-select] or SPACE -- select current line's buffer and other marked buffers.
651 (interactive) 650 (interactive)
652 (kill-all-local-variables) 651 (kill-all-local-variables)
653 (use-local-map bs-mode-map) 652 (use-local-map bs-mode-map)
654 (make-local-variable 'font-lock-defaults) 653 (make-local-variable 'font-lock-defaults)
655 (make-local-variable 'font-lock-verbose) 654 (make-local-variable 'font-lock-verbose)
655 (make-local-variable 'font-lock-global-modes)
656 (buffer-disable-undo) 656 (buffer-disable-undo)
657 (setq major-mode 'bs-mode 657 (setq major-mode 'bs-mode
658 mode-name "Buffer-Selection-Menu" 658 mode-name "Buffer-Selection-Menu"
659 buffer-read-only t 659 buffer-read-only t
660 truncate-lines t 660 truncate-lines t
661 show-trailing-whitespace nil
662 font-lock-global-modes '(not bs-mode)
661 font-lock-defaults '(bs-mode-font-lock-keywords t) 663 font-lock-defaults '(bs-mode-font-lock-keywords t)
662 font-lock-verbose nil) 664 font-lock-verbose nil)
663 (run-mode-hooks 'bs-mode-hook)) 665 (run-mode-hooks 'bs-mode-hook))
664 666
665 (defun bs--restore-window-config () 667 (defun bs--restore-window-config ()
667 (when bs--window-config-coming-from 669 (when bs--window-config-coming-from
668 (set-window-configuration bs--window-config-coming-from) 670 (set-window-configuration bs--window-config-coming-from)
669 (setq bs--window-config-coming-from nil))) 671 (setq bs--window-config-coming-from nil)))
670 672
671 (defun bs-kill () 673 (defun bs-kill ()
672 "Let buffer disappear and reset window-configuration." 674 "Let buffer disappear and reset window configuration."
673 (interactive) 675 (interactive)
674 (bury-buffer (current-buffer)) 676 (bury-buffer (current-buffer))
675 (bs--restore-window-config)) 677 (bs--restore-window-config))
676 678
677 (defun bs-abort () 679 (defun bs-abort ()
776 (switch-to-buffer-other-frame buffer))) 778 (switch-to-buffer-other-frame buffer)))
777 779
778 (defun bs-mouse-select-other-frame (event) 780 (defun bs-mouse-select-other-frame (event)
779 "Select selected line's buffer in new created frame. 781 "Select selected line's buffer in new created frame.
780 Leave Buffer Selection Menu. 782 Leave Buffer Selection Menu.
781 EVENT: a mouse click EVENT." 783 EVENT: a mouse click event."
782 (interactive "e") 784 (interactive "e")
783 (mouse-set-point event) 785 (mouse-set-point event)
784 (bs-select-other-frame)) 786 (bs-select-other-frame))
785 787
786 (defun bs-mouse-select (event) 788 (defun bs-mouse-select (event)
927 (bs-delete) 929 (bs-delete)
928 (unless on-last-line-p 930 (unless on-last-line-p
929 (bs-up 1)))) 931 (bs-up 1))))
930 932
931 (defun bs-show-sorted () 933 (defun bs-show-sorted ()
932 "Show buffer list sorted by buffer name." 934 "Show buffer list sorted by next sort aspect."
933 (interactive) 935 (interactive)
934 (setq bs--current-sort-function 936 (setq bs--current-sort-function
935 (bs-next-config-aux (car bs--current-sort-function) 937 (bs-next-config-aux (car bs--current-sort-function)
936 bs-sort-functions)) 938 bs-sort-functions))
937 (bs--redisplay) 939 (bs--redisplay)
1018 (if (eq (line-end-position) (point-max)) 1020 (if (eq (line-end-position) (point-max))
1019 (goto-line (1+ bs-header-lines-length)) 1021 (goto-line (1+ bs-header-lines-length))
1020 (forward-line 1))) 1022 (forward-line 1)))
1021 1023
1022 (defun bs-visits-non-file (buffer) 1024 (defun bs-visits-non-file (buffer)
1023 "Return t or nil whether BUFFER visits no file. 1025 "Return whether BUFFER visits no file.
1024 A value of t means BUFFER belongs to no file. 1026 A value of t means BUFFER belongs to no file.
1025 A value of nil means BUFFER belongs to a file." 1027 A value of nil means BUFFER belongs to a file."
1026 (not (buffer-file-name buffer))) 1028 (not (buffer-file-name buffer)))
1027 1029
1028 (defun bs-sort-buffer-interns-are-last (b1 b2) 1030 (defun bs-sort-buffer-interns-are-last (b1 b2)
1029 "Function for sorting internal buffers B1 and B2 at the end of all buffers." 1031 "Function for sorting internal buffers at the end of all buffers."
1030 (string-match "^\\*" (buffer-name b2))) 1032 (string-match "^\\*" (buffer-name b2)))
1031 1033
1032 ;; ---------------------------------------------------------------------- 1034 ;; ----------------------------------------------------------------------
1033 ;; Configurations: 1035 ;; Configurations:
1034 ;; ---------------------------------------------------------------------- 1036 ;; ----------------------------------------------------------------------
1035 1037
1036 (defun bs-config-clear () 1038 (defun bs-config-clear ()
1037 "*Reset all variables which specify a configuration. 1039 "Reset all variables which specify a configuration.
1038 These variables are `bs-dont-show-regexp', `bs-must-show-regexp', 1040 These variables are `bs-dont-show-regexp', `bs-must-show-regexp',
1039 `bs-dont-show-function', `bs-must-show-function' and 1041 `bs-dont-show-function', `bs-must-show-function' and
1040 `bs-buffer-sort-function'." 1042 `bs-buffer-sort-function'."
1041 (setq bs-dont-show-regexp nil 1043 (setq bs-dont-show-regexp nil
1042 bs-must-show-regexp nil 1044 bs-must-show-regexp nil
1272 (t (apply fun args)))) 1274 (t (apply fun args))))
1273 1275
1274 (defun bs--get-marked-string (start-buffer all-buffers) 1276 (defun bs--get-marked-string (start-buffer all-buffers)
1275 "Return a string which describes whether current buffer is marked. 1277 "Return a string which describes whether current buffer is marked.
1276 START-BUFFER is the buffer where we started buffer selection. 1278 START-BUFFER is the buffer where we started buffer selection.
1277 ALL-BUFFERS is the list of buffer appearing in Buffer Selection Menu. 1279 ALL-BUFFERS is the list of buffers appearing in Buffer Selection Menu.
1278 The result string is one of `bs-string-current', `bs-string-current-marked', 1280 The result string is one of `bs-string-current', `bs-string-current-marked',
1279 `bs-string-marked', `bs-string-show-normally', `bs-string-show-never', or 1281 `bs-string-marked', `bs-string-show-normally', `bs-string-show-never', or
1280 `bs-string-show-always'." 1282 `bs-string-show-always'."
1281 (cond ;; current buffer is the buffer we started buffer selection. 1283 (cond ;; current buffer is the buffer we started buffer selection.
1282 ((eq (current-buffer) start-buffer) 1284 ((eq (current-buffer) start-buffer)
1297 bs-string-show-always))) 1299 bs-string-show-always)))
1298 1300
1299 (defun bs--get-modified-string (start-buffer all-buffers) 1301 (defun bs--get-modified-string (start-buffer all-buffers)
1300 "Return a string which describes whether current buffer is modified. 1302 "Return a string which describes whether current buffer is modified.
1301 START-BUFFER is the buffer where we started buffer selection. 1303 START-BUFFER is the buffer where we started buffer selection.
1302 ALL-BUFFERS is the list of buffer appearing in Buffer Selection Menu." 1304 ALL-BUFFERS is the list of buffers appearing in Buffer Selection Menu."
1303 (if (buffer-modified-p) "*" " ")) 1305 (if (buffer-modified-p) "*" " "))
1304 1306
1305 (defun bs--get-readonly-string (start-buffer all-buffers) 1307 (defun bs--get-readonly-string (start-buffer all-buffers)
1306 "Return a string which describes whether current buffer is read only. 1308 "Return a string which describes whether current buffer is read only.
1307 START-BUFFER is the buffer where we started buffer selection. 1309 START-BUFFER is the buffer where we started buffer selection.
1308 ALL-BUFFERS is the list of buffer appearing in Buffer Selection Menu." 1310 ALL-BUFFERS is the list of buffers appearing in Buffer Selection Menu."
1309 (if buffer-read-only "%" " ")) 1311 (if buffer-read-only "%" " "))
1310 1312
1311 (defun bs--get-size-string (start-buffer all-buffers) 1313 (defun bs--get-size-string (start-buffer all-buffers)
1312 "Return a string which describes the size of current buffer. 1314 "Return a string which describes the size of current buffer.
1313 START-BUFFER is the buffer where we started buffer selection. 1315 START-BUFFER is the buffer where we started buffer selection.
1314 ALL-BUFFERS is the list of buffer appearing in Buffer Selection Menu." 1316 ALL-BUFFERS is the list of buffers appearing in Buffer Selection Menu."
1315 (int-to-string (buffer-size))) 1317 (int-to-string (buffer-size)))
1316 1318
1317 (defun bs--get-name (start-buffer all-buffers) 1319 (defun bs--get-name (start-buffer all-buffers)
1318 "Return name of current buffer for Buffer Selection Menu. 1320 "Return name of current buffer for Buffer Selection Menu.
1319 The name of current buffer gets additional text properties 1321 The name of current buffer gets additional text properties
1320 for mouse highlighting. 1322 for mouse highlighting.
1321 START-BUFFER is the buffer where we started buffer selection. 1323 START-BUFFER is the buffer where we started buffer selection.
1322 ALL-BUFFERS is the list of buffer appearing in Buffer Selection Menu." 1324 ALL-BUFFERS is the list of buffers appearing in Buffer Selection Menu."
1323 (propertize (buffer-name) 1325 (propertize (buffer-name)
1324 'help-echo "mouse-2: select this buffer, mouse-3: select in other frame" 1326 'help-echo "mouse-2: select this buffer, mouse-3: select in other frame"
1325 'mouse-face 'highlight)) 1327 'mouse-face 'highlight))
1326 1328
1327 (defun bs--get-mode-name (start-buffer all-buffers) 1329 (defun bs--get-mode-name (start-buffer all-buffers)
1328 "Return the name of mode of current buffer for Buffer Selection Menu. 1330 "Return the name of mode of current buffer for Buffer Selection Menu.
1329 START-BUFFER is the buffer where we started buffer selection. 1331 START-BUFFER is the buffer where we started buffer selection.
1330 ALL-BUFFERS is the list of buffer appearing in Buffer Selection Menu." 1332 ALL-BUFFERS is the list of buffers appearing in Buffer Selection Menu."
1331 mode-name) 1333 mode-name)
1332 1334
1333 (defun bs--get-file-name (start-buffer all-buffers) 1335 (defun bs--get-file-name (start-buffer all-buffers)
1334 "Return string for column 'File' in Buffer Selection Menu. 1336 "Return string for column 'File' in Buffer Selection Menu.
1335 This is the variable `buffer-file-name' of current buffer. 1337 This is the variable `buffer-file-name' of current buffer.
1336 If current mode is `dired-mode' or `shell-mode' it returns the 1338 If current mode is `dired-mode' or `shell-mode' it returns the
1337 default directory. 1339 default directory.
1338 START-BUFFER is the buffer where we started buffer selection. 1340 START-BUFFER is the buffer where we started buffer selection.
1339 ALL-BUFFERS is the list of buffer appearing in Buffer Selection Menu." 1341 ALL-BUFFERS is the list of buffers appearing in Buffer Selection Menu."
1340 (propertize (if (member major-mode '(shell-mode dired-mode)) 1342 (propertize (if (member major-mode '(shell-mode dired-mode))
1341 default-directory 1343 default-directory
1342 (or buffer-file-name "")) 1344 (or buffer-file-name ""))
1343 'mouse-face 'highlight 1345 'mouse-face 'highlight
1344 'help-echo "mouse-2: select this buffer, mouse-3: select in other frame")) 1346 'help-echo "mouse-2: select this buffer, mouse-3: select in other frame"))
1370 (setq columns (cdr columns)))) 1372 (setq columns (cdr columns))))
1371 (insert string) 1373 (insert string)
1372 string)) 1374 string))
1373 1375
1374 (defun bs--format-aux (string align len) 1376 (defun bs--format-aux (string align len)
1375 "Generate a string with STRING with alignment ALIGN and length LEN. 1377 "Pad STRING to length LEN with alignment ALIGN.
1376 ALIGN is one of the symbols `left', `middle', or `right'." 1378 ALIGN is one of the symbols `left', `middle', or `right'."
1377 (let* ((width (length string)) 1379 (let* ((width (length string))
1378 (len (max len width))) 1380 (len (max len width)))
1379 (format (format "%%%s%ds" (if (eq align 'right) "" "-") len) 1381 (format (format "%%%s%ds" (if (eq align 'right) "" "-") len)
1380 (if (eq align 'middle) 1382 (if (eq align 'middle)
1381 (concat (make-string (/ (- len width) 2) ?\s) string) 1383 (concat (make-string (/ (- len width) 2) ?\s) string)
1382 string)))) 1384 string))))
1383 1385
1384 (defun bs--show-header () 1386 (defun bs--show-header ()
1385 "Insert header for Buffer Selection Menu in current buffer." 1387 "Insert header for Buffer Selection Menu in current buffer."
1386 (mapcar '(lambda (string) 1388 (dolist (string (bs--create-header))
1387 (insert string "\n")) 1389 (insert string "\n")))
1388 (bs--create-header)))
1389 1390
1390 (defun bs--get-name-length () 1391 (defun bs--get-name-length ()
1391 "Return value of `bs--name-entry-length'." 1392 "Return value of `bs--name-entry-length'."
1392 bs--name-entry-length) 1393 bs--name-entry-length)
1393 1394
1469 ;;;###autoload 1470 ;;;###autoload
1470 (defun bs-show (arg) 1471 (defun bs-show (arg)
1471 "Make a menu of buffers so you can manipulate buffers or the buffer list. 1472 "Make a menu of buffers so you can manipulate buffers or the buffer list.
1472 \\<bs-mode-map> 1473 \\<bs-mode-map>
1473 There are many key commands similar to `Buffer-menu-mode' for 1474 There are many key commands similar to `Buffer-menu-mode' for
1474 manipulating buffer list and buffers itself. 1475 manipulating the buffer list and the buffers themselves.
1475 User can move with [up] or [down], select a buffer 1476 User can move with [up] or [down], select a buffer
1476 by \\[bs-select] or [SPC]\n 1477 by \\[bs-select] or [SPC]\n
1477 Type \\[bs-kill] to leave Buffer Selection Menu without a selection. 1478 Type \\[bs-kill] to leave Buffer Selection Menu without a selection.
1478 Type \\[bs-help] after invocation to get help on commands available. 1479 Type \\[bs-help] after invocation to get help on commands available.
1479 With prefix argument ARG show a different buffer list. Function 1480 With prefix argument ARG show a different buffer list. Function