]> code.delx.au - gnu-emacs-elpa/commitdiff
Introduce company-indent-or-complete-common
authorDmitry Gutov <dgutov@yandex.ru>
Fri, 3 Jul 2015 19:04:00 +0000 (22:04 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 3 Jul 2015 19:04:00 +0000 (22:04 +0300)
As requested in https://github.com/clojure-emacs/cider/pull/1185/

NEWS.md
company.el

diff --git a/NEWS.md b/NEWS.md
index 319e959affdca7e64b7973a1ba6a1616fa825742..b452544f709c2c95f5db834a5b1227e94a17fa6b 100644 (file)
--- 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.
index 5c00dbbbf36708bc27e3ea4c83fef3e6d06736d4..169882e8743c40207c5721ac3912c2cde7f79cc4 100644 (file)
@@ -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