unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Protesilaos Stavrou <info@protesilaos.com>
To: 65039@debbugs.gnu.org
Subject: bug#65039: 30.0.50; [PATCH] Add bookmark handler for M-x shell
Date: Thu, 03 Aug 2023 17:41:27 +0300	[thread overview]
Message-ID: <877cqcw5m0.fsf@protesilaos.com> (raw)

[-- 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


             reply	other threads:[~2023-08-03 14:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03 14:41 Protesilaos Stavrou [this message]
2023-08-03 15:56 ` bug#65039: 30.0.50; [PATCH] Add bookmark handler for M-x shell 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877cqcw5m0.fsf@protesilaos.com \
    --to=info@protesilaos.com \
    --cc=65039@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).