From: Ackerley Tng <ackerleytng@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: juri@linkov.net, 59381@debbugs.gnu.org, Dmitry Gutov <dgutov@yandex.ru>
Subject: bug#59381: Should xref--marker-ring be per-window?
Date: Mon, 21 Nov 2022 18:46:07 -0800 [thread overview]
Message-ID: <CANZnma7AU7wb6O30ppVW6uZmqaErOhCU1AirSx6QRVPARuwX5A@mail.gmail.com> (raw)
In-Reply-To: <838rk44fgg.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 3112 bytes --]
Here's a patch for review!
I made 'window-local the default storage so that we would hopefully
get more feedback, do let me know if I should leave the default as
'global.
On Mon, Nov 21, 2022 at 5:14 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > Date: Mon, 21 Nov 2022 01:17:02 +0200
> > Cc: 59381@debbugs.gnu.org, ackerleytng@gmail.com, juri@linkov.net
> > From: Dmitry Gutov <dgutov@yandex.ru>
> >
> > On 20.11.2022 09:59, Eli Zaretskii wrote:
> >
> > >> But maybe it will be helpful for you to elaborate: what the workflow
> > >> would look like. Would it be a parallel set of commands, or simply a
> > >> command to... do what?
> > >
> > > I just did that, above: add a command that starts a new "stack". All the
> > > rest is unchanged.
> >
> > What would happen with the current stack, though?
>
> It's discarded, as no longer needed.
>
> > Or does it apply to the current window? What about the windows split
> > from it? What about older windows we decide to pop-to-buffer to from one
> > of the new windows?
>
> In my mental picture, the stack is not specific to a window, like it is
> today.
>
> > >> In my workflow, a new stack is more or less created implicitly by
> > >> splitting a window, and discarded by deleting one.
> > >
> > > So you always ever have a given buffer displayed in a single window?
> >
> > Not necessarily, no. If it's a big file, I can have two parallel
> > "investigations" going on in two different window on it. Using two
> > different navigation stacks. That's a feature.
>
> It's a feature if you indeed want a separate stack in each window. What if
> you want the same stack in all of those windows?
>
> > Whether M-. pop a new window, or you use project-find-regexp, we usually
> > make sure that after you navigate to a location, it's displayed in the
> > same window the search was made in. Unless the user called something
> > like xref-find-definitions-other-window, naturally.
> >
> > So it's generally possible to stay within the same window most of the time.
>
> Not if I split that one window because I want to look at something else as
> well.
>
> > And you make good points: Emacs often makes you go from a window to a
> > window, reusing older windows as well. So I'm not sure how to solve that
> > better: searching the window hierarchy won't help.
> >
> > So it could be some propagation mechanism working when windows are split
> > or buffers get displayed, which would nevertheless leave a window when
> > the user pressed 'q', for instance. Reverting the window to its previous
> > stack, let's say. And as for separate command, using it explicitly by
> > itself is easy to forget, but it perhaps could be added to some other
> > commands by the user (via before-advice or etc), to mark the beginning
> > of each stack.
> >
> > This is a very rough idea. There's nobody to work on it in the near
> > future, I'm afraid, so adding an optional change in behavior to use
> > window-local storage is probably the best way forward. To get feedback,
> > as Ackerley said.
>
> When this becomes practical, we could try it and see if enough people like
> it.
[-- Attachment #2: 0001-Add-support-for-window-local-xref-history.patch --]
[-- Type: text/x-patch, Size: 6361 bytes --]
From 3297a0ff016394dbb775caeb194d15c754a238dc Mon Sep 17 00:00:00 2001
From: Ackerley Tng <ackerleytng@google.com>
Date: Mon, 21 Nov 2022 18:38:03 -0800
Subject: [PATCH] Add support for window-local xref history
---
lisp/progmodes/xref.el | 106 ++++++++++++++++++++++++++++-------------
1 file changed, 74 insertions(+), 32 deletions(-)
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 89a090ae93..122bf55541 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -427,32 +427,71 @@ xref-auto-jump-to-first-xref
:version "28.1"
:package-version '(xref . "1.2.0"))
+(defcustom xref-storage-type 'window-local
+ "How xref history is stored.
+
+Before Emacs 29.1, xref history is stored at the global level, so
+the same history is used across the entire Emacs instance.
+
+In Emacs 29.1 the new default is to have one xref history per
+window, which allows you to navigate code independently in
+different windows.
+
+A new xref history is created for every new window."
+ :type '(choice
+ (const :tag "Per-window" window-local)
+ (const :tag "Global history for Emacs instance" global))
+ :version "29.1"
+ :package-version '(xref . "1.5.1"))
+
(make-obsolete-variable 'xref--marker-ring 'xref--history "29.1")
(defun xref-set-marker-ring-length (_var _val)
(declare (obsolete nil "29.1"))
nil)
-(defvar xref--history (cons nil nil)
+(defun xref--make-xref-history ()
+ "Return a new xref history."
+ (cons nil nil))
+
+(defvar xref--history (xref--make-xref-history)
"(BACKWARD-STACK . FORWARD-STACK) of markers to visited Xref locations.")
+(defun xref--get-or-create-window-xref-history ()
+ "Return the xref history for the selected window.
+
+Create an xref history and return it if it did not already exist."
+ (let ((w (selected-window)))
+ (if-let ((r (window-parameter w 'xref--window-xref-history))) r
+ (let ((h (xref--make-xref-history)))
+ (set-window-parameter w 'xref--window-xref-history h)))))
+
+(defun xref--get-history ()
+ "Return xref history based on `xref-storage-type'."
+ (cl-case xref-storage-type
+ (window-local (xref--get-or-create-window-xref-history))
+ (global xref--history)))
+
(defun xref--push-backward (m)
"Push marker M onto the backward history stack."
- (unless (equal m (caar xref--history))
- (push m (car xref--history))))
+ (let ((history (xref--get-history)))
+ (unless (equal m (caar history))
+ (push m (car history)))))
(defun xref--push-forward (m)
"Push marker M onto the forward history stack."
- (unless (equal m (cadr xref--history))
- (push m (cdr xref--history))))
+ (let ((history (xref--get-history)))
+ (unless (equal m (cadr history))
+ (push m (cdr history)))))
(defun xref-push-marker-stack (&optional m)
"Add point M (defaults to `point-marker') to the marker stack.
The future stack is erased."
(xref--push-backward (or m (point-marker)))
- (dolist (mk (cdr xref--history))
- (set-marker mk nil nil))
- (setcdr xref--history nil))
+ (let ((history (xref--get-history)))
+ (dolist (mk (cdr history))
+ (set-marker mk nil nil))
+ (setcdr history nil)))
;;;###autoload
(define-obsolete-function-alias 'xref-pop-marker-stack #'xref-go-back "29.1")
@@ -462,29 +501,31 @@ xref-go-back
"Go back to the previous position in xref history.
To undo, use \\[xref-go-forward]."
(interactive)
- (if (null (car xref--history))
- (user-error "At start of xref history")
- (let ((marker (pop (car xref--history))))
- (xref--push-forward (point-marker))
- (switch-to-buffer (or (marker-buffer marker)
- (user-error "The marked buffer has been deleted")))
- (goto-char (marker-position marker))
- (set-marker marker nil nil)
- (run-hooks 'xref-after-return-hook))))
+ (let ((history (xref--get-history)))
+ (if (null (car history))
+ (user-error "At start of xref history")
+ (let ((marker (pop (car history))))
+ (xref--push-forward (point-marker))
+ (switch-to-buffer (or (marker-buffer marker)
+ (user-error "The marked buffer has been deleted")))
+ (goto-char (marker-position marker))
+ (set-marker marker nil nil)
+ (run-hooks 'xref-after-return-hook)))))
;;;###autoload
(defun xref-go-forward ()
"Got to the point where a previous \\[xref-go-back] was invoked."
(interactive)
- (if (null (cdr xref--history))
- (user-error "At end of xref history")
- (let ((marker (pop (cdr xref--history))))
- (xref--push-backward (point-marker))
- (switch-to-buffer (or (marker-buffer marker)
- (user-error "The marked buffer has been deleted")))
- (goto-char (marker-position marker))
- (set-marker marker nil nil)
- (run-hooks 'xref-after-return-hook))))
+ (let ((history (xref--get-history)))
+ (if (null (cdr history))
+ (user-error "At end of xref history")
+ (let ((marker (pop (cdr history))))
+ (xref--push-backward (point-marker))
+ (switch-to-buffer (or (marker-buffer marker)
+ (user-error "The marked buffer has been deleted")))
+ (goto-char (marker-position marker))
+ (set-marker marker nil nil)
+ (run-hooks 'xref-after-return-hook)))))
(define-obsolete-variable-alias
'xref--current-item
@@ -510,22 +551,23 @@ xref-pulse-momentarily
;; etags.el needs this
(defun xref-clear-marker-stack ()
"Discard all markers from the xref history."
- (dolist (l (list (car xref--history) (cdr xref--history)))
- (dolist (m l)
- (set-marker m nil nil)))
- (setq xref--history (cons nil nil))
+ (let ((history (xref--get-history)))
+ (dolist (l (list (car history) (cdr history)))
+ (dolist (m l)
+ (set-marker m nil nil)))
+ (setq history (cons nil nil)))
nil)
;;;###autoload
(defun xref-marker-stack-empty-p ()
"Whether the xref back-history is empty."
- (null (car xref--history)))
+ (null (car (xref--get-history))))
;; FIXME: rename this to `xref-back-history-empty-p'.
;;;###autoload
(defun xref-forward-history-empty-p ()
"Whether the xref forward-history is empty."
- (null (cdr xref--history)))
+ (null (cdr (xref--get-history))))
\f
(defun xref--goto-char (pos)
--
2.38.1
next prev parent reply other threads:[~2022-11-22 2:46 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-19 5:29 bug#59381: Should xref--marker-ring be per-window? Ackerley Tng
2022-11-19 18:53 ` Juri Linkov
2022-11-19 19:53 ` Eli Zaretskii
2022-11-19 22:01 ` Ackerley Tng
2022-11-20 7:09 ` Eli Zaretskii
2022-11-20 17:00 ` Dmitry Gutov
2022-11-20 17:32 ` Eli Zaretskii
2022-11-20 18:11 ` Ackerley Tng
2022-11-20 18:22 ` Eli Zaretskii
2022-11-20 23:01 ` Dmitry Gutov
2022-11-21 7:42 ` Juri Linkov
2022-11-24 3:16 ` Dmitry Gutov
2022-11-20 2:52 ` Dmitry Gutov
2022-11-20 7:59 ` Eli Zaretskii
2022-11-20 23:17 ` Dmitry Gutov
2022-11-21 13:14 ` Eli Zaretskii
2022-11-22 2:46 ` Ackerley Tng [this message]
2022-11-24 3:28 ` Dmitry Gutov
2022-11-24 14:17 ` Dmitry Gutov
2022-11-24 23:42 ` Ackerley Tng
2022-11-24 23:59 ` Dmitry Gutov
2022-11-25 0:28 ` Ackerley Tng
2022-11-25 1:02 ` Dmitry Gutov
2022-11-24 3:19 ` Dmitry Gutov
2022-11-24 7:30 ` Eli Zaretskii
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=CANZnma7AU7wb6O30ppVW6uZmqaErOhCU1AirSx6QRVPARuwX5A@mail.gmail.com \
--to=ackerleytng@gmail.com \
--cc=59381@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
--cc=eliz@gnu.org \
--cc=juri@linkov.net \
/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).