emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7479c11 1/4: Factor out project--read-project-buffer from project


From: Dmitry Gutov
Subject: master 7479c11 1/4: Factor out project--read-project-buffer from project-switch-buffer
Date: Sun, 26 Jul 2020 19:57:27 -0400 (EDT)

branch: master
commit 7479c11b4e73fcb9aa9d42788012b850ee3245c5
Author: Sean Whitton <spwhitton@spwhitton.name>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    Factor out project--read-project-buffer from project-switch-buffer
    
    * lisp/progmodes/project.el (project--read-project-buffer): New
    function extracted from project-switch-buffer.
    * lisp/progmodes/project.el (project-switch-buffer): Instead of
    unconditionally reading a project buffer from the user, add
    buffer-or-name argument, and populate it using
    project--read-project-buffer when called interactively.  Update
    docstring.
---
 lisp/progmodes/project.el | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 5cfc6a2..2bccd3f 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -877,14 +877,7 @@ Arguments the same as in `compile'."
          (default-directory (project-root pr)))
     (compile command comint)))
 
-;;;###autoload
-(defun project-switch-to-buffer ()
-  "Switch to another buffer belonging to the current project.
-This function prompts for another buffer, offering as candidates
-buffers that belong to the same project as the current buffer.
-Two buffers belong to the same project if their project instances,
-as reported by `project-current' in each buffer, are identical."
-  (interactive)
+(defun project--read-project-buffer ()
   (let* ((pr (project-current t))
          (current-buffer (current-buffer))
          (other-buffer (other-buffer current-buffer))
@@ -896,13 +889,22 @@ as reported by `project-current' in each buffer, are 
identical."
                  (equal pr
                         (with-current-buffer (cdr buffer)
                           (project-current)))))))
-    (switch-to-buffer
-     (read-buffer
-      "Switch to buffer: "
-      (when (funcall predicate (cons other-name other-buffer))
-        other-name)
-      nil
-      predicate))))
+    (read-buffer
+     "Switch to buffer: "
+     (when (funcall predicate (cons other-name other-buffer))
+       other-name)
+     nil
+     predicate)))
+
+;;;###autoload
+(defun project-switch-to-buffer (buffer-or-name)
+  "Display buffer BUFFER-OR-NAME in the selected window.
+When called interactively, prompts for a buffer belonging to the
+current project.  Two buffers belong to the same project if their
+project instances, as reported by `project-current' in each
+buffer, are identical."
+  (interactive (list (project--read-project-buffer)))
+  (switch-to-buffer buffer))
 
 (defcustom project-kill-buffers-ignores
   '("\\*Help\\*")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]