From: Dmitry Gutov Date: Fri, 3 Jul 2015 19:04:00 +0000 (+0300) Subject: Introduce company-indent-or-complete-common X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/d39b956539d378b55723d11990ee54f1b8cf6586?hp=7419d5f4204dedb28b57bc67ab7fec946bf519c2 Introduce company-indent-or-complete-common As requested in https://github.com/clojure-emacs/cider/pull/1185/ --- diff --git a/NEWS.md b/NEWS.md index 319e959af..b452544f7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ## Next +* New command `company-indent-or-complete-common`. * Backend command `doc-buffer` now can also return a cons of buffer and window start position. * Backend command `ignore-case` has been documented. diff --git a/company.el b/company.el index 5c00dbbbf..169882e87 100644 --- a/company.el +++ b/company.el @@ -1955,6 +1955,20 @@ With ARG, move by that many elements." (current-prefix-arg arg)) (call-interactively 'company-select-next)))))) +(defun company-indent-or-complete-common () + "Indent the current line or region, or complete the common part." + (interactive) + (cond + ((use-region-p) + (indent-region (region-beginning) (region-end))) + ((let ((old-point (point)) + (old-tick (buffer-chars-modified-tick)) + (tab-always-indent t)) + (call-interactively #'indent-for-tab-command) + (when (and (eq old-point (point)) + (eq old-tick (buffer-chars-modified-tick))) + (company-complete-common)))))) + (defun company-complete () "Insert the common part of all candidates or the current selection. The first time this is called, the common part is inserted, the second