+(defcustom company-dabbrev-other-buffers 'all
+ "*Determines whether `company-dabbrev' should search other buffers.
+If `all', search all other buffers. If t, search buffers with the same
+major mode.
+See also `company-dabbrev-time-limit'."
+ :group 'company
+ :type '(choice (const :tag "Off" nil)
+ (const :tag "Same major mode" t)
+ (const :tag "All" all)))
+
+(defcustom company-dabbrev-time-limit .5
+ "*Determines how many seconds `company-dabbrev' should look for matches."
+ :group 'company
+ :type '(choice (const :tag "Off" nil)
+ (number :tag "Seconds")))
+
+(defcustom company-dabbrev-char-regexp "\\sw"
+ "*A regular expression matching the characters `company-dabbrev' looks for."
+ :group 'company
+ :type 'regexp)
+
+(defmacro company-dabrev--time-limit-while (test start limit &rest body)
+ (declare (indent 3) (debug t))
+ `(let ((company-time-limit-while-counter 0))
+ (catch 'done
+ (while ,test
+ ,@body
+ (and ,limit
+ (eq (incf company-time-limit-while-counter) 25)
+ (setq company-time-limit-while-counter 0)
+ (> (float-time (time-since ,start)) ,limit)
+ (throw 'done 'company-time-out))))))
+
+(defsubst company-dabbrev--make-regexp (prefix)
+ (concat "\\<" (if (equal prefix "")
+ company-dabbrev-char-regexp
+ (regexp-quote prefix))
+ "\\(" company-dabbrev-char-regexp "\\)*\\>"))
+
+(defun company-dabbrev--search-buffer (regexp pos symbols start limit
+ ignore-comments)