 ;; Source: https://github.com/larstvei/dot-emacs
 (add-to-list 'ido-ignore-buffers "*Messages*")
 
+;; Be able to bury buffers from ido
+;; Source: http://endlessparentheses.com/Ido-Bury-Buffer.html
+(defun endless/ido-bury-buffer-at-head ()
+  "Bury the buffer at the head of `ido-matches'."
+  (interactive)
+  (let ((enable-recursive-minibuffers t)
+        (buf (ido-name (car ido-matches)))
+        (nextbuf (cadr ido-matches)))
+    (when (get-buffer buf)
+      ;; If next match names a buffer use the buffer object;
+      ;; buffer name may be changed by packages such as
+      ;; uniquify.
+      (when (and nextbuf (get-buffer nextbuf))
+        (setq nextbuf (get-buffer nextbuf)))
+      (bury-buffer buf)
+      (if (bufferp nextbuf)
+          (setq nextbuf (buffer-name nextbuf)))
+      (setq ido-default-item nextbuf
+            ido-text-init ido-text
+            ido-exit 'refresh)
+      (exit-minibuffer))))
+
+(defun ido-define-keys ()
+  ;; C-n/p  and up/down keys are more intuitive in vertical layout
+  (define-key ido-completion-map (kbd "C-n")    'ido-next-match)
+  (define-key ido-completion-map (kbd "<down>") 'ido-next-match)
+  (define-key ido-completion-map (kbd "C-p")    'ido-prev-match)
+  (define-key ido-completion-map (kbd "<up>")   'ido-prev-match)
+  (define-key ido-completion-map (kbd "C-b")    'endless/ido-bury-buffer-at-head))
+(add-hook 'ido-setup-hook 'ido-define-keys)
+
 
 (setq setup-ido-loaded t)
 (provide 'setup-ido)
+
+;; Default ido key map
+
+;; Basic map
+;; | C-a     | 'ido-toggle-ignore              |
+;; | C-c     | 'ido-toggle-case                |
+;; | C-e     | 'ido-edit-input                 |
+;; | Tab     | 'ido-complete                   |
+;; | Space   | 'ido-complete-space             |
+;; | C-j     | 'ido-select-text                |
+;; | C-m     | 'ido-exit-minibuffer            |
+;; | C-p     | 'ido-toggle-prefix (OVERRIDDEN) |
+;; | C-r     | 'ido-prev-match                 |
+;; | C-s     | 'ido-next-match                 |
+;; | C-t     | 'ido-toggle-regexp              |
+;; | C-z     | 'ido-undo-merge-work-directory  |
+;; | C-Space | 'ido-restrict-to-matches        |
+;; | M-Space | 'ido-take-first-match           |
+;; | C-@     | 'ido-restrict-to-matches        |
+;; | Right   | 'ido-next-match                 |
+;; | Left    | 'ido-prev-match                 |
+;; | ?       | 'ido-completion-help            |
+
+;; Magic commands.
+;; | C-b | 'ido-magic-backward-char (OVERRIDDEN) |
+;; | C-f | 'ido-magic-forward-char               |
+;; | C-d | 'ido-magic-delete-char                |
+
+;; File and directory map
+;; | C-x C-b                      | 'ido-enter-switch-buffer                 |
+;; | C-x C-f                      | 'ido-fallback-command                    |
+;; | C-x C-d                      | 'ido-enter-dired                         |
+;; | Down                         | 'ido-next-match-dir                      |
+;; | Up                           | 'ido-prev-match-dir                      |
+;; | M-Up                         | 'ido-prev-work-directory                 |
+;; | M-Down                       | 'ido-next-work-directory                 |
+;; | Backspace                    | 'ido-delete-backward-updir               |
+;; | Delete                       | 'ido-delete-backward-updir               |
+;; | [remap delete-backward-char] | 'ido-delete-backward-updir) ; B          |
+;; | [remap backward-kill-word]   | 'ido-delete-backward-word-updir)  ; M-DE |
+;; | C-Backspace                  | 'ido-up-directory                        |
+;; | C-l                          | 'ido-reread-directory                    |
+;; | M-d                          | 'ido-wide-find-dir-or-delete-dir         |
+;; | M-b                          | 'ido-push-dir                            |
+;; | M-v                          | 'ido-push-dir-first                      |
+;; | M-f                          | 'ido-wide-find-file-or-pop-dir           |
+;; | M-k                          | 'ido-forget-work-directory               |
+;; | M-m                          | 'ido-make-directory                      |
+;; | M-n                          | 'ido-next-work-directory                 |
+;; | M-o                          | 'ido-prev-work-file                      |
+;; | M-C-o                        | 'ido-next-work-file                      |
+;; | M-p                          | 'ido-prev-work-directory                 |
+;; | M-s                          | 'ido-merge-work-directories              |
+
+;; File only map
+;; | C-k | 'ido-delete-file-at-head    |
+;; | C-o | 'ido-copy-current-word      |
+;; | C-w | 'ido-copy-current-file-name |
+;; | M-l | 'ido-toggle-literal         |
+
+;; Buffer map
+;; | C-x C-f | 'ido-enter-find-file        |
+;; | C-x C-b | 'ido-fallback-command       |
+;; | C-k     | 'ido-kill-buffer-at-head    |
+;; | C-o     | 'ido-toggle-virtual-buffers |

;; Time-stamp: <2014-06-19 11:55:40 kmodi>

;; Interactively Do Things
;; Source: http://www.masteringemacs.org/articles/2010/10/10/introduction-to-ido-mode/
;; Source: https://github.com/magnars/.emacs.d/blob/master/setup-ido.el

(require 'ido)
(setq ido-enable-flex-matching t ;; enable fuzzy search
      ido-everywhere t
      ido-create-new-buffer 'always ;; create a new buffer if no buffer matches substring

      ;; so I tell Ido to emphasize those
      ido-use-filename-at-point 'guess ;; find file at point using ido
      ido-auto-merge-work-directories-length 0 ;; look into other directories if
      ;; the entered filename doesn't exist in current directory
      ;; ido-auto-merge-work-directories-length -1 ;; do NOT look into other directories if
      ;;                  ;; the entered filename doesn't exist in current directory
      )
