forked from EnigmaCurry/emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ryan-tab-complete.el
92 lines (82 loc) · 3.07 KB
/
ryan-tab-complete.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
86
87
88
89
90
;; This is my attempt to make the holy grail of tab completion possible
;; -Ryan
(require 'yasnippet)
(yas/initialize)
(yas/load-directory "~/.emacs.d/yasnippet/snippets")
;;;
;; Smart Tab
;; Taken from http://www.emacswiki.org/cgi-bin/wiki/TabCompletion
(global-set-key [(tab)] 'smart-tab)
(defvar smart-tab-completion-functions
'((emacs-lisp-mode lisp-complete-symbol)
(lisp-mode slime-complete-symbol)
(python-mode rope-code-assist)
(text-mode dabbrev-completion))
"List of major modes in which to use a mode specific completion
function.")
(defun get-completion-function()
"Get a completion function according to current major mode."
(let ((completion-function
(second (assq major-mode smart-tab-completion-functions))))
(if (null completion-function)
'dabbrev-completion
completion-function)))
(defun smart-tab (prefix)
"Needs `transient-mark-mode' to be on. This smart tab is
minibuffer compliant: it acts as usual in the minibuffer.
In all other buffers: if PREFIX is \\[universal-argument], calls
`smart-indent'. Else if point is at the end of a symbol,
expands it. Else calls `smart-indent'."
(interactive "P")
(if (minibufferp)
(minibuffer-complete)
(if (smart-tab-must-expand prefix)
(let ((dabbrev-case-fold-search t)
(dabbrev-case-replace nil))
(funcall (get-completion-function))))
(smart-indent)))
(defun smart-tab-must-expand (&optional prefix)
"If PREFIX is \\[universal-argument], answers no.
Otherwise, analyses point position and answers."
(unless (or (consp prefix)
mark-active)
(looking-at "\\_>")))
(defun smart-indent ()
"Indents region if mark is active, or current line otherwise."
(interactive)
(if mark-active
(indent-region (region-beginning)
(region-end))
(indent-for-tab-command)))
;;;
;; (defvar smart-tab-using-hippie-expand nil
;; "turn this on if you want to use hippie-expand completion.")
;; (global-set-key [(tab)] 'smart-tab)
;; (defun smart-tab (prefix)
;; "Needs `transient-mark-mode' to be on. This smart tab is
;; minibuffer compliant: it acts as usual in the minibuffer.
;; In all other buffers: if PREFIX is \\[universal-argument], calls
;; `smart-indent'. Else if point is at the end of a symbol,
;; expands it. Else calls `smart-indent'."
;; (interactive "P")
;; (if (minibufferp)
;; (minibuffer-complete)
;; (if (smart-tab-must-expand prefix)
;; (if smart-tab-using-hippie-expand
;; (hippie-expand nil)
;; (dabbrev-expand nil))
;; (smart-indent))))
;; (defun smart-indent ()
;; "Indents region if mark is active, or current line otherwise."
;; (interactive)
;; (if mark-active
;; (indent-region (region-beginning)
;; (region-end))
;; (indent-for-tab-command)))
;; (defun smart-tab-must-expand (&optional prefix)
;; "If PREFIX is \\[universal-argument], answers no.
;; Otherwise, analyses point position and answers."
;; (unless (or (consp prefix)
;; mark-active)
;; (looking-at "\\_>")))
;; ;;; End smart tab