]> code.delx.au - gnu-emacs-elpa/commitdiff
company-safe-substring: use a temp buffer
authorDmitry Gutov <dgutov@yandex.ru>
Fri, 15 Mar 2013 14:54:00 +0000 (18:54 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 15 Mar 2013 14:54:00 +0000 (18:54 +0400)
* No more situations where we replace actual text with whitespace.

* Still don't handle wide characters, except by untabifying in advance.

* It's fast enough, although it woudln't hurt to replace most of the string
  splitting and munching in the callers with direct buffer manipulation.

company.el

index fce59f726912bea22fbcc65982aa98e8330166b9..8344b6371953379e6fa33157284ba1bae77f5ea1 100644 (file)
@@ -1437,15 +1437,18 @@ To show the number next to the candidates in some back-ends, enable
 (defsubst company-safe-substring (str from &optional to)
   (if (> from (string-width str))
       ""
-    (if to
-        (let* ((res (substring str from (min to (length str))))
-               (padding (- to from (string-width res)))
-               (cutting-comp (and (> (length str) to)
-                                  (get-text-property to 'composition str))))
-          (concat res
-                  (when (and (> padding 0) (not cutting-comp))
-                    (company-space-string padding))))
-      (substring str from))))
+    (with-temp-buffer
+      (insert str)
+      (move-to-column from)
+      (let ((beg (point)))
+        (if to
+            (progn
+              (move-to-column to)
+              (concat (buffer-substring beg (point))
+                      (let ((padding (- to (current-column))))
+                        (when (> padding 0)
+                          (company-space-string padding)))))
+          (buffer-substring beg (point-max)))))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;