From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Visuwesh Newsgroups: gmane.emacs.bugs Subject: bug#73293: [PATCH] Add buffer-local register commands to doc-view Date: Mon, 16 Sep 2024 17:40:18 +0530 Message-ID: <87y13rx0id.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28329"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 73293@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 16 14:13:58 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sqAcA-0007Cq-Eh for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 16 Sep 2024 14:13:58 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqAc2-0006Qe-Rq; Mon, 16 Sep 2024 08:13:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqAc1-0006Py-Bo for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 08:13:49 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sqAc1-00008f-2O for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 08:13:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=VA/MKxLYdaBUMehU0kOsIsmIGwugjPou+polLGjPi5s=; b=L9sZ+PXyAvU8228Neks5X9gJv3Mgvm5+3XE4OI3QTEQ3bK8kbb0f9eOsFBonXkd0bOr8Qyc3lNpMW2NUgzqv3ZCMxYjPk4vCbPl9/f+bTtFcR+crk/imXc0JkYG5k10L9pv/nnj1tBGrQQ76c89kcjngYBmyaPhdqFv1VGU9PZ8tTEyqqWljl3GOtIgMF5bjveV/AVGinmTvdvPLL26B0CwCytrhPwbpGdMmzN+YINhpSPUUj2YO2blQulyCZCrMWfcqDboioknrdBBpd9JN5NpGpB/RavAXYLNrAzo/M526cn2re555FM9kt2MxK8SAyunWuzuHtas+SncXRS87Tg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sqAcE-0003wz-83 for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 08:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Visuwesh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Sep 2024 12:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73293 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.172648879515078 (code B ref -1); Mon, 16 Sep 2024 12:14:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Sep 2024 12:13:15 +0000 Original-Received: from localhost ([127.0.0.1]:51233 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqAbS-0003v8-Gz for submit@debbugs.gnu.org; Mon, 16 Sep 2024 08:13:15 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:51978) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqAbQ-0003uy-Ba for submit@debbugs.gnu.org; Mon, 16 Sep 2024 08:13:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqAZ7-0005Ss-2M for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 08:10:49 -0400 Original-Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sqAZ4-0008Nf-7v for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 08:10:48 -0400 Original-Received: by mail-pf1-x443.google.com with SMTP id d2e1a72fcca58-7191901abd6so1983320b3a.3 for ; Mon, 16 Sep 2024 05:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726488643; x=1727093443; darn=gnu.org; h=mime-version:user-agent:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to; bh=VA/MKxLYdaBUMehU0kOsIsmIGwugjPou+polLGjPi5s=; b=IUM0nv1bB74CHb434lz75keFiLVzfh4JHwgk+h/+JZEHpYvxvnH++OXBqEec+GW5/v XrHEa963zhkuYFjh0BdSdr1ZykERIp6vFakUx9Qbev73XofNIGoEIlpzDu8JGuKMb6nz DZQEr3xcbH9mIhz5U1m59BXKJTrkY7JNZtZlXRMLTLyctz4VTqPhJd+0v8FQ6kJybNeM tE+nJza8s0DsQeH8UVD1ETR2XWJXGpFPq7waeXjD8e6IlLoqLgRrmKgx7Z5MrJpxPLqL IkAni86W8LHu5fS6nPkoY8F3tDOd8j/WZ93L+cstjsMLxPDz07R/we/MLyTM/N2u9PQp k+CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726488643; x=1727093443; h=mime-version:user-agent:message-id:date:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VA/MKxLYdaBUMehU0kOsIsmIGwugjPou+polLGjPi5s=; b=dhBsrnGJ7ObkxQ3QNeu7HuHB323Z682YDlQ7kA/qFAnp/+JG5RlqsqTwBTI1m7QGCk 0vOOrvv9wp7u9Qouu0vaAumN1/t6k7J3JlLkXthH2qAUOt8hzvdayRGSo4hSo1ljEajh x/b5jooidlvqQNVtqtyQN3enw+Q/W4VOEG7IpcXAmz+LlEeOZmkjkG+BTC7Dd+HQ5Ikg 4fEDWJI8qxnbnOogX30civrl7r4BXfgWH/YRhvd/BpLXC7+SADsxTVvaBEtCNM+cM+VX TMwUzlX5weqL9PRbhE4jLaB4F/+5k7A7HtT0Ix7rHnntgacLghnfifzARV82ayWLXwuR 6rgA== X-Gm-Message-State: AOJu0YzeiMzR20RejtEfQg/NxH2QwFzCi7Jf7qQrDvhHbwL6GcwYPEmA cAeqAt3THd776fHMgA/vP43vOAD/GSozpSSIG+XFvtf8HflbWq59mIKvAlnq X-Google-Smtp-Source: AGHT+IHmOixWpWgvK9pFCvsCfWcshXgt7A17KAHp4eH0vowL7lhfggZM15ohgSOH4eqTsUZWkHS/vg== X-Received: by 2002:a05:6a20:e18a:b0:1d1:21a8:ee8d with SMTP id adf61e73a8af0-1d121a8ef34mr12566692637.22.1726488643285; Mon, 16 Sep 2024 05:10:43 -0700 (PDT) Original-Received: from localhost ([1.7.159.70]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944b7b5b2sm3580144b3a.139.2024.09.16.05.10.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 05:10:42 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=visuweshm@gmail.com; helo=mail-pf1-x443.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:291885 Archived-At: --=-=-= Content-Type: text/plain 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' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-buffer-local-register-commands-to-doc-view.patch >From 415f3ba0ad07f113858eaa45b60b9bd66b09c7da Mon Sep 17 00:00:00 2001 From: Visuwesh 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 --=-=-=--