Subject: bug#41821: 28.0.50; read-directory-name in vc commands should provide defaults from projects

From: Juri Linkov <[email-masked]>
Date: Thu, 02 Jul 2020 01:10:00 +0300

> we at least put this feature request on hold (and, for now,
> revert the installed patches).

Ok, reverted the installed patches.

It's easy to achieve the same in the init file with these
simple advises.  Now this works perfectly from POV of users
who prefer to use project directories everywhere in all prompts
that ask for a directory:

#+begin_src emacs-lisp
;; When a prompt of some commands such as 'rgrep' or 'vc-print-log' asks for
;; a directory name, allow 'M-n' to access the most recently used project
;; directories saved in ~/.emacs.d/projects:

(advice-add 'read-directory-name :around
            (lambda (orig-fun prompt &optional dir default-dirname
                              mustmatch initial)
              (when (featurep 'project)
                (setq default-dirname
                      (append (cond
                               ((null default-dirname)
                                (list (or dir default-directory)))
                               ((consp default-dirname)
                                default-dirname)
                               (t
                                (list default-dirname)))
                              (project-known-project-roots))))
              (let ((ret (funcall orig-fun prompt dir default-dirname
                                  mustmatch initial)))
                (when (featurep 'project)
                  ;; Update project list with selected project dir
                  (let ((default-directory ret))
                    (project-current t)))
                ret))
            '((name . read-directory-name-project-defaults)))

(advice-add 'vc-dir :after
            (lambda (dir &optional _backend)
              (when (featurep 'project)
                ;; Add current vc project dir to project list
                (let ((default-directory dir))
                  (project-current t))))
            '((name . vc-dir-add-project)))
#+end_src