comparison lisp/ibuf-ext.el @ 94985:78ec9a87d0e5

(ibuffer-interactive-filter-by-mode) (ibuffer-set-filter-groups-by-mode, ibuffer-list-buffer-modes) (define-ibuffer-filter mode, define-ibuffer-filter used-mode) (define-ibuffer-sorter major-mode, ibuffer-mark-unsaved-buffers) (ibuffer-mark-read-only-buffers) (ibuffer-mark-dired-buffers): Use `buffer-local-value'.
author John Paul Wallington <jpw@pobox.com>
date Thu, 15 May 2008 01:14:41 +0000
parents 4584a4064fe3
children 987e540891e7
comparison
equal deleted inserted replaced
94984:b8d24d4a4bdc 94985:78ec9a87d0e5
258 (goto-char event-or-point)) 258 (goto-char event-or-point))
259 (let ((buf (ibuffer-current-buffer))) 259 (let ((buf (ibuffer-current-buffer)))
260 (if (assq 'mode ibuffer-filtering-qualifiers) 260 (if (assq 'mode ibuffer-filtering-qualifiers)
261 (setq ibuffer-filtering-qualifiers 261 (setq ibuffer-filtering-qualifiers
262 (ibuffer-delete-alist 'mode ibuffer-filtering-qualifiers)) 262 (ibuffer-delete-alist 'mode ibuffer-filtering-qualifiers))
263 (ibuffer-push-filter (cons 'mode 263 (ibuffer-push-filter (cons 'mode (buffer-local-value 'major-mode buf)))))
264 (with-current-buffer buf
265 major-mode)))))
266 (ibuffer-update nil t)) 264 (ibuffer-update nil t))
267 265
268 ;;;###autoload 266 ;;;###autoload
269 (defun ibuffer-mouse-toggle-filter-group (event) 267 (defun ibuffer-mouse-toggle-filter-group (event)
270 "Toggle the display status of the filter group chosen with the mouse." 268 "Toggle the display status of the filter group chosen with the mouse."
560 (mapcar (lambda (mode) 558 (mapcar (lambda (mode)
561 (cons (format "%s" mode) `((mode . ,mode)))) 559 (cons (format "%s" mode) `((mode . ,mode))))
562 (let ((modes 560 (let ((modes
563 (ibuffer-remove-duplicates 561 (ibuffer-remove-duplicates
564 (mapcar (lambda (buf) 562 (mapcar (lambda (buf)
565 (with-current-buffer buf major-mode)) 563 (buffer-local-value 'major-mode buf))
566 (buffer-list))))) 564 (buffer-list)))))
567 (if ibuffer-view-ibuffer 565 (if ibuffer-view-ibuffer
568 modes 566 modes
569 (delq 'ibuffer-mode modes))))) 567 (delq 'ibuffer-mode modes)))))
570 (ibuffer-update nil t)) 568 (ibuffer-update nil t))
964 The list returned will be of the form (\"MODE-NAME\" . MODE-SYMBOL)." 962 The list returned will be of the form (\"MODE-NAME\" . MODE-SYMBOL)."
965 (let ((bufs (buffer-list)) 963 (let ((bufs (buffer-list))
966 (modes) 964 (modes)
967 (this-mode)) 965 (this-mode))
968 (while bufs 966 (while bufs
969 (setq this-mode 967 (setq this-mode (buffer-local-value 'major-mode (car bufs))
970 (with-current-buffer
971 (car bufs)
972 major-mode)
973 bufs (cdr bufs)) 968 bufs (cdr bufs))
974 (add-to-list 969 (add-to-list
975 'modes 970 'modes
976 `(,(symbol-name this-mode) . 971 `(,(symbol-name this-mode) .
977 ,this-mode))) 972 ,this-mode)))
991 (string-match "-mode$" 986 (string-match "-mode$"
992 (symbol-name e))) 987 (symbol-name e)))
993 t 988 t
994 (let ((buf (ibuffer-current-buffer))) 989 (let ((buf (ibuffer-current-buffer)))
995 (if (and buf (buffer-live-p buf)) 990 (if (and buf (buffer-live-p buf))
996 (with-current-buffer buf 991 (symbol-name (buffer-local-value 'major-mode buf))
997 (symbol-name major-mode))
998 ""))))) 992 "")))))
999 (eq qualifier (with-current-buffer buf major-mode))) 993 (eq qualifier (buffer-local-value 'major-mode buf)))
1000 994
1001 ;;;###autoload (autoload 'ibuffer-filter-by-used-mode "ibuf-ext") 995 ;;;###autoload (autoload 'ibuffer-filter-by-used-mode "ibuf-ext")
1002 (define-ibuffer-filter used-mode 996 (define-ibuffer-filter used-mode
1003 "Toggle current view to buffers with major mode QUALIFIER. 997 "Toggle current view to buffers with major mode QUALIFIER.
1004 Called interactively, this function allows selection of modes 998 Called interactively, this function allows selection of modes
1010 (ibuffer-list-buffer-modes) 1004 (ibuffer-list-buffer-modes)
1011 nil 1005 nil
1012 t 1006 t
1013 (let ((buf (ibuffer-current-buffer))) 1007 (let ((buf (ibuffer-current-buffer)))
1014 (if (and buf (buffer-live-p buf)) 1008 (if (and buf (buffer-live-p buf))
1015 (with-current-buffer buf 1009 (symbol-name (buffer-local-value
1016 (symbol-name major-mode)) 1010 'major-mode buf))
1017 ""))))) 1011 "")))))
1018 (eq qualifier (with-current-buffer buf major-mode))) 1012 (eq qualifier (buffer-local-value 'major-mode buf)))
1019 1013
1020 ;;;###autoload (autoload 'ibuffer-filter-by-name "ibuf-ext") 1014 ;;;###autoload (autoload 'ibuffer-filter-by-name "ibuf-ext")
1021 (define-ibuffer-filter name 1015 (define-ibuffer-filter name
1022 "Toggle current view to buffers with name matching QUALIFIER." 1016 "Toggle current view to buffers with name matching QUALIFIER."
1023 (:description "buffer name" 1017 (:description "buffer name"
1104 (define-ibuffer-sorter major-mode 1098 (define-ibuffer-sorter major-mode
1105 "Sort the buffers by major modes. 1099 "Sort the buffers by major modes.
1106 Ordering is lexicographic." 1100 Ordering is lexicographic."
1107 (:description "major mode") 1101 (:description "major mode")
1108 (string-lessp (downcase 1102 (string-lessp (downcase
1109 (symbol-name (with-current-buffer 1103 (symbol-name (buffer-local-value 'major-mode (car a))))
1110 (car a)
1111 major-mode)))
1112 (downcase 1104 (downcase
1113 (symbol-name (with-current-buffer 1105 (symbol-name (buffer-local-value 'major-mode (car b))))))
1114 (car b)
1115 major-mode)))))
1116 1106
1117 ;;;###autoload (autoload 'ibuffer-do-sort-by-mode-name "ibuf-ext") 1107 ;;;###autoload (autoload 'ibuffer-do-sort-by-mode-name "ibuf-ext")
1118 (define-ibuffer-sorter mode-name 1108 (define-ibuffer-sorter mode-name
1119 "Sort the buffers by their mode name. 1109 "Sort the buffers by their mode name.
1120 Ordering is lexicographic." 1110 Ordering is lexicographic."
1121 (:description "major mode name") 1111 (:description "major mode name")
1122 (string-lessp (downcase 1112 (string-lessp (downcase
1123 (with-current-buffer 1113 (with-current-buffer
1124 (car a) 1114 (car a)
1125 (format-mode-line mode-name))) 1115 (format-mode-line mode-name)))
1126 (downcase 1116 (downcase
1127 (with-current-buffer 1117 (with-current-buffer
1128 (car b) 1118 (car b)
1129 (format-mode-line mode-name))))) 1119 (format-mode-line mode-name)))))
1130 1120
1437 ;;;###autoload 1427 ;;;###autoload
1438 (defun ibuffer-mark-unsaved-buffers () 1428 (defun ibuffer-mark-unsaved-buffers ()
1439 "Mark all modified buffers that have an associated file." 1429 "Mark all modified buffers that have an associated file."
1440 (interactive) 1430 (interactive)
1441 (ibuffer-mark-on-buffer 1431 (ibuffer-mark-on-buffer
1442 #'(lambda (buf) (and (with-current-buffer buf buffer-file-name) 1432 #'(lambda (buf) (and (buffer-local-value 'buffer-file-name buf)
1443 (buffer-modified-p buf))))) 1433 (buffer-modified-p buf)))))
1444 1434
1445 ;;;###autoload 1435 ;;;###autoload
1446 (defun ibuffer-mark-dissociated-buffers () 1436 (defun ibuffer-mark-dissociated-buffers ()
1447 "Mark all buffers whose associated file does not exist." 1437 "Mark all buffers whose associated file does not exist."
1506 ;;;###autoload 1496 ;;;###autoload
1507 (defun ibuffer-mark-read-only-buffers () 1497 (defun ibuffer-mark-read-only-buffers ()
1508 "Mark all read-only buffers." 1498 "Mark all read-only buffers."
1509 (interactive) 1499 (interactive)
1510 (ibuffer-mark-on-buffer 1500 (ibuffer-mark-on-buffer
1511 #'(lambda (buf) 1501 #'(lambda (buf) (buffer-local-value 'buffer-read-only buf))))
1512 (with-current-buffer buf
1513 buffer-read-only))))
1514 1502
1515 ;;;###autoload 1503 ;;;###autoload
1516 (defun ibuffer-mark-dired-buffers () 1504 (defun ibuffer-mark-dired-buffers ()
1517 "Mark all `dired' buffers." 1505 "Mark all `dired' buffers."
1518 (interactive) 1506 (interactive)
1519 (ibuffer-mark-on-buffer 1507 (ibuffer-mark-on-buffer
1520 #'(lambda (buf) 1508 #'(lambda (buf) (eq (buffer-local-value 'major-mode buf) 'dired-mode))))
1521 (with-current-buffer buf
1522 (eq major-mode 'dired-mode)))))
1523 1509
1524 ;;;###autoload 1510 ;;;###autoload
1525 (defun ibuffer-do-occur (regexp &optional nlines) 1511 (defun ibuffer-do-occur (regexp &optional nlines)
1526 "View lines which match REGEXP in all marked buffers. 1512 "View lines which match REGEXP in all marked buffers.
1527 Optional argument NLINES says how many lines of context to display: it 1513 Optional argument NLINES says how many lines of context to display: it