From: Eshel Yaron Date: Tue, 11 Apr 2023 16:50:39 +0000 (+0300) Subject: Tweak esy/read-project-by-name X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=42d80e822cd6d07d88484d2e30eaca6b130dc052;p=dotfiles.git Tweak esy/read-project-by-name --- diff --git a/.emacs.d/init.el b/.emacs.d/init.el index e30b9cf..4e3ee05 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -341,7 +341,7 @@ completions-detailed nil completion-styles '(orderless partial-completion basic) completion-show-help nil - completions-header-format (propertize "%s candidates:\n" 'face 'shadow) + completions-header-format nil completion-auto-help 'visual completions-max-height 16 completion-auto-wrap t @@ -362,8 +362,7 @@ ;; use relative line numbers display-line-numbers-type 'relative ;; persist Git commit message history - savehist-additional-variables '(log-edit-comment-ring - esy/project-name-history) + savehist-additional-variables '(log-edit-comment-ring) ;; IRC stuff rcirc-default-nick "eshel" rcirc-server-alist '(("irc.libera.chat" @@ -693,15 +692,17 @@ (defvar esy/projects-directory "~/checkouts/") - (defun esy/project-names () - "Return an alist of known project names and their root directories." - (mapcar (lambda (dir) - (cons (project-name (project-current nil dir)) dir)) - (project-known-project-roots))) - (defun esy/read-project-by-name () - "Read a known project name and return its root directory." - (let* ((name-dir-alist (esy/project-names)) + "Read a project name and return its root directory. + +If no known project matches the selected name, prompt for a +sub-directory of `esy/projects-directory' using the selected name +as the initial input for completion, and return that directory." + (let* ((name-dir-alist + (mapcar (lambda (dir) + (cons (project-name (project-current nil dir)) + dir)) + (project-known-project-roots))) (current (project-current)) (default (and current (project-name current))) (name (completing-read (format-prompt "Project" default) @@ -713,9 +714,8 @@ (let* ((dir (read-directory-name "Project root directory: " esy/projects-directory nil t name)) - (dir-project (project-current nil dir))) - (when dir-project - (project-remember-project dir-project)) + (project (project-current nil dir))) + (when project (project-remember-project project)) dir)))))) (esy/init-step sql