]> git.eshelyaron.com Git - dotfiles.git/commitdiff
Tweak esy/read-project-by-name
authorEshel Yaron <me@eshelyaron.com>
Tue, 11 Apr 2023 16:50:39 +0000 (19:50 +0300)
committerEshel Yaron <me@eshelyaron.com>
Tue, 11 Apr 2023 18:00:50 +0000 (21:00 +0300)
.emacs.d/init.el

index e30b9cfdcad23922495384df01c8646d9f01e00f..4e3ee05246ea6e78b518c470d8f046df6d608c1c 100644 (file)
    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
    ;; 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"
 
     (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)
             (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