 
 (defun long-enough-p ()
   "Is this word long enough to expand?"
-  (> (- (point) (car (bounds-of-thing-at-point 'word))) 2))
+  (let ((old-point (point)))
+    (save-excursion (> (- old-point (point)) 2))))
+
 (defun override-p ()
   "Did we manually override the length limit?"
   (eq this-command last-command))
 
+(defvar smart-tab-always-indent nil)
+(setq-local smart-tab-always-indent nil)
+
 ;; Modified from http://emacswiki.org/emacs/TabCompletion
 (defun smart-tab ()
   "Smart tab does the following:
-    In the mini-buffer: expand the word.
+   In the mini-buffer: expand the word.
 
-    If mark is active: indent the region.
+   If mark is active: indent the region.
 
-    If we are at the end of the word or call twice: expand the word.
+   If we are at the end of the word or call twice: expand the word.
 
-    Otherwise: indent the current line."
+   Otherwise: indent the current line."
   (interactive)
   ;; Always expend in the buffer.
   (if (minibufferp)

(defun smart-beginning-of-line ()
  "Move point to first non-whitespace character or beginning-of-line.

Move point to the first non-whitespace character on this line.
If point was already at that position, move point to beginning of line."
  (interactive)
  (let ((oldpos (point)))
    (back-to-indentation)

                       (region-end))
      ;; Are we at the end of a word?
      (if (looking-at "\\_>")
          (progn
            (if smart-tab-always-indent
                (indent-for-tab-command) nil)
            (if (long-enough-p)
                (dabbrev-expand nil)
              (if (override-p)
                  (progn
                    (dabbrev--reset-global-variables)
                    (dabbrev-expand nil)
                    (indent-for-tab-command)))))
        (indent-for-tab-command)))))
;; Make dabbrev-replace case insensitive.
;; insensitive.
(setq dabbrev-case-replace nil)
;; Replace dabbrev-expand with hippie-expand.
(global-set-key (kbd "M-/") 'hippie-expand)
;; Bind to tab.
(global-set-key (kbd "C-i") 'smart-tab)
;; Function to enable autosave.
