minad / cape

🦸cape.el - Completion At Point Extensions
GNU General Public License v3.0
608 stars 22 forks source link

First candidate is not selected in `cape-file` when completing #20

Closed failable closed 2 years ago

failable commented 2 years ago

Compared to other cape-* functions, cape-file does not select the first candidate when the frame shows up. Is it by design? Thanks.

Screen Shot 2022-01-06 at 6 22 33 PM Screen Shot 2022-01-06 at 6 26 51 PM

Config:

(setq user-init-file (or load-file-name (buffer-file-name)))
(setq user-emacs-directory (file-name-directory user-init-file))
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))

(require 'package)
(add-to-list 'package-archives '("tromey" . "http://tromey.com/elpa/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(setq package-user-dir (expand-file-name "elpa/" user-emacs-directory))
(package-initialize)

;; Install use-package that we require for managing all other dependencies
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(package-install 'corfu)
(package-install 'multiple-cursors)
(package-install 'cape)

(setq corfu-auto t)
(corfu-global-mode)

(add-to-list 'completion-at-point-functions #'cape-file)
minad commented 2 years ago

This is by design since the input is a valid file path. Otherwise you wouldn't be able to input directory paths.

failable commented 2 years ago

The company way seems better since it's has the advantage of TAB quickly to access deep nested files to minimize the C-ns. To insert a directory, aren't both libraries require a C-g?

Screen Shot 2022-01-06 at 8 42 14 PM Screen Shot 2022-01-06 at 8 42 43 PM
minad commented 2 years ago

The company way seems better since it's has the advantage of TAB quickly to access deep nested files to minimize the C-ns. To insert a directory, aren't both libraries require a C-g?

I disagree. Corfu uses the underlying Emacs file completion table as is. There you don't complete full paths but the files step by step.

Anyways if you prefer the Company way you can either use Company or use the Company backend with Corfu/Cape.

(fset #'cape-path (cape-company-to-capf #'company-files))
(add-hook 'completion-at-point-functions #'cape-path)
failable commented 2 years ago

That works! Thanks!