  
 
+;;;; Basic cache facility
+
+(defvar ac-clear-variables-after-save nil)
+
+(defun ac-clear-variable-after-save (variable)
+  (push variable ac-clear-variables-after-save))
+
+(defun ac-clear-variables-after-save ()
+  (dolist (variable ac-clear-variables-after-save)
+    (set variable nil)))
+
++
+
 ;;;; Sources implementation
 
 (defvar ac-sources '(ac-source-words-in-buffer)
   "Sources for completion.
 
-Source takes a form of alist:
+Source takes a form of just function which returns candidates or alist:
 
 init INIT-FUNC
   INIT-FUNC will be called before creating candidate every time.

       (let ((selection (1- ac-selection)))
         (if (< selection ac-menu-offset)
             (if (= ac-menu-scroll 0)
                 (prog1 (1- (+ ac-menu-offset (min ac-candidate-menu-height (length ac-candidates))))
                   (setq ac-menu-scroll (- (length ac-candidates) (min ac-candidate-menu-height (length ac-candidates))))
                   (ac-redraw-candidates))
               (setq ac-menu-scroll (1- ac-menu-scroll))
               (ac-redraw-candidates)
               ac-selection)
           selection)))))

(defun ac-expand-1 ()
  "Try expansion."
  (let ((string (overlay-get (ac-menu-line-overlay ac-menu ac-selection) 'real-string)))
    (delete-region ac-point (point))
    (insert string)
    (setq ac-prefix string)))

(defun ac-expand ()
  "Try expansion but select next if expanded twice."
  (interactive)
  (if (and ac-dwim ac-dwim-enable)
      (ac-complete)
    (let ((target ac-prefix)
          (string (ac-expand-1)))
      (when (equal target string)
        (ac-next)
        (ac-expand-1)))))

(defun ac-expand-common ()
  "Try expansion common part."

  "Implementation for `ac-cadidates-function' by sources."
  (let (candidates)
    (dolist (source ac-current-sources)
      (let* ((ac-limit (or (ac-get-source-property 'limit source) ac-limit))
             (requires (ac-get-source-property 'requires source))
             cand)
        (when (or ac-sources-omni-completion
                  (>= (length ac-prefix)
