forked from fgeller/emacs-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-ido.el
85 lines (72 loc) · 3.99 KB
/
init-ido.el
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
82
83
84
85
;; Use C-f during file selection to switch to regular find-file
(ido-mode t) ; use 'buffer rather than t to use only buffer switching
(ido-ubiquitous-mode t)
(ido-everywhere t)
(setq ido-enable-flex-matching t)
(setq ido-use-filename-at-point nil)
(setq ido-auto-merge-work-directories-length 0)
(setq ido-use-virtual-buffers t)
;; Allow the same buffer to be open in different frames
(setq ido-default-buffer-method 'selected-window)
;; Display ido results vertically, rather than horizontally
(setq ido-decorations (quote ("\n-> " "" "\n " "\n ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]" " [Confirm]")))
(defun ido-disable-line-trucation () (set (make-local-variable 'truncate-lines) nil))
(add-hook 'ido-minibuffer-setup-hook 'ido-disable-line-trucation)
;; https://gist.github.com/493269
(defun split-window-vertically-and-switch ()
(interactive)
(split-window-vertically)
(other-window 1))
(defun split-window-horizontally-and-switch ()
(interactive)
(split-window-horizontally)
(other-window 1))
(defun ido-invoke-in-other-window ()
"signals ido mode to switch to (or create) another window after exiting"
(interactive)
(setq ido-exit-minibuffer-target-window 'other)
(ido-exit-minibuffer))
(defun ido-invoke-in-horizontal-split ()
"signals ido mode to split horizontally and switch after exiting"
(interactive)
(setq ido-exit-minibuffer-target-window 'horizontal)
(ido-exit-minibuffer))
(defun ido-invoke-in-vertical-split ()
"signals ido mode to split vertically and switch after exiting"
(interactive)
(setq ido-exit-minibuffer-target-window 'vertical)
(ido-exit-minibuffer))
(defun ido-invoke-in-new-frame ()
"signals ido mode to create a new frame after exiting"
(interactive)
(setq ido-exit-minibuffer-target-window 'frame)
(ido-exit-minibuffer))
(defadvice ido-read-internal (around ido-read-internal-with-minibuffer-other-window activate)
(let* (ido-exit-minibuffer-target-window
(this-buffer (current-buffer))
(result ad-do-it))
(cond
((equal ido-exit-minibuffer-target-window 'other)
(if (= 1 (count-windows))
(split-window-horizontally-and-switch)
(other-window 1)))
((equal ido-exit-minibuffer-target-window 'horizontal)
(split-window-horizontally-and-switch))
((equal ido-exit-minibuffer-target-window 'vertical)
(split-window-vertically-and-switch))
((equal ido-exit-minibuffer-target-window 'frame)
(make-frame)))
(switch-to-buffer this-buffer) ;; why? Some ido commands, such as textmate.el's textmate-goto-symbol don't switch the current buffer
result))
(defadvice ido-init-completion-maps (after ido-init-completion-maps-with-other-window-keys activate)
(mapcar (lambda (map)
(define-key map (kbd "C-o") 'ido-invoke-in-other-window)
(define-key map (kbd "C-2") 'ido-invoke-in-vertical-split)
(define-key map (kbd "C-3") 'ido-invoke-in-horizontal-split)
(define-key map (kbd "C-4") 'ido-invoke-in-other-window)
(define-key map (kbd "C-5") 'ido-invoke-in-new-frame))
(list ido-buffer-completion-map
ido-common-completion-map
ido-file-completion-map
ido-file-dir-completion-map)))
(provide 'init-ido)