]> code.delx.au - gnu-emacs-elpa/blobdiff - company.el
company-modify-line: Handle an empty first line with line-prefix
[gnu-emacs-elpa] / company.el
index 47f0f617bd6f88517fecf5946cbfc289800cd98b..1a98036ea28e7bf0b37e4cee88314acceb510893 100644 (file)
@@ -574,11 +574,14 @@ 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)))
+      (save-restriction
+        (+ (save-excursion
+             (vertical-motion 0)
+             (narrow-to-region (point) pt)
+             (let ((prefix (get-text-property (point) 'line-prefix)))
+               (if prefix (length prefix) 0)))
+           (current-column))))))
 
 (defun company--row (&optional pos)
   (save-excursion
@@ -720,7 +723,7 @@ can retrieve meta-data for them."
   (or company--explicit-action
       company-selection-changed))
 
-(defsubst company-reformat (candidate)
+(defun company-reformat (candidate)
   ;; company-ispell needs this, because the results are always lower-case
   ;; It's mory efficient to fix it only when they are displayed.
   (concat company-prefix (substring candidate (length company-prefix))))
@@ -738,14 +741,14 @@ can retrieve meta-data for them."
            (and (symbolp this-command) (get this-command 'company-begin)))
        (not (and transient-mark-mode mark-active))))
 
-(defsubst company-call-frontends (command)
+(defun company-call-frontends (command)
   (dolist (frontend company-frontends)
     (condition-case err
         (funcall frontend command)
       (error (error "Company: Front-end %s error \"%s\" on command %s"
                     frontend (error-message-string err) command)))))
 
-(defsubst company-set-selection (selection &optional force-update)
+(defun company-set-selection (selection &optional force-update)
   (setq selection (max 0 (min (1- company-candidates-length) selection)))
   (when (or force-update (not (equal selection company-selection)))
     (setq company-selection selection
@@ -1420,12 +1423,12 @@ To show the number next to the candidates in some back-ends, enable
       (push (make-string (- company-space-strings-limit 1 i) ?\  ) lst))
     (apply 'vector lst)))
 
-(defsubst company-space-string (len)
+(defun company-space-string (len)
   (if (< len company-space-strings-limit)
       (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
@@ -1651,19 +1654,30 @@ Example:
 (defun company-buffer-lines (beg end)
   (goto-char beg)
   (let (lines)
-    (while (< (point) end)
-      (let ((bol (point)))
+    (while (and (= 1 (vertical-motion 1))
+                (<= (point) end))
+      (let ((bound (min end (1- (point)))))
         ;; A visual line can contain several physical lines (e.g. with outline's
         ;; folding overlay).  Take only the first one.
-        (re-search-forward "$")
-        (push (buffer-substring bol (min end (point))) lines))
-      (vertical-motion 1))
+        (push (buffer-substring beg
+                                (save-excursion
+                                  (goto-char beg)
+                                  (re-search-forward "$" bound 'move)
+                                  (point)))
+              lines))
+      (setq beg (point)))
+    (unless (eq beg end)
+      (push (buffer-substring beg end) lines))
     (nreverse lines)))
 
-(defsubst company-modify-line (old new offset)
-  (concat (company-safe-substring old 0 offset)
-          new
-          (company-safe-substring old (+ offset (length new)))))
+(defun company-modify-line (old new offset)
+  (let ((prefix (get-text-property 0 'line-prefix old)))
+    (when prefix ; Keep the original value unmodified, for no special reason.
+      (setq old (concat prefix old))
+      (remove-text-properties 0 (length old) '(line-prefix) old))
+    (concat (company-safe-substring old 0 offset)
+            new
+            (company-safe-substring old (+ offset (length new))))))
 
 (defsubst company--length-limit (lst limit)
   (if (nthcdr limit lst)
@@ -1763,7 +1777,7 @@ Example:
   (let ((edges (window-inside-edges)))
     (- (nth 3 edges) (nth 1 edges))))
 
-(defsubst company--pseudo-tooltip-height ()
+(defun company--pseudo-tooltip-height ()
   "Calculate the appropriate tooltip height.
 Returns a negative number if the tooltip should be displayed above point."
   (let* ((lines (company--row))
@@ -1833,6 +1847,8 @@ Returns a negative number if the tooltip should be displayed above point."
     (overlay-put company-pseudo-tooltip-overlay 'invisible t)
     ;; Beat outline's folding overlays, at least.
     (overlay-put company-pseudo-tooltip-overlay 'priority 1)
+    ;; No (extra) prefix for the first line.
+    (overlay-put company-pseudo-tooltip-overlay 'line-prefix "")
     (overlay-put company-pseudo-tooltip-overlay 'before-string
                  (overlay-get company-pseudo-tooltip-overlay 'company-before))
     (overlay-put company-pseudo-tooltip-overlay 'window (selected-window))))
@@ -1940,17 +1956,12 @@ Returns a negative number if the tooltip should be displayed above point."
         (message "%s" company-echo-last-msg)
       (message ""))))
 
-(defsubst company-echo-show-soon (&optional getter)
+(defun company-echo-show-soon (&optional getter)
   (when company-echo-timer
     (cancel-timer company-echo-timer))
   (setq company-echo-timer (run-with-timer 0 nil 'company-echo-show getter)))
 
 (defsubst company-echo-show-when-idle (&optional getter)
-  (when (sit-for .01)
-    (company-echo-show getter)))
-
-(defsubst company-echo-show-when-not-busy (&optional getter)
-  "Run `company-echo-show' with arg GETTER once Emacs isn't busy."
   (when (sit-for company-echo-delay)
     (company-echo-show getter)))