summaryrefslogtreecommitdiff
path: root/ibuffer.el
blob: 49e6a292fef17dbb4240560b7c6f2e4d6946ebae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;;; -*- lexical-binding: t; -*-

(require 'ibuffer)
(require 'ibuf-ext)

(setq ibuffer-expert t
      ibuffer-display-summary nil)

(setq ibuffer-show-empty-filter-groups nil)

;;; Bindings related to buffers

;;;; Quickly switch to the last buffer.

;;;###autoload
(defun durand-switch-to-last-buffer (&optional arg)
  "Switch to the last buffer.

The last buffer is given by `other-buffer'.

If ARG is non-nil, then display the last buffer in a new window."
  (interactive "P")
  (cond
   (arg (switch-to-buffer-other-window nil))
   ((switch-to-buffer nil))))

;;;###autoload
(defun durand-switch-to-last-buffer-other-window ()
  "Switch to the last buffer in a new window."
  (interactive)
  (switch-to-buffer-other-window nil))

(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 ?\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)
(define-key global-map (vector ?\s-N) #'durand-switch-to-last-buffer-other-window)

(define-key ibuffer-mode-map (vector ?d) #'ibuffer-do-delete)
(define-key ibuffer-mode-map (vector ?D) #'ibuffer-mark-for-delete)

;;; filter for bongo

;;;###autoload
(define-ibuffer-filter durand-bongo
    "Group bongo buffers together."
  (:description "Bongo buffers together"
                :reader (read-string "no effect: "))
  (cond
   ((not (boundp 'durand-bongo-music-dir))
    (load-config "bongo.el")))
  (with-current-buffer buf
    (cond
     ((derived-mode-p 'dired-mode)
      (let ((bongo-dirs durand-bongo-music-dir)
            found)
        (while (and (not found)
                    (consp bongo-dirs))
          (cond
           ((file-in-directory-p default-directory (car bongo-dirs))
            (setq found t))
           (t (setq bongo-dirs (cdr bongo-dirs)))))
        found))
     ((derived-mode-p 'bongo-playlist-mode 'bongo-library-mode)))))

;;;###autoload
(defun durand-bongo-set-filter ()
  "Set my custom filters."
  (interactive)
  (setq ibuffer-filter-groups
        (cons (cons "Bongo" '((durand-bongo)))
              ibuffer-filter-groups))
  (let ((ibuf (get-buffer "*Ibuffer*")))
    (when ibuf
      (with-current-buffer ibuf
        ;; (pop-to-buffer ibuf)
        (ibuffer-update nil t)))))

(add-hook 'ibuffer-hook 'durand-bongo-set-filter 100)