2

I am frequently diving through many layers of directory hierarchies (thanks, Java) to find files named like this…

java/test/com/company/thing/test/testy/testier/testier/Tester.java

The main issue that I have is that TAB-completion in find-file only completes one directory at a time, meaning that I may have to press TAB 5 times to get through the first few layers of the hierarchy, where each directory contains only one subdirectory and nothing more (e.g. com/ contains only company/, company/ contains only thing/), etc.

Is there any package that modifies TAB-completion with standard Emacs commands, including find-file, so that multiple directories will be "greedily" autocompleted when they contain only one subdirectory?

I'm aware of Projectile, and know that it has a similar feature, but I'm hoping to find something standalone and minimal that just solves this one issue.

0

I use ivy/counsel so I only have an ivy solution:

(defcustom dc4ever-cd-all-the-way t
  "Whether to enable cd-all-the-way feature." :type 'boolean)
(defvar dc4ever--cd-all-the-way-flag nil "Internal flag for cd-all-the-way.")

(defun dc4ever//ivy-magic-slash-advice (func &rest r)
  "Set `dc4ever--cd-all-the-way-flag' for `ivy--magic-file-slash'."
  (let ((dc4ever--cd-all-the-way-flag dc4ever-cd-all-the-way))
    (apply func r)))
(advice-add #'ivy--magic-file-slash :around #'dc4ever//ivy-magic-slash-advice)

(defun dc4ever//ivy--cd-advice (func &rest r)
  "Advice `ivy--cd' to do cd-all-the-way."
  (if (not dc4ever--cd-all-the-way-flag) (apply func r)
    (cl-labels ((get-only-dir
                 (dir)
                 (let* ((entries (f-entries dir))
                        (onlyent (when (= 1 (length entries))
                                   (concat (expand-file-name (car entries) dir)
                                           "/"))))
                   (cond
                    ((null onlyent) dir)
                    ((f-dir? onlyent) (get-only-dir onlyent))
                    (t dir)))))
      (funcall func (get-only-dir (car r))))))
(advice-add #'ivy--cd :around #'dc4ever//ivy--cd-advice)

NOTE:

This only works if you type / since I implemented that way, so that TAB would keep the original behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.