all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#41879: 28.0.50; [Patch]: Add project-switch-to-buffer in project.el
@ 2020-06-15 17:45 Theodor Thornhill
  2020-06-15 18:29 ` Philip K.
                   ` (3 more replies)
  0 siblings, 4 replies; 47+ messages in thread
From: Theodor Thornhill @ 2020-06-15 17:45 UTC (permalink / raw)
  To: 41879

[-- Attachment #1: Type: text/plain, Size: 741 bytes --]


Hello!

This patch is directly dependent on https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41868
since I reused one of the functions added by Philip K.

For now I rely on that report to be resolved before this.

However, attached is a patch for project-switch-to-buffer, where only file-bound buffers are included. I believe the function should be kind of self explanatory.

I use this daily, but stole the buffer list function since it was better than my initial one, and seems to be accepted soon :)

I find this useful, and hope others will as well. I bind it myself to 'C-x p b'.

The 'project--list-buffers' will not be part of the final patch, but I wanted to provide it so that you have a working example.

Theodor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: project-switch-to-buffer.patch --]
[-- Type: text/x-patch; name=project-switch-to-buffer.patch, Size: 1283 bytes --]

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 218058b195..65f3285705 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -753,6 +753,35 @@ project-compile
          (default-directory (project-root pr)))
     (compile command comint)))
 
+(defun project--list-buffers (pr)
+  "Return a list of all buffers in project PR."
+  (let ((root (project-root pr))
+        bufs)
+    (dolist (buf (buffer-list))
+      (when-let* ((path (or (buffer-file-name buf)
+                            (buffer-local-value 'default-directory buf)))
+                  (true (file-truename path)))
+        (when (file-in-directory-p true root)
+          (push buf bufs))))
+    bufs))
+
+(defun project--buffer-file-names (pr)
+  "Return the buffers in project PR associated with a file."
+  (mapcar #'buffer-name
+          (cl-remove-if-not
+           (lambda (buffer) (buffer-file-name buffer))
+           (project--list-buffers pr))))
+
+;;;###autoload
+(defun project-switch-to-buffer ()
+  "Switch to a buffer in the current project."
+  (interactive)
+  (let ((pr (project-current t)))
+    (switch-to-buffer
+     (project--completing-read-strict
+      "Switch to buffer"
+      (project--buffer-file-names pr)))))
+
 \f
 ;;; Project list
 

^ permalink raw reply related	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2020-06-22 14:59 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-15 17:45 bug#41879: 28.0.50; [Patch]: Add project-switch-to-buffer in project.el Theodor Thornhill
2020-06-15 18:29 ` Philip K.
2020-06-15 20:55 ` Dmitry Gutov
2020-06-15 22:05   ` Theodor Thornhill
2020-06-15 23:38     ` Dmitry Gutov
2020-06-16  5:45       ` Theodor Thornhill
2020-06-16  6:11         ` Philip K.
2020-06-16  6:49           ` Theodor Thornhill
2020-06-16 10:26             ` Basil L. Contovounesios
2020-06-16 13:29               ` Theodor Thornhill
2020-06-16 14:02                 ` Basil L. Contovounesios
2020-06-16 16:53                   ` Theodor Thornhill
2020-06-16 18:19                     ` Basil L. Contovounesios
2020-06-16 18:58                       ` Theodor Thornhill
2020-06-16 20:37                         ` Basil L. Contovounesios
2020-06-16 22:39                         ` Dmitry Gutov
2020-06-17 23:10                         ` Dmitry Gutov
2020-06-16 21:40                       ` Dmitry Gutov
2020-06-16 21:58                         ` Basil L. Contovounesios
2020-06-16 22:11                           ` Dmitry Gutov
2020-06-15 23:10 ` Juri Linkov
2020-06-16  0:21   ` Dmitry Gutov
2020-06-18  9:41 ` Andrii Kolomoiets
2020-06-18 10:11   ` Theodor Thornhill
2020-06-18 10:26   ` Theodor Thornhill
2020-06-18 10:31   ` Theodor Thornhill
2020-06-18 10:48     ` Andrii Kolomoiets
2020-06-18 11:07       ` Dmitry Gutov
2020-06-18 11:30         ` Andrii Kolomoiets
2020-06-18 11:35           ` Dmitry Gutov
2020-06-18 11:47             ` Andrii Kolomoiets
2020-06-18 13:00               ` Dmitry Gutov
2020-06-18 18:03       ` Andrii Kolomoiets
2020-06-18 18:49         ` Theodor Thornhill
2020-06-18 19:35           ` Basil L. Contovounesios
2020-06-19  0:43             ` Dmitry Gutov
2020-06-19  4:50           ` Andrii Kolomoiets
2020-06-19  0:45         ` Dmitry Gutov
2020-06-19  4:59           ` Andrii Kolomoiets
2020-06-19  5:27             ` Theodor Thornhill
2020-06-19 11:00             ` Dmitry Gutov
2020-06-20  8:35               ` Andrii Kolomoiets
2020-06-21  1:04                 ` Dmitry Gutov
2020-06-22  9:30                   ` Andrii Kolomoiets
2020-06-22 13:46                     ` Dmitry Gutov
2020-06-22 13:54                       ` Andrii Kolomoiets
2020-06-22 14:59                         ` Dmitry Gutov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.