From: Ackerley Tng <ackerleytng@gmail.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Eli Zaretskii <eliz@gnu.org>, juri@linkov.net, 59381@debbugs.gnu.org
Subject: bug#59381: Should xref--marker-ring be per-window?
Date: Thu, 24 Nov 2022 15:42:19 -0800 [thread overview]
Message-ID: <CANZnma79oc5HLRJJdHGN7QMR7s5edAW9eaPPYH87JOFZj-ju+g@mail.gmail.com> (raw)
In-Reply-To: <90fccc99-14e1-80f7-5179-62c44c1833b8@yandex.ru>
[-- Attachment #1: Type: text/plain, Size: 340 bytes --]
> (defcustom xref-history-storage 'xref-window-local-history
Here's an updated patch!
On Thu, Nov 24, 2022 at 6:17 AM Dmitry Gutov <dgutov@yandex.ru> wrote:
>
> On 24/11/22 05:28, Dmitry Gutov wrote:
> > (defcustom xref-storage-type 'xref-window-local-history
>
> Or rather:
>
> (defcustom xref-history-storage 'xref-window-local-history
[-- Attachment #2: 0001-Add-support-for-window-local-xref-history.patch --]
[-- Type: text/x-patch, Size: 6669 bytes --]
From 4c89685dc6d32389d7f2a9053670a17511b83b29 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 | 115 +++++++++++++++++++++++++++++------------
1 file changed, 83 insertions(+), 32 deletions(-)
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index e220367a21..6f11d6f4d4 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -429,32 +429,80 @@ xref-auto-jump-to-first-xref
:version "28.1"
:package-version '(xref . "1.2.0"))
+(defcustom xref-history-storage #'xref-window-local-history
+ "Function that returns xref history.
+
+The following functions are predefined:
+
+- `xref-global-history'
+ Return a single, global history used across the entire Emacs
+ instance.
+- `xref-window-local-history'
+ Return different xref histories, one per window. Allows you
+ to navigate code independently in different windows. A new
+ xref history is created for every new window."
+ :type '(radio
+ (function-item :tag "Per-window" xref-window-local-history)
+ (function-item :tag "Global history for Emacs instance" xref-global-history)
+ (function :tag "Other"))
+ :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-global-history (&optional new-value)
+ "Return the xref history global to this Emacs instance.
+
+Override existing value with NEW-VALUE if NEW-VALUE is set."
+ (if new-value
+ (setq xref--history new-value)
+ xref--history))
+
+(defun xref-window-local-history (&optional new-value)
+ "Return window-local xref history.
+
+Override existing value with NEW-VALUE if NEW-VALUE is set."
+ (let ((w (selected-window)))
+ (if new-value
+ (set-window-parameter w 'xref--history new-value)
+ (or (window-parameter w 'xref--history)
+ (set-window-parameter w 'xref--history (xref--make-xref-history))))))
+
+(defun xref--get-history ()
+ "Return xref history using xref-history-storage."
+ (funcall xref-history-storage))
+
(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")
@@ -464,29 +512,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
@@ -512,22 +562,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-24 23:42 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
2022-11-24 3:28 ` Dmitry Gutov
2022-11-24 14:17 ` Dmitry Gutov
2022-11-24 23:42 ` Ackerley Tng [this message]
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=CANZnma79oc5HLRJJdHGN7QMR7s5edAW9eaPPYH87JOFZj-ju+g@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).