unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#65039: 30.0.50; [PATCH] Add bookmark handler for M-x shell
@ 2023-08-03 14:41 Protesilaos Stavrou
  2023-08-03 15:56 ` Eli Zaretskii
  2023-08-03 17:08 ` Visuwesh
  0 siblings, 2 replies; 20+ messages in thread
From: Protesilaos Stavrou @ 2023-08-03 14:41 UTC (permalink / raw)
  To: 65039

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

Dear maintainers,

I noticed that M-x shell does not have a bookmark handler like M-x
eshell does.  What do you think about the attached patch?

All the best,
Protesilaos (or simply "Prot")

-- 
Protesilaos Stavrou
https://protesilaos.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-bookmark-handler-for-M-x-shell.patch --]
[-- Type: text/x-patch, Size: 2603 bytes --]

From 69744f953b95dc2f3c9c3039324e121a6d664570 Mon Sep 17 00:00:00 2001
Message-ID: <69744f953b95dc2f3c9c3039324e121a6d664570.1691073443.git.info@protesilaos.com>
From: Protesilaos Stavrou <info@protesilaos.com>
Date: Thu, 3 Aug 2023 17:35:10 +0300
Subject: [PATCH] Add bookmark handler for M-x shell

* etc/NEWS: Anounce the new feature.
* lisp/shell.el (shell-mode): Add buffer-local 'bookmark-make-record-function'.
(bookmark-prop-get, shell-bookmark-name, shell-bookmark-make-record)
(shell-bookmark-jump): Add bookmark handler.
---
 etc/NEWS      |  6 ++++++
 lisp/shell.el | 26 ++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 7b521f3e6fe..da5d9b96002 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -286,6 +286,12 @@ When this user option is non-nil, 'shell-get-old-input' ('C-RET')
 includes multiple shell "\" continuation lines from command output.
 Default is nil.
 
+---
+*** Bookmark handler for 'shell' buffers
+Now the 'bookmark-set' command will record 'shell' buffers.  This
+means that 'bookmark-jump' will create the 'shell' buffer in the
+directory it was in.
+
 ** Prog Mode
 
 +++
diff --git a/lisp/shell.el b/lisp/shell.el
index 0a24b4ea4c2..bdf8eb17fbd 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -676,6 +676,7 @@ (define-derived-mode shell-mode comint-mode "Shell"
 
   (setq comint-prompt-regexp shell-prompt-pattern)
   (shell-completion-vars)
+  (setq-local bookmark-make-record-function #'shell-bookmark-make-record)
   (setq-local paragraph-separate "\\'")
   (setq-local paragraph-start comint-prompt-regexp)
   (setq-local font-lock-defaults '(shell-font-lock-keywords t))
@@ -1812,6 +1813,31 @@ (defun shell-highlight-undef-mode-restart ()
   (when shell-highlight-undef-mode
     (shell-highlight-undef-mode 1)))
 
+;;; Bookmark support
+
+;; Adapted from esh-mode.el
+(declare-function bookmark-prop-get "bookmark" (bookmark prop))
+
+(defun shell-bookmark-name ()
+  (format "shell-%s"
+          (file-name-nondirectory
+           (directory-file-name
+            (file-name-directory default-directory)))))
+
+(defun shell-bookmark-make-record ()
+  "Create a bookmark for the current Shell buffer."
+  `(,(shell-bookmark-name)
+    (location . ,default-directory)
+    (handler . shell-bookmark-jump)))
+
+;;;###autoload
+(defun shell-bookmark-jump (bookmark)
+  "Default bookmark handler for Shell buffers."
+  (let ((default-directory (bookmark-prop-get bookmark 'location)))
+    (shell)))
+
+(put 'shell-bookmark-jump 'bookmark-handler-type "Shell")
+
 (provide 'shell)
 
 ;;; shell.el ends here
-- 
2.41.0


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

end of thread, other threads:[~2023-09-18  5:28 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-03 14:41 bug#65039: 30.0.50; [PATCH] Add bookmark handler for M-x shell Protesilaos Stavrou
2023-08-03 15:56 ` Eli Zaretskii
2023-08-04  9:17   ` Protesilaos Stavrou
2023-08-04 10:32     ` Eli Zaretskii
2023-08-04 14:06       ` Protesilaos Stavrou
2023-08-05  9:18         ` Eli Zaretskii
2023-09-03 11:15           ` Stefan Kangas
2023-09-03 11:42             ` Eli Zaretskii
2023-09-05  4:39             ` Protesilaos Stavrou
2023-09-05  6:17               ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18  5:28                 ` Protesilaos Stavrou
2023-08-04 14:35       ` Drew Adams
2023-08-03 17:08 ` Visuwesh
2023-08-04  9:20   ` Protesilaos Stavrou
2023-08-04 13:01     ` Visuwesh
2023-08-04 14:13       ` Protesilaos Stavrou
2023-08-04 14:35         ` Visuwesh
2023-08-11  4:55           ` Protesilaos Stavrou
2023-08-04 17:01     ` Jim Porter
2023-08-06  4:43       ` Protesilaos Stavrou

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).