(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 ()
(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
(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
(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)