From 6f4690bba0073aadb45641f4f4bb293befdd0eb2 Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Tue, 15 Sep 2026 15:08:37 -0700 Subject: [PATCH] Add ~/Projects to C-x p p switcher --- emacs/init.el | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/emacs/init.el b/emacs/init.el index 9d099d6..f4e5d09 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -298,6 +298,9 @@ EMACS-ALTERNATIVE is the Emacs equivalent (e.g., 'C-s')." :init (vertico-mode) (vertico-multiform-mode 1) + ;; Preserve project.el's most-recently-used order in the project chooser. + (add-to-list 'vertico-multiform-commands + '(project-switch-project (vertico-sort-function . nil))) (add-to-list 'vertico-multiform-categories '(jinx grid (vertico-grid-annotate . 20)))) @@ -658,6 +661,7 @@ EMACS-ALTERNATIVE is the Emacs equivalent (e.g., 'C-s')." ;;;; Project (use-package project :custom + (project-prompter #'my/project-prompt) (project-switch-commands '((project-find-file "Find file") (consult-ripgrep "Ripgrep") @@ -666,7 +670,27 @@ EMACS-ALTERNATIVE is the Emacs equivalent (e.g., 'C-s')." (project-any-command "Other"))) :config ;; Make project.el recognize directories with a .project file as project roots - (add-to-list 'project-vc-extra-root-markers ".project")) + (add-to-list 'project-vc-extra-root-markers ".project") + + (defcustom my/project-search-path '("~/Projects/") + "Directories whose immediate children are scanned for projects." + :type '(repeat directory) + :group 'project) + + (defun my/project-refresh () + "Remember recognized projects directly under `my/project-search-path'." + (interactive) + (dolist (directory my/project-search-path) + (let ((directory (expand-file-name directory))) + (when (file-directory-p directory) + (project-remember-projects-under directory))))) + + (defun my/project-prompt (&optional prompt predicate require-known) + "Refresh known projects, then prompt using the standard project chooser. +Pass PROMPT, PREDICATE and REQUIRE-KNOWN through to the chooser." + (let ((inhibit-message t)) + (my/project-refresh)) + (project-prompt-project-dir prompt predicate require-known))) ;;;; hl-todo (use-package hl-todo