update packages
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
;;; company-files.el --- company-mode completion backend for file names
|
||||
;;; company-files.el --- company-mode completion backend for file names -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2009-2011, 2013-2021 Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2009-2011, 2013-2024 Free Software Foundation, Inc.
|
||||
|
||||
;; Author: Nikolaj Schumacher
|
||||
|
||||
@@ -38,22 +38,14 @@ The values should use the same format as `completion-ignored-extensions'."
|
||||
:type '(repeat (string :tag "File extension or directory name"))
|
||||
:package-version '(company . "0.9.1"))
|
||||
|
||||
(defcustom company-files-chop-trailing-slash t
|
||||
"Non-nil to remove the trailing slash after inserting directory name.
|
||||
|
||||
This way it's easy to continue completion by typing `/' again.
|
||||
|
||||
Set this to nil to disable that behavior."
|
||||
:type 'boolean)
|
||||
|
||||
(defun company-files--directory-files (dir prefix)
|
||||
;; Don't use directory-files. It produces directories without trailing /.
|
||||
(condition-case err
|
||||
(condition-case _err
|
||||
(let ((comp (sort (file-name-all-completions prefix dir)
|
||||
(lambda (s1 s2) (string-lessp (downcase s1) (downcase s2))))))
|
||||
(when company-files-exclusions
|
||||
(setq comp (company-files--exclusions-filtered comp)))
|
||||
(if (equal prefix "")
|
||||
(if (string-empty-p prefix)
|
||||
(delete "../" (delete "./" comp))
|
||||
comp))
|
||||
(file-error nil)))
|
||||
@@ -105,54 +97,58 @@ Set this to nil to disable that behavior."
|
||||
|
||||
(defvar company-files--completion-cache nil)
|
||||
|
||||
(defun company-files--complete (prefix)
|
||||
(let* ((dir (file-name-directory prefix))
|
||||
(file (file-name-nondirectory prefix))
|
||||
(defun company-files--complete (_prefix)
|
||||
(let* ((full-prefix (company-files--grab-existing-name))
|
||||
(dir (file-name-directory full-prefix))
|
||||
(file (file-name-nondirectory full-prefix))
|
||||
(key (list file
|
||||
(expand-file-name dir)
|
||||
(nth 5 (file-attributes dir))))
|
||||
(completion-ignore-case read-file-name-completion-ignore-case))
|
||||
(unless (company-file--keys-match-p key (car company-files--completion-cache))
|
||||
(let* ((candidates (mapcar (lambda (f) (concat dir f))
|
||||
(company-files--directory-files dir file)))
|
||||
(unless (or (company-file--keys-match-p key (car company-files--completion-cache))
|
||||
(not (company-files--connected-p dir)))
|
||||
(let* ((candidates (company-files--directory-files dir file))
|
||||
(directories (unless (file-remote-p dir)
|
||||
(cl-remove-if-not (lambda (f)
|
||||
(and (company-files--trailing-slash-p f)
|
||||
(not (file-remote-p f))
|
||||
(company-files--connected-p f)))
|
||||
(company-files--trailing-slash-p f))
|
||||
candidates)))
|
||||
(children (and directories
|
||||
(cl-mapcan (lambda (d)
|
||||
(mapcar (lambda (c) (concat d c))
|
||||
(company-files--directory-files d "")))
|
||||
(company-files--directory-files d ""))
|
||||
directories))))
|
||||
(setq company-files--completion-cache
|
||||
(cons key (append candidates children)))))
|
||||
(all-completions prefix
|
||||
(cdr company-files--completion-cache))))
|
||||
(all-completions file (cdr company-files--completion-cache))))
|
||||
|
||||
(defun company-files--prefix ()
|
||||
(let ((existing (company-files--grab-existing-name)))
|
||||
(when existing
|
||||
(list existing (company-grab-suffix "[^ '\"\t\n\r/]*/?")))))
|
||||
|
||||
(defun company-file--keys-match-p (new old)
|
||||
(and (equal (cdr old) (cdr new))
|
||||
(string-prefix-p (car old) (car new))))
|
||||
|
||||
(defun company-files--post-completion (arg)
|
||||
(when (and company-files-chop-trailing-slash
|
||||
(company-files--trailing-slash-p arg))
|
||||
(delete-char -1)))
|
||||
(defun company-files--adjust-boundaries (_file prefix suffix)
|
||||
(cons
|
||||
(file-name-nondirectory prefix)
|
||||
suffix))
|
||||
|
||||
;;;###autoload
|
||||
(defun company-files (command &optional arg &rest ignored)
|
||||
(defun company-files (command &optional arg &rest rest)
|
||||
"`company-mode' completion backend existing file names.
|
||||
Completions works for proper absolute and relative files paths.
|
||||
File paths with spaces are only supported inside strings."
|
||||
(interactive (list 'interactive))
|
||||
(cl-case command
|
||||
(interactive (company-begin-backend 'company-files))
|
||||
(prefix (company-files--grab-existing-name))
|
||||
(candidates (company-files--complete arg))
|
||||
(prefix (company-files--prefix))
|
||||
(candidates
|
||||
(company-files--complete arg))
|
||||
(adjust-boundaries
|
||||
(company-files--adjust-boundaries arg (nth 0 rest) (nth 1 rest)))
|
||||
(location (cons (dired-noselect
|
||||
(file-name-directory (directory-file-name arg))) 1))
|
||||
(post-completion (company-files--post-completion arg))
|
||||
(kind (if (string-suffix-p "/" arg) 'folder 'file))
|
||||
(sorted t)
|
||||
(no-cache t)))
|
||||
|
||||
Reference in New Issue
Block a user