(push (semantic-tag-name tag) candidates)))
(delete "" candidates)))
+(defun company-semantic--pre-prefix-length (prefix-length)
+ "Sum up the length of all chained symbols before POS.
+Symbols are chained by \".\" or \"->\"."
+ (save-excursion
+ (let ((pos (point)))
+ (goto-char (- (point) prefix-length))
+ (while (looking-back "->\\|\\.")
+ (goto-char (match-beginning 0))
+ (skip-syntax-backward "w_"))
+ (- pos (point)))))
+
+(defun company-semantic--grab ()
+ "Grab the semantic prefix, but return everything before -> or . as length."
+ (let ((symbol (company-grab-symbol)))
+ (when symbol
+ (cons symbol (company-semantic--pre-prefix-length (length symbol))))))
+
;;;###autoload
(defun company-semantic (command &optional arg &rest ignored)
"A `company-mode' completion back-end using CEDET Semantic."
('prefix (and (memq major-mode '(c-mode c++-mode jde-mode java-mode))
(semantic-active-p)
(not (company-in-string-or-comment))
- (or (company-grab-symbol) 'stop)))
+ (or (company-semantic--grab) 'stop)))
('candidates (or (company-semantic-completions arg)
(company-semantic-completions-raw arg)))
('meta (funcall company-semantic-metadata-function
;;
;;; Change Log:
;;
+;; In C modes . and -> now count towards `company-minimum-prefix-length'.
;; Reverted default front-end back to `company-preview-if-just-one-frontend'.
;; The pseudo tooltip will no longer be clipped at the right window edge.
;; Added `company-tooltip-minimum'.
'prefix: The back-end should return the text to be completed. It must be
text immediately before `point'. Returning nil passes control to the next
back-end. The function should return 'stop if it should complete but cannot
-\(e.g. if it is in the middle of a string\).
+\(e.g. if it is in the middle of a string\). If the returned value is only
+part of the prefix (e.g. the part after \"->\" in C), the back-end may return a
+cons of prefix and prefix length, which is then used in the
+`company-minimum-prefix-length' test.
'candidates: The second argument is the prefix to be completed. The
return value should be a list of candidates that start with the prefix.
nil)))))
(defun company--good-prefix-p (prefix)
- (and (stringp prefix)
- (or (company-explicit-action-p)
- (>= (length prefix) company-minimum-prefix-length))))
+ (and (or (company-explicit-action-p)
+ (>= (or (cdr-safe prefix) (length prefix))
+ company-minimum-prefix-length))
+ (stringp (or (car-safe prefix) prefix))))
(defun company--continue ()
(when (company-call-backend 'no-cache company-prefix)
(setq company-candidates-cache nil))
(let* ((new-prefix (company-call-backend 'prefix))
(c (when (and (company--good-prefix-p new-prefix)
+ (setq new-prefix (or (car-safe new-prefix) new-prefix))
(= (- (point) (length new-prefix))
(- company-point (length company-prefix))))
+ (setq new-prefix (or (car-safe new-prefix) new-prefix))
(company-calculate-candidates new-prefix))))
(or (cond
((eq c t)
(company--multi-backend-adapter backend 'prefix)))
(when prefix
(when (company--good-prefix-p prefix)
- (setq company-backend backend
+ (setq prefix (or (car-safe prefix) prefix)
+ company-backend backend
c (company-calculate-candidates prefix))
;; t means complete/unique. We don't start, so no hooks.
(when (consp c)