]> code.delx.au - gnu-emacs-elpa/blobdiff - company.el
Bumped version to 0.3.1.
[gnu-emacs-elpa] / company.el
index 8aad11614108f0544c8627f89e550a98ff2d5870..3be107ef0e7d856eacea585a9adddf035ec417e1 100644 (file)
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2009 Nikolaj Schumacher
 ;;
 ;; Author: Nikolaj Schumacher <bugs * nschum de>
-;; Version: 0.3
+;; Version: 0.3.1
 ;; Keywords: abbrev, convenience, matchis
 ;; URL: http://nschum.de/src/emacs/company/
 ;; Compatibility: GNU Emacs 22.x, GNU Emacs 23.x
@@ -69,6 +69,9 @@
 ;;
 ;;; Change Log:
 ;;
+;; 2009-04-15 (0.3.1)
+;;    Added 'stop prefix to prevent dabbrev from completing inside of symbols.
+;;    Fixed issues with tabbar-mode and line-spacing.
 ;;    Performance enhancements.
 ;;
 ;; 2009-04-12 (0.3)
@@ -248,7 +251,8 @@ of the following:
 
 'prefix: The back-end should return the text to be completed.  It must be
 text immediately before `point'.  Returning nil passes control to the next
-back-end.
+back-end.  The function should return 'stop if it should complete but cannot
+(e.g. if it is in the middle of a string).
 
 'candidates: The second argument is the prefix to be completed.  The
 return value should be a list of candidates that start with the prefix.
@@ -525,17 +529,19 @@ keymap during active completions (`company-active-map'):
   (if (looking-at "\\_>")
       (buffer-substring (point) (save-excursion (skip-syntax-backward "w_")
                                                 (point)))
-    ""))
+    (unless (and (char-after) (memq (char-syntax (char-after)) '(?w ?_)))
+      "")))
 
 (defun company-grab-word ()
   (if (looking-at "\\>")
       (buffer-substring (point) (save-excursion (skip-syntax-backward "w")
                                                 (point)))
-    ""))
+    (unless (and (char-after) (eq (char-syntax (char-after)) ?w))
+      "")))
 
-(defun company-in-string-or-comment (&optional point)
-  (let ((pos (syntax-ppss)))
-    (or (nth 3 pos) (nth 4 pos) (nth 7 pos))))
+(defun company-in-string-or-comment ()
+  (let ((ppss (syntax-ppss)))
+    (or (nth 3 ppss) (nth 4 ppss) (nth 7 ppss))))
 
 ;;; completion mechanism ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -593,13 +599,14 @@ keymap during active completions (`company-active-map'):
   ;; It's mory efficient to fix it only when they are displayed.
   (concat company-prefix (substring candidate (length company-prefix))))
 
-(defsubst company-should-complete (prefix)
-  (and (eq company-idle-delay t)
+(defun company--should-complete ()
+  (and (not (or buffer-read-only overriding-terminal-local-map
+                overriding-local-map))
+       (eq company-idle-delay t)
        (or (eq t company-begin-commands)
            (memq company--this-command company-begin-commands)
            (and (symbolp this-command) (get this-command 'company-begin)))
-       (not (and transient-mark-mode mark-active))
-       (>= (length prefix) company-minimum-prefix-length)))
+       (not (and transient-mark-mode mark-active))))
 
 (defsubst company-call-frontends (command)
   (dolist (frontend company-frontends)
@@ -729,64 +736,62 @@ keymap during active completions (`company-active-map'):
                          company-auto-complete-chars)))))
 
 (defun company-continue ()
-  (when company-candidates
-    (when (funcall company-backend 'no-cache company-prefix)
-      ;; Don't complete existing candidates, fetch new ones.
-      (setq company-candidates-cache nil))
-    (let ((new-prefix (funcall company-backend 'prefix)))
-      (unless (and (= (- (point) (length new-prefix))
-                      (- company-point (length company-prefix)))
-                   (or (equal company-prefix new-prefix)
-                       (let ((c (company-calculate-candidates new-prefix)))
-                         ;; t means complete/unique.
-                         (if (eq c t)
-                             (progn (company-cancel new-prefix) t)
-                           (when (consp c)
-                             (setq company-prefix new-prefix)
-                             (company-update-candidates c)
-                             t)))))
-        (if (company-auto-complete-p company-point (point))
-            (save-excursion
-              (goto-char company-point)
-              (company-complete-selection)
+  (when (funcall company-backend 'no-cache company-prefix)
+    ;; Don't complete existing candidates, fetch new ones.
+    (setq company-candidates-cache nil))
+  (let ((new-prefix (funcall company-backend 'prefix)))
+    (unless (and (= (- (point) (length new-prefix))
+                    (- company-point (length company-prefix)))
+                 (or (equal company-prefix new-prefix)
+                     (let ((c (company-calculate-candidates new-prefix)))
+                       ;; t means complete/unique.
+                       (if (eq c t)
+                           (progn (company-cancel new-prefix) t)
+                         (when (consp c)
+                           (setq company-prefix new-prefix)
+                           (company-update-candidates c)
+                           t)))))
+      (if (company-auto-complete-p company-point (point))
+          (save-excursion
+            (goto-char company-point)
+            (company-complete-selection)
+            (setq company-candidates nil))
+        (if (not (and (company-incremental-p company-prefix new-prefix)
+                      (company-require-match-p)))
+            (progn
+              (when (equal company-prefix (car company-candidates))
+                ;; cancel, but last input was actually success
+                (company-cancel company-prefix))
               (setq company-candidates nil))
-          (if (not (and (company-incremental-p company-prefix new-prefix)
-                        (company-require-match-p)))
-              (progn
-                (when (equal company-prefix (car company-candidates))
-                  ;; cancel, but last input was actually success
-                  (company-cancel company-prefix))
-                (setq company-candidates nil))
-            (backward-delete-char (length new-prefix))
-            (insert company-prefix)
-            (ding)
-            (message "Matching input is required")))
-        company-candidates))))
+          (backward-delete-char (length new-prefix))
+          (insert company-prefix)
+          (ding)
+          (message "Matching input is required")))
+      company-candidates)))
 
 (defun company-begin ()
-  (if (or buffer-read-only overriding-terminal-local-map overriding-local-map)
-      ;; Don't complete in these cases.
-      (setq company-candidates nil)
-    (company-continue)
-    (unless company-candidates
-      (let (prefix)
-        (dolist (backend (if company-backend
-                             ;; prefer manual override
-                             (list company-backend)
-                           (cons company-backend company-backends)))
-          (when (and (functionp backend)
-                     (setq prefix (funcall backend 'prefix)))
-            (setq company-backend backend)
-            (when (company-should-complete prefix)
-              (let ((c (company-calculate-candidates prefix)))
-                ;; t means complete/unique.  We don't start, so no hooks.
-                (when (consp c)
-                  (setq company-prefix prefix)
-                  (company-update-candidates c)
-                  (run-hook-with-args 'company-completion-started-hook
-                                      (company-explicit-action-p))
-                  (company-call-frontends 'show))))
-            (return prefix))))))
+  (when (if company-candidates
+            (not (company-continue))
+          (company--should-complete))
+    (let (prefix)
+      (dolist (backend (if company-backend
+                           ;; prefer manual override
+                           (list company-backend)
+                         company-backends))
+        (when (and (functionp backend)
+                   (setq prefix (funcall backend 'prefix)))
+          (when (and (stringp prefix)
+                     (>= (length prefix) company-minimum-prefix-length))
+            (setq company-backend backend
+                  company-prefix prefix)
+            (let ((c (company-calculate-candidates prefix)))
+              ;; t means complete/unique.  We don't start, so no hooks.
+              (when (consp c)
+                (company-update-candidates c)
+                (run-hook-with-args 'company-completion-started-hook
+                                    (company-explicit-action-p))
+                (company-call-frontends 'show))))
+          (return prefix)))))
   (if company-candidates
       (progn
         (when (and company-end-of-buffer-workaround (eobp))
@@ -1080,8 +1085,8 @@ followed by `company-search-kill-others' after each input."
   "Select the candidate picked by the mouse."
   (interactive "e")
   (when (nth 4 (event-start event))
-    (company-set-selection (- (cdr (posn-col-row (event-start event)))
-                              (cdr (posn-col-row (posn-at-point)))
+    (company-set-selection (- (cdr (posn-actual-col-row (event-start event)))
+                              (cdr (posn-actual-col-row (posn-at-point)))
                               1))
     t))
 
@@ -1119,7 +1124,9 @@ when the selection has been changed, the selected candidate is completed."
       (setq this-command 'company-complete-common))))
 
 (defun company-complete-number (n)
-  "Complete the Nth candidate."
+  "Complete the Nth candidate.
+To show the number next to the candidates in some back-ends, enable
+`company-show-numbers'."
   (when (company-manual-begin)
     (and (< n 1) (> n company-candidates-length)
          (error "No candidate number %d" n))
@@ -1172,7 +1179,7 @@ when the selection has been changed, the selected candidate is completed."
   `(when (company-manual-begin)
      (save-window-excursion
        (let ((height (window-height))
-             (row (cdr (posn-col-row (posn-at-point)))))
+             (row (cdr (posn-actual-col-row (posn-at-point)))))
          ,@body
          (and (< (window-height) height)
               (< (- (window-height) row 2) company-tooltip-limit)
@@ -1336,7 +1343,7 @@ Example:
 
 (defun company-buffer-lines (beg end)
   (goto-char beg)
-  (let ((row (cdr (posn-col-row (posn-at-point))))
+  (let ((row (cdr (posn-actual-col-row (posn-at-point))))
         lines)
     (while (and (equal (move-to-window-line (incf row)) row)
                 (<= (point) end))
@@ -1397,9 +1404,8 @@ Example:
     (setq lines-copy lines)
 
     ;; number can make tooltip too long
-    (and company-show-numbers
-         (< (setq numbered company-tooltip-offset) 10)
-         (incf width 2))
+    (when company-show-numbers
+      (setq numbered company-tooltip-offset))
 
     (when previous
       (push (propertize (company-safe-substring previous 0 width)
@@ -1462,8 +1468,10 @@ Example:
       (overlay-put company-pseudo-tooltip-overlay 'window (selected-window)))))
 
 (defun company-pseudo-tooltip-show-at-point (pos)
-  (let ((col-row (posn-col-row (posn-at-point pos))))
-    (company-pseudo-tooltip-show (1+ (cdr col-row)) (car col-row) company-selection)))
+  (let ((col-row (posn-actual-col-row (posn-at-point pos))))
+    (when col-row
+      (company-pseudo-tooltip-show (1+ (cdr col-row)) (car col-row)
+                                   company-selection))))
 
 (defun company-pseudo-tooltip-edit (lines selection)
   (let* ((old-string (overlay-get company-pseudo-tooltip-overlay 'company-old))