- (when (looking-at "\\>")
- (let ((end (point)))
- (dabbrev--reset-global-variables)
- (dabbrev--goto-start-of-abbrev)
- (buffer-substring-no-properties (point) end)))))
+ (let (match)
+ (goto-char (if pos (1- pos) (point-min)))
+ ;; search before pos
+ (company-dabrev--time-limit-while (re-search-backward regexp nil t)
+ start limit
+ (setq match (match-string-no-properties 0))
+ (if (and ignore-comments (company-in-string-or-comment))
+ (goto-char (nth 8 (syntax-ppss)))
+ (when (>= (length match) company-dabbrev-minimum-length)
+ (push match symbols))))
+ (goto-char (or pos (point-min)))
+ ;; search after pos
+ (company-dabrev--time-limit-while (re-search-forward regexp nil t)
+ start limit
+ (setq match (match-string-no-properties 0))
+ (if (and ignore-comments (company-in-string-or-comment))
+ (re-search-forward "\\s>\\|\\s!\\|\\s\"" nil t)
+ (when (>= (length match) company-dabbrev-minimum-length)
+ (push match symbols))))
+ symbols)))
+
+(defun company-dabbrev--search (regexp &optional limit other-buffer-modes
+ ignore-comments)
+ (let* ((start (current-time))
+ (symbols (company-dabbrev--search-buffer regexp (point) nil start limit
+ ignore-comments)))
+ (when other-buffer-modes
+ (cl-dolist (buffer (delq (current-buffer) (buffer-list)))
+ (with-current-buffer buffer
+ (when (if (eq other-buffer-modes 'all)
+ (not (string-match-p company-dabbrev-ignore-buffers
+ (buffer-name)))
+ (apply #'derived-mode-p other-buffer-modes))
+ (setq symbols
+ (company-dabbrev--search-buffer regexp nil symbols start
+ limit ignore-comments))))
+ (and limit
+ (> (float-time (time-since start)) limit)
+ (cl-return))))
+ symbols))