From: Dmitry Gutov Date: Mon, 2 Feb 2015 12:32:11 +0000 (+0200) Subject: Use mode-line format in company-lighter X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/94f24594cfbf7a7e2f96e04fb423bf9f8354e9d3 Use mode-line format in company-lighter And use company-lighter-base in it. Resolves #290. Resolves #291. --- diff --git a/NEWS.md b/NEWS.md index 0718b399a..13fc6bdbc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ## Next +* New variable `company-lighter-base`. * Better tracking of the current selection. * Pressing `M-0`...`M-9` works in the search mode. * Pressing `` or `` doesn't quit the search mode. diff --git a/company.el b/company.el index dcdc19d85..991ab9bc4 100644 --- a/company.el +++ b/company.el @@ -662,9 +662,26 @@ asynchronous call into synchronous.") (unless (keywordp b) (company-init-backend b)))))) -(defvar company-default-lighter " company") - -(defvar-local company-lighter company-default-lighter) +(defcustom company-lighter-base "company" + "Base string to use for the `company-mode' lighter." + :type 'string + :package-version '(company . "0.8.10")) + +(defvar company-lighter '(" " + (company-backend + (:eval + (if (consp company-backend) + (company--group-lighter + (nth company-selection + company-candidates)) + (symbol-name company-backend))) + company-lighter-base)) + "Mode line lighter for Company. + +The value of this variable is a mode line template as in +`mode-line-format'.") + +(put 'company-lighter 'risky-local-variable t) ;;;###autoload (define-minor-mode company-mode @@ -1045,19 +1062,17 @@ can retrieve meta-data for them." (mod selection company-candidates-length) (max 0 (min (1- company-candidates-length) selection)))) (when (or force-update (not (equal selection company-selection))) - (company--update-group-lighter (nth selection company-candidates)) (setq company-selection selection company-selection-changed t) (company-call-frontends 'update))) -(defun company--update-group-lighter (candidate) - (when (listp company-backend) - (let ((backend (or (get-text-property 0 'company-backend candidate) - (car company-backend)))) - (when (and backend (symbolp backend)) - (let ((name (replace-regexp-in-string "company-\\|-company" "" - (symbol-name backend)))) - (setq company-lighter (format " company-<%s>" name))))))) +(defun company--group-lighter (candidate) + (let ((backend (or (get-text-property 0 'company-backend candidate) + (car company-backend)))) + (when (and backend (symbolp backend)) + (let ((name (replace-regexp-in-string "company-\\|-company" "" + (symbol-name backend)))) + (format "%s-<%s>" company-lighter-base name))))) (defun company-update-candidates (candidates) (setq company-candidates-length (length candidates)) @@ -1452,9 +1467,6 @@ from the rest of the back-ends in the group, if any, will be left at the end." (message "No completion found")) (when company--manual-action (setq company--manual-prefix prefix)) - (if (symbolp backend) - (setq company-lighter (concat " " (symbol-name backend))) - (company--update-group-lighter (car c))) (company-update-candidates c) (run-hook-with-args 'company-completion-started-hook (company-explicit-action-p)) @@ -1492,7 +1504,6 @@ from the rest of the back-ends in the group, if any, will be left at the end." company-selection-changed nil company--manual-action nil company--manual-prefix nil - company-lighter company-default-lighter company--point-max nil company-point nil) (when company-timer