diff options
Diffstat (limited to 'ibuffer.el')
-rw-r--r-- | ibuffer.el | 46 |
1 files changed, 45 insertions, 1 deletions
@@ -30,9 +30,53 @@ If ARG is non-nil, then display the last buffer in a new window." (interactive) (switch-to-buffer-other-window nil)) +;;;###autoload +(defun switch-to-buffer-same-mode (&optional arg) + "Switch to a buffer with the same major mode as the current + buffer. +If the optional ARG is non-nil, then produce an IBUFFER buffer + listing all buffers of the same mode as the current buffer." + (interactive "P") + (cond + ((null arg) + (let ((def (buffer-name + (car + (delete nil + (mapcar + (lambda (buf) + (and + (provided-mode-derived-p + (buffer-local-value 'major-mode buf) + (buffer-local-value 'major-mode (current-buffer))) + (not (= (aref (buffer-name buf) 0) 32)) + (not (eq buf (current-buffer))) + buf)) + (buffer-list))))))) + (switch-to-buffer + (read-buffer (format + "Switch to buffer with major mode %S:" + (buffer-local-value 'major-mode (current-buffer))) + def t + (lambda (name-or-cons) + (provided-mode-derived-p + (buffer-local-value + 'major-mode + (cond ((consp name-or-cons) + (car name-or-cons)) + ((get-buffer name-or-cons)))) + (buffer-local-value + 'major-mode + (current-buffer)))))))) + ((ibuffer + nil + (format "*Buffers for %S*" + (buffer-local-value 'major-mode (current-buffer))) + (list (cons 'used-mode + (buffer-local-value 'major-mode (current-buffer)))))))) + (define-key global-map (vector 24 2) #'ibuffer) (define-key global-map (vector ?\s-h) #'ibuffer) -(define-key global-map (vector ?\M-\s-b) #'ibuffer) +(define-key global-map (vector ?\M-\s-b) #'switch-to-buffer-same-mode) (define-key global-map (vector ?\s-b) #'switch-to-buffer) (define-key global-map (vector ?\s-B) #'switch-to-buffer-other-window) (define-key global-map (vector ?\s-n) #'durand-switch-to-last-buffer) |