* bug#73293: [PATCH] Add buffer-local register commands to doc-view
@ 2024-09-16 12:10 Visuwesh
2024-09-21 10:28 ` Eli Zaretskii
2024-09-28 9:13 ` Eli Zaretskii
0 siblings, 2 replies; 4+ messages in thread
From: Visuwesh @ 2024-09-16 12:10 UTC (permalink / raw)
To: 73293
[-- Attachment #1: Type: text/plain, Size: 801 bytes --]
Attached patch adds buffer-local registers to doc-view-mode. I have
opted to make the registers buffer-local since I personally use the same
mnemonic to save pages to the register in multiple buffers. It is
something like folding a page or placing a pen in between to quickly go
to-and-fro between those pages.
In GNU Emacs 31.0.50 (build 7, x86_64-pc-linux-gnu, X toolkit, cairo
version 1.18.0, Xaw scroll bars) of 2024-09-09 built on astatine
Repository revision: 7d7aa65f63db78c5732f1580213fc3767b767a4a
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101011
System Description: Debian GNU/Linux trixie/sid
Configured using:
'configure --with-sound=alsa --with-x-toolkit=lucid --without-xaw3d
--without-gconf --without-libsystemd --with-cairo'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-buffer-local-register-commands-to-doc-view.patch --]
[-- Type: text/patch, Size: 5021 bytes --]
From 415f3ba0ad07f113858eaa45b60b9bd66b09c7da Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Sun, 15 Sep 2024 13:56:21 +0530
Subject: [PATCH] Add buffer-local register commands to doc-view
* lisp/doc-view.el (doc-view-register-alist): New defvar to keep
track of buffer-local register-alist.
(doc-view-page-to-register, doc-view-jump-to-register): Add new
commands to set and jump to buffer-local registers.
(register-val-insert, register-val-describe)
(register-val-jump-to): Register defmethod to save and restore
doc-view registers.
(doc-view-mode-map): Bind the new commands.
* doc/emacs/misc.texi (DocView Navigation): Document the new
commands.
* etc/NEWS: Announce the change.
---
doc/emacs/misc.texi | 10 +++++++++
etc/NEWS | 6 +++++
lisp/doc-view.el | 54 ++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index eb157c146e7..e19e554fb26 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -593,6 +593,16 @@ DocView Navigation
displayed using the variables @code{doc-view-imenu-format} and
@code{doc-view-imenu-flatten}.
+@findex doc-view-page-to-register
+@findex doc-view-jump-to-register
+@kindex m @r{(DocView mode)}
+@kindex ' @r{(DocView mode)}
+ You can save the current page to a register with @kbd{m}
+(@code{doc-view-page-to-register}) (@pxref{Registers}). However, these
+registers are not shared across buffers and stay local to the DocView
+buffer. You can later jump to the register with @kbd{'}
+(@code{doc-view-jump-to-register}).
+
@node DocView Searching
@subsection DocView Searching
diff --git a/etc/NEWS b/etc/NEWS
index c6f8b0062e4..607665a71bb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -262,6 +262,12 @@ When switching to the plain text contents with 'doc-view-open-text',
DocView now creates a dedicated buffer to display it. 'C-c C-c' gets you
back to real DocView buffer if it still exists.
++++
+*** New commands to save and restore pages in buffer local registers.
+Docview can store current page to buffer local registers with the new
+command 'doc-view-page-to-register' (bound to 'm'), and later can be
+restored with 'doc-view-jump-to-register' (bound to ''').
+
** Tramp
+++
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 0d89d63e03e..395993e6263 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -556,7 +556,10 @@ doc-view-mode-map
"C-c C-c" #'doc-view-toggle-display
;; Open a new buffer with doc's text contents
"C-c C-t" #'doc-view-open-text
- "r" #'revert-buffer)
+ "r" #'revert-buffer
+ ;; Registers
+ "m" #'doc-view-page-to-register
+ "'" #'doc-view-jump-to-register)
(define-obsolete-function-alias 'doc-view-revert-buffer #'revert-buffer "27.1")
(defvar revert-buffer-preserve-modes)
@@ -2468,6 +2471,55 @@ doc-view-bookmark-jump
(put 'doc-view-bookmark-jump 'bookmark-handler-type "DocView")
+;;; Register integration
+
+(defvar-local doc-view-register-alist nil
+ "Register alist containing only doc-view registers for current buffer.
+Each doc-view register entry is of the form (doc-view . ALIST) where
+ALIST has the keys `buffer', `file', and `page'. `buffer' is the buffer
+the `file' is visiting. `page' is the page number to be show.")
+
+(defun doc-view-page-to-register (register)
+ "Store the current page to the register REGISTER."
+ (interactive
+ (let ((register-alist doc-view-register-alist))
+ (list (register-read-with-preview "Page to register: "))))
+ (let ((register-alist doc-view-register-alist))
+ (set-register register
+ `(doc-view
+ (buffer . ,(current-buffer))
+ (file . ,(buffer-file-name))
+ (page . ,(doc-view-current-page))))
+ (setq doc-view-register-alist register-alist)))
+
+(defun doc-view-jump-to-register (register)
+ "Jump to the register REGISTER."
+ (interactive
+ (let ((register-alist doc-view-register-alist))
+ (list (register-read-with-preview "Jump to register: "))))
+ (let ((register-alist doc-view-register-alist))
+ (jump-to-register register)))
+
+(cl-defmethod register-val-insert ((val (head doc-view)))
+ (prin1 val))
+
+(cl-defmethod register-val-describe ((val (head doc-view)) _verbose)
+ (let* ((alist (cdr val))
+ (name (or (file-name-nondirectory (alist-get 'file alist))
+ (buffer-name (alist-get 'buffer alist)))))
+ (princ name)
+ (princ " p. ")
+ (princ (alist-get 'page alist))))
+
+(cl-defmethod register-val-jump-to ((val (head doc-view)) _arg)
+ (let* ((alist (cdr val))
+ (buffer (or (alist-get 'buffer alist)
+ (find-buffer-visiting (alist-get 'file alist)))))
+ (unless buffer
+ (user-error "Cannot find the doc-view buffer to jump to"))
+ (switch-to-buffer buffer)
+ (doc-view-goto-page (alist-get 'page alist))))
+
;; Obsolete.
(defun doc-view-intersection (l1 l2)
--
2.45.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#73293: [PATCH] Add buffer-local register commands to doc-view
2024-09-16 12:10 bug#73293: [PATCH] Add buffer-local register commands to doc-view Visuwesh
@ 2024-09-21 10:28 ` Eli Zaretskii
2024-09-23 16:12 ` Tassilo Horn
2024-09-28 9:13 ` Eli Zaretskii
1 sibling, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-09-21 10:28 UTC (permalink / raw)
To: Visuwesh, Tassilo Horn; +Cc: 73293
> From: Visuwesh <visuweshm@gmail.com>
> Date: Mon, 16 Sep 2024 17:40:18 +0530
>
> Attached patch adds buffer-local registers to doc-view-mode. I have
> opted to make the registers buffer-local since I personally use the same
> mnemonic to save pages to the register in multiple buffers. It is
> something like folding a page or placing a pen in between to quickly go
> to-and-fro between those pages.
Thanks.
Tassilo, any comments or suggestions?
> In GNU Emacs 31.0.50 (build 7, x86_64-pc-linux-gnu, X toolkit, cairo
> version 1.18.0, Xaw scroll bars) of 2024-09-09 built on astatine
> Repository revision: 7d7aa65f63db78c5732f1580213fc3767b767a4a
> Repository branch: master
> Windowing system distributor 'The X.Org Foundation', version 11.0.12101011
> System Description: Debian GNU/Linux trixie/sid
>
> Configured using:
> 'configure --with-sound=alsa --with-x-toolkit=lucid --without-xaw3d
> --without-gconf --without-libsystemd --with-cairo'
>
>
> >From 415f3ba0ad07f113858eaa45b60b9bd66b09c7da Mon Sep 17 00:00:00 2001
> From: Visuwesh <visuweshm@gmail.com>
> Date: Sun, 15 Sep 2024 13:56:21 +0530
> Subject: [PATCH] Add buffer-local register commands to doc-view
>
> * lisp/doc-view.el (doc-view-register-alist): New defvar to keep
> track of buffer-local register-alist.
> (doc-view-page-to-register, doc-view-jump-to-register): Add new
> commands to set and jump to buffer-local registers.
> (register-val-insert, register-val-describe)
> (register-val-jump-to): Register defmethod to save and restore
> doc-view registers.
> (doc-view-mode-map): Bind the new commands.
> * doc/emacs/misc.texi (DocView Navigation): Document the new
> commands.
> * etc/NEWS: Announce the change.
> ---
> doc/emacs/misc.texi | 10 +++++++++
> etc/NEWS | 6 +++++
> lisp/doc-view.el | 54 ++++++++++++++++++++++++++++++++++++++++++++-
> 3 files changed, 69 insertions(+), 1 deletion(-)
>
> diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
> index eb157c146e7..e19e554fb26 100644
> --- a/doc/emacs/misc.texi
> +++ b/doc/emacs/misc.texi
> @@ -593,6 +593,16 @@ DocView Navigation
> displayed using the variables @code{doc-view-imenu-format} and
> @code{doc-view-imenu-flatten}.
>
> +@findex doc-view-page-to-register
> +@findex doc-view-jump-to-register
> +@kindex m @r{(DocView mode)}
> +@kindex ' @r{(DocView mode)}
> + You can save the current page to a register with @kbd{m}
> +(@code{doc-view-page-to-register}) (@pxref{Registers}). However, these
> +registers are not shared across buffers and stay local to the DocView
> +buffer. You can later jump to the register with @kbd{'}
> +(@code{doc-view-jump-to-register}).
> +
> @node DocView Searching
> @subsection DocView Searching
>
> diff --git a/etc/NEWS b/etc/NEWS
> index c6f8b0062e4..607665a71bb 100644
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -262,6 +262,12 @@ When switching to the plain text contents with 'doc-view-open-text',
> DocView now creates a dedicated buffer to display it. 'C-c C-c' gets you
> back to real DocView buffer if it still exists.
>
> ++++
> +*** New commands to save and restore pages in buffer local registers.
> +Docview can store current page to buffer local registers with the new
> +command 'doc-view-page-to-register' (bound to 'm'), and later can be
> +restored with 'doc-view-jump-to-register' (bound to ''').
> +
> ** Tramp
>
> +++
> diff --git a/lisp/doc-view.el b/lisp/doc-view.el
> index 0d89d63e03e..395993e6263 100644
> --- a/lisp/doc-view.el
> +++ b/lisp/doc-view.el
> @@ -556,7 +556,10 @@ doc-view-mode-map
> "C-c C-c" #'doc-view-toggle-display
> ;; Open a new buffer with doc's text contents
> "C-c C-t" #'doc-view-open-text
> - "r" #'revert-buffer)
> + "r" #'revert-buffer
> + ;; Registers
> + "m" #'doc-view-page-to-register
> + "'" #'doc-view-jump-to-register)
>
> (define-obsolete-function-alias 'doc-view-revert-buffer #'revert-buffer "27.1")
> (defvar revert-buffer-preserve-modes)
> @@ -2468,6 +2471,55 @@ doc-view-bookmark-jump
>
> (put 'doc-view-bookmark-jump 'bookmark-handler-type "DocView")
>
> +;;; Register integration
> +
> +(defvar-local doc-view-register-alist nil
> + "Register alist containing only doc-view registers for current buffer.
> +Each doc-view register entry is of the form (doc-view . ALIST) where
> +ALIST has the keys `buffer', `file', and `page'. `buffer' is the buffer
> +the `file' is visiting. `page' is the page number to be show.")
> +
> +(defun doc-view-page-to-register (register)
> + "Store the current page to the register REGISTER."
> + (interactive
> + (let ((register-alist doc-view-register-alist))
> + (list (register-read-with-preview "Page to register: "))))
> + (let ((register-alist doc-view-register-alist))
> + (set-register register
> + `(doc-view
> + (buffer . ,(current-buffer))
> + (file . ,(buffer-file-name))
> + (page . ,(doc-view-current-page))))
> + (setq doc-view-register-alist register-alist)))
> +
> +(defun doc-view-jump-to-register (register)
> + "Jump to the register REGISTER."
> + (interactive
> + (let ((register-alist doc-view-register-alist))
> + (list (register-read-with-preview "Jump to register: "))))
> + (let ((register-alist doc-view-register-alist))
> + (jump-to-register register)))
> +
> +(cl-defmethod register-val-insert ((val (head doc-view)))
> + (prin1 val))
> +
> +(cl-defmethod register-val-describe ((val (head doc-view)) _verbose)
> + (let* ((alist (cdr val))
> + (name (or (file-name-nondirectory (alist-get 'file alist))
> + (buffer-name (alist-get 'buffer alist)))))
> + (princ name)
> + (princ " p. ")
> + (princ (alist-get 'page alist))))
> +
> +(cl-defmethod register-val-jump-to ((val (head doc-view)) _arg)
> + (let* ((alist (cdr val))
> + (buffer (or (alist-get 'buffer alist)
> + (find-buffer-visiting (alist-get 'file alist)))))
> + (unless buffer
> + (user-error "Cannot find the doc-view buffer to jump to"))
> + (switch-to-buffer buffer)
> + (doc-view-goto-page (alist-get 'page alist))))
> +
> ;; Obsolete.
>
> (defun doc-view-intersection (l1 l2)
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#73293: [PATCH] Add buffer-local register commands to doc-view
2024-09-21 10:28 ` Eli Zaretskii
@ 2024-09-23 16:12 ` Tassilo Horn
0 siblings, 0 replies; 4+ messages in thread
From: Tassilo Horn @ 2024-09-23 16:12 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 73293, Visuwesh
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Visuwesh <visuweshm@gmail.com>
>> Date: Mon, 16 Sep 2024 17:40:18 +0530
>>
>> Attached patch adds buffer-local registers to doc-view-mode. I have
>> opted to make the registers buffer-local since I personally use the same
>> mnemonic to save pages to the register in multiple buffers. It is
>> something like folding a page or placing a pen in between to quickly go
>> to-and-fro between those pages.
>
> Thanks.
>
> Tassilo, any comments or suggestions?
No, looks good and useful from my point of view.
Bye,
Tassilo
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#73293: [PATCH] Add buffer-local register commands to doc-view
2024-09-16 12:10 bug#73293: [PATCH] Add buffer-local register commands to doc-view Visuwesh
2024-09-21 10:28 ` Eli Zaretskii
@ 2024-09-28 9:13 ` Eli Zaretskii
1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-09-28 9:13 UTC (permalink / raw)
To: Visuwesh; +Cc: 73293-done
> From: Tassilo Horn <tsdh@gnu.org>
> Cc: Visuwesh <visuweshm@gmail.com>, 73293@debbugs.gnu.org
> Date: Mon, 23 Sep 2024 18:12:19 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> From: Visuwesh <visuweshm@gmail.com>
> >> Date: Mon, 16 Sep 2024 17:40:18 +0530
> >>
> >> Attached patch adds buffer-local registers to doc-view-mode. I have
> >> opted to make the registers buffer-local since I personally use the same
> >> mnemonic to save pages to the register in multiple buffers. It is
> >> something like folding a page or placing a pen in between to quickly go
> >> to-and-fro between those pages.
> >
> > Thanks.
> >
> > Tassilo, any comments or suggestions?
>
> No, looks good and useful from my point of view.
Thanks, installed on master, and closing the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-28 9:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-16 12:10 bug#73293: [PATCH] Add buffer-local register commands to doc-view Visuwesh
2024-09-21 10:28 ` Eli Zaretskii
2024-09-23 16:12 ` Tassilo Horn
2024-09-28 9:13 ` Eli Zaretskii
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).