]> code.delx.au - gnu-emacs-elpa/commitdiff
Respect line-prefix at bol (#24)
authorDmitry Gutov <dgutov@yandex.ru>
Tue, 21 May 2013 01:15:58 +0000 (05:15 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Tue, 21 May 2013 03:28:30 +0000 (07:28 +0400)
NEWS.md
company-tests.el
company.el

diff --git a/NEWS.md b/NEWS.md
index e5ad713e97f6d6e86f389686667f65c1eda2a05c..b6459c7f544f358c5291a1c5ac22d35ef9d82116 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
 
 ## Next
 
+* Plays nicer with `org-indent-mode`.
 * Works in horizontally scrolled windows.
 
 ## 2013-05-10 (0.6.9)
index 78337259981d568518628d2371e6a6351967ae7e..604e8c29f316bd31da5cf3a85a5ada75d406de51 100644 (file)
     (compose-region 1 (1+ (length "lambda")) "\\")
     (should (= (company--column) 4))))
 
+(ert-deftest company-column-with-line-prefix ()
+  (with-temp-buffer
+    (insert "foo")
+    (put-text-property (point-min) (point) 'line-prefix "  ")
+    (should (= (company--column) 5))))
+
+(ert-deftest company-modify-line-with-line-prefix ()
+  (let ((str (propertize "foobar" 'line-prefix "-*-")))
+    (should (string= (company-modify-line str "zz" 4)
+                     "fzzbar"))
+    (should (string= (company-modify-line str "zzxx" 0)
+                     "zzxxoobar"))
+    (should (string= (company-modify-line str "zzxx" 0)
+                     "zzxxoobar"))
+    (should (string= (company-modify-line str "zz" 10)
+                     "foobar zz"))))
+
 ;;; Template
 
 (ert-deftest company-template-removed-after-the-last-jump ()
index 47f0f617bd6f88517fecf5946cbfc289800cd98b..84b9bd3fe77e2e05d5f903030de600ed13b9fe4e 100644 (file)
@@ -574,11 +574,16 @@ keymap during active completions (`company-active-map'):
 (defun company--column (&optional pos)
   (save-excursion
     (when pos (goto-char pos))
-    (save-restriction
-      (narrow-to-region (save-excursion
-                          (vertical-motion 0) (point))
-                        (point))
-      (current-column))))
+    (let ((pt (point))
+          (modifier 0))
+      (save-restriction
+        (save-excursion
+          (vertical-motion 0)
+          (narrow-to-region (point) pt)
+          (let ((prefix (get-text-property (point) 'line-prefix)))
+            (when prefix (setq modifier (length prefix)))))
+        (+ (current-column)
+           modifier)))))
 
 (defun company--row (&optional pos)
   (save-excursion
@@ -1425,7 +1430,7 @@ To show the number next to the candidates in some back-ends, enable
       (aref company-space-strings len)
     (make-string len ?\ )))
 
-(defsubst company-safe-substring (str from &optional to)
+(defun company-safe-substring (str from &optional to)
   (if (> from (string-width str))
       ""
     (with-temp-buffer
@@ -1661,9 +1666,17 @@ Example:
     (nreverse lines)))
 
 (defsubst company-modify-line (old new offset)
-  (concat (company-safe-substring old 0 offset)
-          new
-          (company-safe-substring old (+ offset (length new)))))
+  (let ((prefix (get-text-property 0 'line-prefix old))
+        before)
+    (when prefix
+      (if (<= offset (length prefix))
+        (setq before (substring prefix 0 offset)))
+      (decf offset (length prefix)))
+    (concat (or before (company-safe-substring old 0 offset))
+            new
+            (company-safe-substring old
+                                    (let ((to (+ offset (length new))))
+                                      (if (> to 0) to 0))))))
 
 (defsubst company--length-limit (lst limit)
   (if (nthcdr limit lst)