all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Protesilaos Stavrou <info@protesilaos.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 65039@debbugs.gnu.org
Subject: bug#65039: 30.0.50; [PATCH] Add bookmark handler for M-x shell
Date: Fri, 04 Aug 2023 17:06:59 +0300	[thread overview]
Message-ID: <871qgisxz0.fsf@protesilaos.com> (raw)
In-Reply-To: <834jlfw116.fsf@gnu.org>

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

> From: Eli Zaretskii <eliz@gnu.org>
> Date: Fri,  4 Aug 2023 13:32:37 +0300
>
>> From: Protesilaos Stavrou <info@protesilaos.com>
>> Cc: 65039@debbugs.gnu.org
>> Date: Fri, 04 Aug 2023 12:17:43 +0300
>> 
>> > I'll let users of bookmarks comment, but in any case, please also
>> > check that the section "Bookmarks" in the Emacs user manual doesn't
>> > need some update due to this feature.  (You marked the NEWS entry with
>> > "---", which might mean you already checked that, but I'm not sure.)
>> 
>> I thought a change was not necessary.  Though I am happy to do it, if
>> needed.
>
> It sounds like the notion of "jumping" to a bookmark has evolved, and
> nowadays jumping to a bookmark might do much more than just jump to a
> buffer position.  Perhaps that node in the manual should say something
> about that, and show a couple of examples?

The revised patch includes a possible update to the manual.  Are those
examples sufficient?

-- 
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: 3519 bytes --]

From 4c903061803f7e41cc4f87f80b1b089c2174cc21 Mon Sep 17 00:00:00 2001
Message-ID: <4c903061803f7e41cc4f87f80b1b089c2174cc21.1691157813.git.info@protesilaos.com>
From: Protesilaos Stavrou <info@protesilaos.com>
Date: Fri, 4 Aug 2023 17:03:08 +0300
Subject: [PATCH] Add bookmark handler for M-x shell

* doc/emacs/regs.texi (Bookmarks): Explain that 'bookmark-jump'
establishes a remote connection.
* etc/NEWS: Announce the new feature.
* lisp/shell.el (shell-mode): Add buffer-local value for 'bookmark-make-record-function'.
(bookmark-prop-get, shell-bookmark-name, shell-bookmark-make-record)
(shell-bookmark-jump): Add section about the bookmark handler.
---
 doc/emacs/regs.texi |  6 ++++++
 etc/NEWS            |  6 ++++++
 lisp/shell.el       | 26 ++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/doc/emacs/regs.texi b/doc/emacs/regs.texi
index e52f68dd18e..2debf9988c2 100644
--- a/doc/emacs/regs.texi
+++ b/doc/emacs/regs.texi
@@ -391,6 +391,12 @@ many characters of context to record on each side of the bookmark's
 position.  (In buffers that are visiting encrypted files, no context
 is saved in the bookmarks file no matter the value of this variable.)
 
+  If the bookmark is stored in a remote location, @code{bookmark-jump}
+will establish the connection and then create the buffer.  This works
+with regular files, as well as the buffers of @kbd{M-x dired} and
+@kbd{M-x shell}.  @xref{Top, The Tramp Manual,, tramp, The Tramp
+Manual}.
+
   Here are some additional commands for working with bookmarks:
 
 @table @kbd
diff --git a/etc/NEWS b/etc/NEWS
index 7b521f3e6fe..6329165cda2 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-04 14:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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

  git send-email \
    --in-reply-to=871qgisxz0.fsf@protesilaos.com \
    --to=info@protesilaos.com \
    --cc=65039@debbugs.gnu.org \
    --cc=eliz@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 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.