emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/bufferlo 175674d755 1/4: Add functions to find tabs/fra


From: ELPA Syncer
Subject: [elpa] externals/bufferlo 175674d755 1/4: Add functions to find tabs/frames containig specific buffers
Date: Sun, 19 Nov 2023 15:57:24 -0500 (EST)

branch: externals/bufferlo
commit 175674d755999433abe9399bb30340612e4d1a3e
Author: Florian Rommel <mail@florommel.de>
Commit: Florian Rommel <mail@florommel.de>

    Add functions to find tabs/frames containig specific buffers
---
 README.org  |  5 +++++
 bufferlo.el | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/README.org b/README.org
index 6e5cbe6e07..c10e6d35f1 100644
--- a/README.org
+++ b/README.org
@@ -77,6 +77,11 @@ Bufferlo provides functions to manage the local buffer lists:
   Close the tab and kill all its local buffers.
 - ~bufferlo-isolate-project~:
   Isolate a project in the frame or tab.
+- ~bufferlo-find-buffer~:
+  Switch to (one of) the frame/tab that contains the buffer in its local list.
+- ~bufferlo-find-buffer-switch~:
+  Switch to (one of) the frame/tab that contains the buffer in its local list,
+  and select the buffer.
 
 
 ** Consult Integration
diff --git a/bufferlo.el b/bufferlo.el
index f8373ca5d9..daa96dbf78 100644
--- a/bufferlo.el
+++ b/bufferlo.el
@@ -519,6 +519,80 @@ Buffers matching `bufferlo-include-buffer-filters' are not 
removed."
             (bufferlo-remove buffer)))
       (message "Current buffer is not part of a project"))))
 
+(defun bufferlo-find-buffer (buffer-or-name)
+  "Switch to the frame/tab containing BUFFER-OR-NAME in its local list.
+If multiple frame or tabs contain the buffer, interactively prompt
+for the to-be-selected frame and tab.
+This does not select the buffer -- just the containing frame and tab."
+  (interactive "b")
+  (let* ((buffer (get-buffer buffer-or-name))
+         (flatten (lambda (list)
+                    (apply #'append (append list '()))))
+         (search-tabs (lambda (f)
+                        (let ((i 0))
+                          (mapcar
+                           (lambda (tab)
+                             (setq i (1+ i))
+                             (when (bufferlo-local-buffer-p buffer f (1- i) t)
+                               (list f (frame-parameter f 'name)
+                                     (eq f (selected-frame))
+                                     i (cdr (assq 'name tab)))))
+                           (frame-parameter f 'tabs)))))
+         (search-frames (lambda (f)
+                          (unless (frame-parameter f 'no-accept-focus)
+                            (if (frame-parameter f 'tabs)
+                                ;; has tabs
+                                (funcall search-tabs f)
+                              ;; has no tabs
+                              (when (bufferlo-local-buffer-p buffer f nil t)
+                                (list (list f (frame-parameter f 'name)
+                                            (eq f (selected-frame))
+                                            nil nil)))))))
+         (candidates (seq-filter 'identity
+                                 (funcall flatten
+                                          (mapcar
+                                           (lambda (f)
+                                             (funcall search-frames f))
+                                           (frame-list)))))
+         (candidates (mapcar
+                      (lambda (c)
+                        (let ((sel (if (nth 2 c) " [this]" ""))
+                              (frame-name (nth 1 c))
+                              (frame-obj  (nth 0 c))
+                              (tab-index  (nth 3 c))
+                              (tab-name   (nth 4 c)))
+                          (if tab-index
+                              (cons (format "Frame: %s (%s)%s  Tab %s: %s"
+                                            frame-name frame-obj sel
+                                            tab-index tab-name)
+                                    c)
+                            (cons (format "Frame: %s (%s)%s"
+                                          frame-name frame-obj sel)
+                                  c))))
+                      candidates))
+         (selected (if (cdr candidates)
+                       (completing-read
+                        "Select frame/tab: "
+                        candidates
+                        nil t)
+                     (caar candidates)))
+         (selected (assoc selected candidates)))
+    (if (not selected)
+        (message "Orphan: No frame/tab contains buffer '%s'" (buffer-name 
buffer))
+      (let ((frame (nth 1 selected))
+            (tab-index (nth 4 selected)))
+        (select-frame-set-input-focus frame)
+        (when tab-index
+          (tab-bar-select-tab tab-index))
+        frame))))
+
+(defun bufferlo-find-buffer-switch (buffer-or-name)
+  "Switch to the frame/tab containig BUFFER-OR-NAME and select the buffer.
+This is like `bufferlo-find-buffer' but additionally selects the buffer."
+  (interactive "b")
+  (when (bufferlo-find-buffer buffer-or-name)
+    (switch-to-buffer buffer-or-name)))
+
 (defun bufferlo-switch-to-buffer (buffer &optional norecord force-same-window)
   "Display the BUFFER in the selected window.
 Completion includes only local buffers.



reply via email to

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