Skip to content

Instantly share code, notes, and snippets.

@rmm5t
Created October 22, 2009 12:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rmm5t/215930 to your computer and use it in GitHub Desktop.
Save rmm5t/215930 to your computer and use it in GitHub Desktop.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Hippie expand. Groovy vans with tie-dyes.
;; Change the default hippie-expand order and add yasnippet to the front.
(setq hippie-expand-try-functions-list
'(yas/hippie-try-expand
try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name
try-complete-lisp-symbol))
;; Helps when debugging which try-function expanded
(setq hippie-expand-verbose t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Smart Tab
(defvar smart-tab-using-hippie-expand t
"turn this on if you want to use hippie-expand completion.")
(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")
(labels ((smart-tab-must-expand (&optional prefix)
(unless (or (consp prefix)
mark-active)
(looking-at "\\_>"))))
(cond ((minibufferp)
(minibuffer-complete))
((smart-tab-must-expand prefix)
(if smart-tab-using-hippie-expand
(hippie-expand prefix)
(dabbrev-expand prefix)))
((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)))
;; Bind tab everywhere
(global-set-key (kbd "TAB") 'smart-tab)
;; Enables tab completion in the `eval-expression` minibuffer
(define-key read-expression-map [(tab)] 'hippie-expand)
(define-key read-expression-map [(shift tab)] 'unexpand)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; YASnippet
;; Replace yasnippets's TAB
(add-hook 'yas/minor-mode-hook
(lambda () (define-key yas/minor-mode-map
(kbd "TAB") 'smart-tab))) ; was yas/expand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment