]> code.delx.au - gnu-emacs-elpa/commitdiff
company-files.el: Change regexp prefix
authorJames Browder <Orion@home.com>
Sun, 21 Sep 2014 22:52:53 +0000 (17:52 -0500)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 28 Sep 2014 15:45:31 +0000 (19:45 +0400)
* Fix Windows drive letters recognition.
* Complete relative paths, starting with ./ or ../.

company-files.el

index 3dc4d867f8b67fb925e68a05fd6e65dc5b54bd36..c8fba51ccdb240f320d90beaa7fa2223023bb926 100644 (file)
       (file-name-all-completions prefix dir))))
 
 (defvar company-files-regexps
-  (let ((begin (if (eq system-type 'windows-nt)
-                   "[a-z][A-Z]\\"
-                 "~?/")))
+  (let* ((begin (if (eq system-type 'windows-nt)
+                    "[a-zA-Z]:/"
+                  "/"))
+         (begin (concat "\\(?:\\.\\{1,2\\}/\\|~/\\|" begin "\\)")))
     (list (concat "\"\\(" begin "[^\"\n]*\\)")
           (concat "\'\\(" begin "[^\'\n]*\\)")
           (concat "\\(?:[ \t]\\|^\\)\\(" begin "[^ \t\n]*\\)"))))
 
 (defun company-files-complete (prefix)
   (let* ((dir (file-name-directory prefix))
+         (dir-exp (expand-file-name dir))
          (file (file-name-nondirectory prefix))
          candidates directories)
-    (unless (equal dir (car company-files-completion-cache))
+    (unless (equal dir-exp (car company-files-completion-cache))
       (dolist (file (company-files-directory-files dir file))
         (setq file (concat dir file))
         (push file candidates)
           (push (concat directory
                         (unless (eq (aref directory (1- (length directory))) ?/) "/")
                         child) candidates)))
-      (setq company-files-completion-cache (cons dir (nreverse candidates))))
+      (setq company-files-completion-cache (cons dir-exp (nreverse candidates))))
     (all-completions prefix
                      (cdr company-files-completion-cache))))
 
 ;;;###autoload
 (defun company-files (command &optional arg &rest ignored)
-  "`company-mode' completion back-end existing file names."
+  "`company-mode' completion back-end existing file names.
+Completions are triggered when the text inside quotes starts with any of 
+the following: ./, ../, ~/, or root drive"
   (interactive (list 'interactive))
   (cl-case command
     (interactive (company-begin-backend 'company-files))