]> git.eshelyaron.com Git - emacs.git/commitdiff
(project-forget-project): Add minibuffer-action
authorEshel Yaron <me@eshelyaron.com>
Thu, 3 Apr 2025 16:46:08 +0000 (18:46 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 3 Apr 2025 16:46:08 +0000 (18:46 +0200)
lisp/progmodes/project.el

index 41ddcf6e49c3be0bd1a78004773256ce9a320ab6..19a77720e8087f4893f907e8fedc32174d98ef83 100644 (file)
@@ -1887,6 +1887,17 @@ the project list."
   (project--remove-from-project-list
    project-root "Project `%s' removed from known projects"))
 
+(put 'project-forget-project 'minibuffer-action
+     (cons
+      (lambda (name)
+        (project-forget-project
+         (or (get-text-property 0 'project-root name)
+             (seq-find (lambda (dir)
+                         (when-let ((proj (project-current nil dir)))
+                           (string= (project-name proj) name)))
+                       (project-known-project-roots)))))
+      "forget"))
+
 (defvar project--dir-history)
 
 (defun project-prompt-project-dir (&optional prompt)
@@ -1934,20 +1945,24 @@ sub-directory of `project-new-projects-directory' using the selected
 name as the initial input for completion, and return that directory."
   (let* ((current (project-current))
          (default (and current (project-name current)))
-         (name (completing-read (format-prompt (or prompt "Project") default)
-                                (lambda (string pred action)
-                                  (if (eq action 'metadata)
-                                      `(metadata (sort-function . minibuffer-sort-alphabetically))
-                                    (complete-with-action
-                                     action
-                                     (seq-keep (lambda (dir)
-                                                 (when-let ((proj (project-current nil dir)))
-                                                   (project-name proj)))
-                                               (project-known-project-roots))
-                                     string pred)))
-                                nil nil nil
-                                'project-name-history
-                                default)))
+         (name
+          (minibuffer-with-setup-hook
+              (lambda () (setq completion-max-replace-secs 0))
+            (completing-read (format-prompt (or prompt "Project") default)
+                             (lambda (string pred action)
+                               (if (eq action 'metadata)
+                                   `(metadata (sort-function . minibuffer-sort-alphabetically))
+                                 (complete-with-action
+                                  action
+                                  (seq-keep (lambda (dir)
+                                              (when-let ((proj (project-current nil dir))
+                                                         (name (project-name proj)))
+                                                (propertize name 'project-root dir)))
+                                            (project-known-project-roots))
+                                  string pred)))
+                             nil nil nil
+                             'project-name-history
+                             default))))
     (or (seq-find (lambda (dir)
                     (when-let ((proj (project-current nil dir)))
                       (string= (project-name proj) name)))