]> git.eshelyaron.com Git - emacs.git/commitdiff
Maintain a list of terminal buffers in the menu
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 18 Jul 2021 14:34:02 +0000 (16:34 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 18 Jul 2021 14:35:17 +0000 (16:35 +0200)
* lisp/term.el (term--update-term-menu): New function (bug#5641).
(term-mode): Use it to list terminal buffers.

lisp/term.el

index d41895ad3d91f8599219a28313439d447aa7e3c3..560549ece90bb9c213b61ae53556cc176b7f63cd 100644 (file)
@@ -864,8 +864,30 @@ is buffer-local."
     ["Paging" term-pager-toggle :style toggle :selected term-pager-count
      :help "Toggle paging feature"]))
 
+(defun term--update-term-menu (&optional force)
+  (when (and (lookup-key term-mode-map [menu-bar terminal])
+             (or force (frame-or-buffer-changed-p)))
+    (let ((buffer-list
+           (seq-filter
+            (lambda (buffer)
+              (provided-mode-derived-p (buffer-local-value 'major-mode buffer)
+                                       'term-mode))
+            (buffer-list))))
+      (easy-menu-change
+       '("Terminal")
+       "Terminal Buffers"
+       (mapcar
+        (lambda (buffer)
+          (vector (format "%s (%s)" (buffer-name buffer)
+                          (abbreviate-file-name
+                           (buffer-local-value 'default-directory buffer)))
+                  (lambda ()
+                    (interactive)
+                    (switch-to-buffer buffer))))
+        buffer-list)))))
+
 (easy-menu-define term-signals-menu
 (list term-mode-map term-raw-map term-pager-break-map)
+ (list term-mode-map term-raw-map term-pager-break-map)
   "Signals menu for Term mode."
   '("Signals"
     ["BREAK" term-interrupt-subjob :active t
@@ -1076,6 +1098,7 @@ Entry to this mode runs the hooks on `term-mode-hook'."
   (setq-local term-pending-delete-marker (make-marker))
   (make-local-variable 'term-current-face)
   (term-ansi-reset)
+  (add-hook 'menu-bar-update-hook 'term--update-term-menu)
   (setq-local term-pending-frame nil)
   ;; Cua-mode's keybindings interfere with the term keybindings, disable it.
   (setq-local cua-mode nil)