Add ibuffer
authorJoerg Jaspert <joerg@debian.org>
Sat, 24 May 2014 22:01:46 +0000 (00:01 +0200)
committerJoerg Jaspert <joerg@debian.org>
Sat, 24 May 2014 22:01:46 +0000 (00:01 +0200)
.emacs.d/config/emacs.org

index 3e6e6b9..d8aa478 100644 (file)
@@ -1670,7 +1670,294 @@ Instead of default /html-mode/ I use /html-helper-mode/.
 [2014-05-21 Wed 23:54]
 #+BEGIN_SRC emacs-lisp :tangle yes
 (use-package ibuffer
-  :bind ("C-x C-b" . ibuffer))
+  :defer t
+  :bind (("C-h h" . ibuffer)
+         ("C-x C-b" . ibuffer)
+         ("<XF86WebCam>" . ibuffer)
+         )
+  :commands ibuffer
+  :init
+  (progn
+    (defvar my-ibufffer-separator " • ")
+    (setq ibuffer-filter-group-name-face 'variable-pitch
+          ibuffer-use-header-line t
+          ibuffer-old-time 12)
+    (use-package ibuffer-vc
+      :ensure t
+      :commands
+      (ibuffer-vc-set-filter-groups-by-vc-root
+       ibuffer-vc-generate-filter-groups-by-vc-root))
+    (use-package ibuffer-tramp
+      :ensure t
+      :commands (ibuffer-tramp-generate-filter-groups-by-tramp-connection
+                 ibuffer-tramp-set-filter-groups-by-tramp-connection))
+    ;; Switching to ibuffer puts the cursor on the most recent buffer
+    (defadvice ibuffer (around ibuffer-point-to-most-recent activate)
+      "Open ibuffer with cursor pointed to most recent buffer name"
+      (let ((recent-buffer-name (buffer-name)))
+        ad-do-it
+        (ibuffer-update nil t)
+        (unless (string= recent-buffer-name "*Ibuffer*")
+          (ibuffer-jump-to-buffer recent-buffer-name)))))
+  :config
+  (progn
+    (unbind-key "M-o" ibuffer-mode-map)
+    (bind-key "s" 'isearch-forward-regexp ibuffer-mode-map)
+    (bind-key "." 'ibuffer-invert-sorting ibuffer-mode-map)
+
+    (defun ibuffer-magit-status ()
+      (interactive)
+      (--when-let (get-buffer "*Ibuffer*")
+        (with-current-buffer it
+          (let* ((selected-buffer (ibuffer-current-buffer))
+                 (buffer-path (with-current-buffer
+                                  selected-buffer
+                                (or (buffer-file-name)
+                                   list-buffers-directory
+                                   default-directory)))
+                 (default-directory
+                   (if (file-regular-p buffer-path)
+                       (file-name-directory buffer-path)
+                     buffer-path)))
+            (magit-status default-directory)))))
+    (bind-key "i" 'ibuffer-magit-status ibuffer-mode-map)
+    (bind-key "G" 'ibuffer-magit-status ibuffer-mode-map)
+
+    (setq ibuffer-directory-abbrev-alist
+          (-uniq
+           (-flatten
+            (--map
+             (list
+              (cons  (f-slash (f-expand (cdr it))) (concat (car it) my-ibufffer-separator))
+              (cons  (f-slash (f-canonical (cdr it))) (concat (car it) my-ibufffer-separator)))
+
+             '(
+               ("dak" . "/develop/dak/")
+               ("org" . "~/org/")
+               ("config" . "~/.emacs.d/config/")
+               ("tmp" . "~/tmp/")
+               ("systmp" . "/tmp/")
+               ("puppet" . "~/git/puppet")
+               ("git" . "~/git/")
+               )))))
+
+    (use-package ibuffer-git
+      :ensure t)
+    (use-package ibuffer-vc
+      :ensure t)
+
+    (define-ibuffer-column size-h
+      (:name "Size" :inline t)
+      (cond
+       ((> (buffer-size) 1000)
+        (format "%7.1fk" (/ (buffer-size) 1000.0)))
+       ((> (buffer-size) 1000000)
+        (format "%7.1fM" (/ (buffer-size) 1000000.0)))
+       (t
+        (format "%8d" (buffer-size)))))
+
+    (require 'ibuf-ext)
+    (define-ibuffer-filter filename2
+        "Toggle current view to buffers with filename matching QUALIFIER."
+      (:description "filename2"
+                    :reader (read-from-minibuffer "Filter by filename (regexp): "))
+      ;; (ibuffer-awhen (buffer-local-value 'buffer-file-name buf)
+      (ibuffer-awhen (with-current-buffer buf
+                       (or buffer-file-name
+                          default-directory))
+        (string-match qualifier it)))
+
+    (defvar ibuffer-magit-filter-groups nil)
+    (defun ibuffer-magit-define-filter-groups ()
+      (when (and (not ibuffer-magit-filter-groups)
+               (boundp 'magit-repo-dirs))
+        (setq ibuffer-magit-filter-groups
+              (--map (list
+                      (concat "git:: "
+                              (file-name-nondirectory (directory-file-name it)))
+                      `(filename2 . ,it))
+                     (mapcar 'cdr (magit-list-repos magit-repo-dirs))))))
+
+    (defun ibuffer-set-filter-groups-by-root  ()
+      (interactive)
+      ;; (ibuffer-projectile-define-filter-groups)
+      ;; (ibuffer-magit-define-filter-groups)
+      (setq ibuffer-filter-groups
+            (-concat
+             ;; ibuffer-projectile-filter-groups
+             ibuffer-magit-filter-groups
+
+             '(("MORE"
+                (or (mode . magit-log-edit-mode)
+                   (name . "^\\*\\(traad-server\\|httpd\\|epc con.*\\|tramp/.*\\|Completions\\)\\*$")
+                   (name . "^\\*Pymacs\\*$")
+                   (name . "^\\*helm.*\\*")
+                   (name . "^\\*Compile-log\\*$")
+                   (name . "^\\*Ido Completions\\*$")
+                   (name . "^\\*magit-\\(process\\)\\*$")
+                   (name . "^ "))))
+             '(("EMACS"
+                (or
+                 (name . "^\\*scratch")
+                 (name . "^\\*Messages")
+                 (name . "^\\*Help")
+                 )))
+             (ibuffer-vc-generate-filter-groups-by-vc-root)
+             (ibuffer-tramp-generate-filter-groups-by-tramp-connection))))
+
+    (defun toggle-ibuffer-filter-groups ()
+      "DOCSTRING"
+      (interactive)
+      (let ((ibuf (get-buffer "*Ibuffer*")))
+        (when ibuf
+          (with-current-buffer ibuf
+            (let ((selected-buffer (ibuffer-current-buffer)))
+              (if (not ibuffer-filter-groups)
+                  (ibuffer-set-filter-groups-by-root)
+                (setq ibuffer-filter-groups nil))
+              (pop-to-buffer ibuf)
+              (ibuffer-update nil t)
+              (ibuffer-jump-to-buffer (buffer-name selected-buffer )))))))
+
+    (bind-key "h" 'toggle-ibuffer-filter-groups ibuffer-mode-map)
+
+    (setq ibuffer-default-sorting-mode 'recency
+          ibuffer-eliding-string "…"
+          ibuffer-compile-formats t
+          ibuffer-git-column-length 6
+          ibuffer-show-empty-filter-groups nil
+          ibuffer-default-directory "~/"
+          )
+    (setq ibuffer-formats '((mark vc-status-mini
+                                  " "
+                                  (git-status 8 8 :left)
+                                  " "
+                                  read-only modified
+                                  " "
+                                  (name 18 18 :left :elide)
+                                  " "
+                                  (size-h 9 -1 :right)
+                                  " "
+                                  (mode 16 16 :left :elide)
+                                  " " filename-and-process)
+                            (mark " "
+                                  (git-status 8 8 :left)
+                                  " "
+                                  (name 16 -1)
+                                  " " filename)
+                            ))
+
+     (setq ibuffer-saved-filter-groups
+           (quote (("flat")
+                   ("default"
+                    ("dired"  (mode . dired-mode))
+                    ("perl"   (mode . cperl-mode))
+                    ("puppet" (or
+                               (mode . puppet-mode)
+                               (mode . yaml-mode)))
+                    ("ruby"   (mode . ruby-mode))
+                    ("emacs" (or
+                              (name . "^\\*scratch\\*$")
+                              (name . "^\\*Compile-log\\*$")
+                              (name . "^\\*Completions\\*$")
+                              (name . "^\\*Messages\\*$")
+                              (name . "^\\*Backtrace\\*$")
+                              (name . "^\\*Packages*\\*$")
+                              (name . "^\\*Help*\\*$")
+                              ))
+                    ("gnus"  (or
+                              (mode . message-mode)
+                              (mode . bbdb-mode)
+                              (mode . mail-mode)
+                              (mode . gnus-group-mode)
+                              (mode . gnus-summary-mode)
+                              (mode . gnus-article-mode)
+                              (name . "^\\.bbdb$")
+                              (name . "^\\.newsrc-dribble")))
+                    ("org"   (or
+                              (filename . ".*/org/.*")
+                              (mode . org-agenda-mode)
+                              (name . "^diary$")))
+                    ("other" (or
+                              (mode . magit-log-edit-mode)
+                              (name . "^\\*magit-\\(process\\|commit\\)\\*$"))))
+                   ("categorized"
+              ;; -------------------------------------------------
+              ;; programming languages #1
+                    ("code" (or
+                             (mode . emacs-lisp-mode)
+                             (mode . python-mode)
+                             (mode . ruby-mode)
+                             (mode . coffee-mode)
+                             (mode . js-mode)
+                             (mode . js2-mode)
+                             (mode . actionscript-mode)
+                             (mode . java-mode)
+                             (mode . sh-mode)
+                             (mode . haskell-mode)
+                             (mode . html-mode)
+                             (mode . web-mode)
+                             (mode . haml-mode)
+                             (mode . nxml-mode)
+                             (mode . css-mode)))
+                    ;; -------------------------------------------------
+                    ;; configuration/data files
+                    ("conf" (or
+                             (mode . json-mode)
+                             (mode . yaml-mode)
+                             (mode . conf-mode)))
+                    ;; -------------------------------------------------
+                    ;; text/notetaking/org
+                    ("org agenda"  (mode . org-agenda-mode))
+                    ("org" (or
+                            (mode . org-mode)
+                            (name . "^\\*Calendar\\*$")
+                            (name . "^diary$")))
+                    ("text misc" (or
+                                  (mode . text-mode)
+                                  (mode . rst-mode)
+                                  (mode . markdown-mode)))
+                    ;; -------------------------------------------------
+                    ;; media
+                    ("media" (or
+                              (mode . image-mode)))
+                    ;; -------------------------------------------------
+                    ;; misc
+                    ("w3m" (mode . w3m-mode))
+                    ("scm" (or
+                            (mode . magit-status-mode)
+                            (mode . magit-log-mode)
+                            (mode . vc-annotate-mode)))
+                    ("dired" (mode . dired-mode))
+                    ("help" (or
+                             (mode . Info-mode)
+                             (mode . help-mode)
+                             (mode . Man-mode)
+                             (name . "^\\*Personal Keybindings\\*$")))
+                    ;; -------------------------------------------------
+                    ;; *buffer* buffers
+                    ("MORE" (or (mode . magit-log-edit-mode)
+                                (name . "^\\*\\(traad-server\\|httpd\\|epc con.*\\|tramp/.*\\|Completions\\)\\*$")
+                                (name . "^\\*Pymacs\\*$")
+                                (name . "^\\*Compile-log\\*$")
+                                (name . "^\\*Completions\\*$")
+                                (name . "^\\*magit-\\(process\\|commit\\)\\*$")
+                                (name . "^ ")))
+                    ("*buffer*" (name . "\\*.*\\*"))))))
+
+    (add-hook 'ibuffer-mode-hook
+              (lambda ()
+                (ibuffer-auto-mode 1)
+                (ibuffer-switch-to-saved-filter-groups "default")))
+
+  ;; Unless you turn this variable on you will be prompted every time
+  ;; you want to delete a buffer, even unmodified ones, which is way
+  ;; too cautious for most people. You’ll still be prompted for
+  ;; confirmation when deleting modified buffers after the option has
+  ;; been turned off.
+  (setq ibuffer-expert t)
+
+)
 #+END_SRC
 ** icicles
 [[http://article.gmane.org/gmane.emacs.orgmode/4574/match%3Dicicles]["In case you never heard of it, Icicles is to ‘TAB’ completion what