From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Barra =?UTF-8?Q?=C3=93_?= =?UTF-8?Q?Cath=C3=A1in?= via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#68921: File and Buffer register functions. Date: Sat, 03 Feb 2024 20:50:45 +0000 Message-ID: <875xz5gtlm.fsf@ocathain.ie> Reply-To: Barra =?UTF-8?Q?=C3=93_?= =?UTF-8?Q?Cath=C3=A1in?= 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="29077"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 68921@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 04 04:39:13 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 1rWTLb-0007M7-Qn for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 04 Feb 2024 04:39:12 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWTLJ-0007zo-Td; Sat, 03 Feb 2024 22:38:54 -0500 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 1rWTLH-0007zE-MK for bug-gnu-emacs@gnu.org; Sat, 03 Feb 2024 22:38:51 -0500 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 1rWTLH-0007gl-Ei for bug-gnu-emacs@gnu.org; Sat, 03 Feb 2024 22:38:51 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rWTLT-00005z-3E for bug-gnu-emacs@gnu.org; Sat, 03 Feb 2024 22:39:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Barra =?UTF-8?Q?=C3=93_?= =?UTF-8?Q?Cath=C3=A1in?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 04 Feb 2024 03:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68921 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170701788732745 (code B ref -1); Sun, 04 Feb 2024 03:39:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 Feb 2024 03:38:07 +0000 Original-Received: from localhost ([127.0.0.1]:47396 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rWTKY-0008Vy-Kl for submit@debbugs.gnu.org; Sat, 03 Feb 2024 22:38:07 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:39110) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rWN89-000693-2h for submit@debbugs.gnu.org; Sat, 03 Feb 2024 16:00:53 -0500 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 1rWN7g-0006ph-FN for bug-gnu-emacs@gnu.org; Sat, 03 Feb 2024 16:00:24 -0500 Original-Received: from abi149bb126.cwl1.oracleemaildelivery.com ([129.149.22.126]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rWN7a-0003S2-EQ for bug-gnu-emacs@gnu.org; Sat, 03 Feb 2024 16:00:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=ocathain-2023-02-08; d=ocathain.ie; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender; bh=rmyzwvom0EnItwqLOe2wmOvogGnr3i6Klys3licb+1s=; b=P3keYWCRfP41yc2egTlMQf2rTINNkNP0cBjA0utaXH9PD+4x082wy5BxIeDcJHG4fM4yNIHXboYf zjKX+FOptn/qjHhcNHJjkqy+wNLpJ1epG2eWQEGRzaheLybW13IQ830ZyeLjArG55nqZ1zcXT3AD gj+B3RHuINScmNGPrxVdjsojZ+x/zl873nKIUCFuOtKzNXYDcIDgh2mO7Nr6OF+zjJhtS+mtEs9t faKOD5k6u8sOcEHknzPDD1+WPN5LPYpcipIek12xhbeSi96Y4X2i4SCeDvLloI1ov9ZzRsOqvABx 1e3FH+ohh4G2U0vOSjxP2jxonL8mUoIvgQTlRw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-cwl-20201026; d=cwl1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender; bh=rmyzwvom0EnItwqLOe2wmOvogGnr3i6Klys3licb+1s=; b=UJvZ5kDg1T3aGcR4w4dKFkR8WzZlh9e6z/gn3k/rJ8U8yaZdRcWgxOhW5dGEWP0GgbiLzRF3Qbln I1MT52RpYSIZpp8+3lphhRNc27kLPndPUTGfLEIKBxOzMVm3RrFoL8D0e3rv5rwC8k9UGmgPwaRA vs0S8KkQTEV7U+x92mPOy3hbLodF7EYypnh/yIXfO8SHcLRuf6mDHxUYYDSx240KmMjCmjpDgQDB BCX4DzJfWBM6t/e7Ca/+kYutnGK79SNFsnvjf9AC05pQbYWfKNQP83Ly+TqCIKekCZxrQXtuPv2I DOUEIBPMdoMKxsY9s5iMZuBAVXrH5Ow5xvkfBg== Original-Received: by omta-ad1-fd2-101-uk-cardiff-1.omtaad1.vcndpcwl.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20231214 64bit (built Dec 14 2023)) with ESMTPS id <0S8A004B0SJQFQB0@omta-ad1-fd2-101-uk-cardiff-1.omtaad1.vcndpcwl.oraclevcn.com> for bug-gnu-emacs@gnu.org; Sat, 03 Feb 2024 20:50:14 +0000 (GMT) Reporting-Meta: AAG6IJ1+5PpPce61hfUaqc/pnRR+GCP4Blia4LgZx+4G1gdmaHQbA2xJQX13Y2hZ JoyO2Z91tapSzDksHsR0KgPZLSjlDHTuMl+xDuV8siw3m8OztbTrN3dHbeIZsNWl AnVUaEFd7cp8/iYqZEP9N4AIzxrM0vcZnfIa1MaHy+EnjPrsAZ0nLKqKhV5xsm/q p+BUOzUSyO4bmk6BrieTJQ1FgyGdeVEqLWQfB3c2FXCmNEDLQhhgHmEPWhIlI2BQ JbNjHSu3FSyKN+JHXa4ujjoT9iSTJz8U+y/yQ5cbj3wGOS9/DwHd3J/nYX8e9hWy 0MZu3CdUzxjJgP6IRmCh+0Jm4EdHZ6J6oXDn2ivk5sOfC+4CXEpKTjyo9B5V3jB9 WwZ0/Zs/6EXjqXKxfxMfsgBnGZRlq2CjKWPMcT2DQPiLBrH3N9eZ0H+NLDP12Unv BGWDIYb+vljKh8iaTnfy6fm7cAfNjhJmi/Nt8TsZHp/FcWqGPzKxBTbTcQ== Received-SPF: pass client-ip=129.149.22.126; envelope-from=bounces+bug-gnu-emacs=gnu.org@cwl1.rp.oracleemaildelivery.com; helo=abi149bb126.cwl1.oracleemaildelivery.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 03 Feb 2024 22:38:04 -0500 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:279389 Archived-At: --=-=-= Content-Type: text/plain Hello! I noticed that files and buffers don't have "to-register" functions of their own, rather, relying on (set-register). To that end, I have written 4 functions that I feel may be useful and "complete the set" of register functions. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Added-buffer-and-file-to-register-functions.patch >From d697dc8b3fb66fb3c37851ab1d33af665870ae1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= Date: Fri, 2 Feb 2024 21:45:05 +0000 Subject: [PATCH 1/4] Added buffer and file to register functions. Added buffer-to-register, file-to-register, current-buffer-to-register, and current-file-to-register to register.el. --- lisp/register.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lisp/register.el b/lisp/register.el index 822467a0d72..8fff867e547 100644 --- a/lisp/register.el +++ b/lisp/register.el @@ -685,6 +685,50 @@ Interactively, prompt for REGISTER using `register-read-with-preview'." (let ((val (get-register register))) (register-val-jump-to val delete))) +(defun file-to-register (register file-name) + "Inserts a given file into a register. To visit the file, use + \\[jump-to-register]. + +Called from Lisp, takes two args: REGISTER, and FILE-NAME. + +Interactively, prompt for REGISTER using `register-read-with-preview', +and prompt for FILE-NAME using `read-file-name'." + (interactive (list (register-read-with-preview "File to register: ") + (read-file-name "File: "))) + (set-register register `(file . ,file-name))) + +(defun current-file-to-register (register) + "Places the current file name into a register. To visit the file, use +\\[jump-to-register]. + +Called from Lisp, takes one arg: REGISTER. + +Interactively, prompt for REGISTER using `register-read-with-preview." + (interactive (list (register-read-with-preview "Current file to register: "))) + (set-register register `(file . ,(buffer-file-name)))) + +(defun buffer-to-register (register buffer) + "Inserts a given buffer into a register. To visit the buffer, use +\\[jump-to-register]. + +Called from Lisp, takes two args: REGISTER, and BUFFER. + +Interactively, prompt for REGISTER using `register-read-with-preview', and +prompt for BUFFER-NAME using `read-buffer'." + (interactive (list (register-read-with-preview "Buffer to register: ") + (read-buffer "Buffer: "))) + (set-register register `(buffer . ,buffer))) + +(defun current-buffer-to-register (register) + "Places the current buffer into a register. To visit the buffer, use +\\[jump-to-register]. + +Called from Lisp, takes one arg: REGISTER. + +Interactively, prompt for REGISTER using `register-read-with-preview.'" + (interactive (list (register-read-with-preview "Current buffer to register: "))) + (set-register register `(buffer . ,(current-buffer)))) + (cl-defgeneric register-val-jump-to (_val _arg) "Execute the \"jump\" operation of VAL. VAL is the contents of a register as returned by `get-register'. -- 2.43.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-Added-bindings-for-the-new-to-register-functions.patch >From f53b313bbf9e033ca0aea9e1e1e4a547d6b5b194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= Date: Fri, 2 Feb 2024 22:28:44 +0000 Subject: [PATCH 2/4] Added bindings for the new "to register" functions Added bindings for "current-file-to-register" and "current-buffer-to-register" to bindings.el. --- lisp/bindings.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/bindings.el b/lisp/bindings.el index 4690897fed4..21767f37f61 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -1570,7 +1570,10 @@ if `inhibit-field-text-motion' is non-nil." "n" #'number-to-register "+" #'increment-register "w" #'window-configuration-to-register - "f" #'frameset-to-register) + "f" #'frameset-to-register + "F" #'current-file-to-register + "B" #'current-buffer-to-register) + (define-key ctl-x-map "r" ctl-x-r-map) (define-key esc-map "q" 'fill-paragraph) -- 2.43.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0003-Basic-error-checking-for-new-register-functions.patch >From 23dcde96046a9edc04bca68579174300dde5cd44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= Date: Sat, 3 Feb 2024 20:34:45 +0000 Subject: [PATCH 3/4] Basic error checking for new register functions --- lisp/register.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/register.el b/lisp/register.el index 8fff867e547..cfb3c6a2b13 100644 --- a/lisp/register.el +++ b/lisp/register.el @@ -695,7 +695,9 @@ Interactively, prompt for REGISTER using `register-read-with-preview', and prompt for FILE-NAME using `read-file-name'." (interactive (list (register-read-with-preview "File to register: ") (read-file-name "File: "))) - (set-register register `(file . ,file-name))) + (if (file-exists-p file-name) + (set-register register `(file . ,file-name))) + (user-error "File does not exist.") (defun current-file-to-register (register) "Places the current file name into a register. To visit the file, use @@ -717,7 +719,9 @@ Interactively, prompt for REGISTER using `register-read-with-preview', and prompt for BUFFER-NAME using `read-buffer'." (interactive (list (register-read-with-preview "Buffer to register: ") (read-buffer "Buffer: "))) - (set-register register `(buffer . ,buffer))) + (if (buffer-p buffer) + (set-register register `(buffer . ,buffer)) + (user-error "Not a buffer.")) (defun current-buffer-to-register (register) "Places the current buffer into a register. To visit the buffer, use -- 2.43.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0004-Documentation-in-Info-for-new-register-commands.patch >From cf28598990cb374f6e3bedb0b5c49e0ccc861477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= Date: Sat, 3 Feb 2024 20:43:05 +0000 Subject: [PATCH 4/4] Documentation in Info for new register commands Simple modification to regs.texi to refer to the new register commands. --- doc/emacs/regs.texi | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/emacs/regs.texi b/doc/emacs/regs.texi index cac5b32c566..e9fb2c74773 100644 --- a/doc/emacs/regs.texi +++ b/doc/emacs/regs.texi @@ -291,11 +291,13 @@ numeric argument stores zero in the register. @cindex saving buffer name in a register If you visit certain file names frequently, you can visit them more -conveniently if you put their names in registers. Here's the Lisp code -used to put a file @var{name} into register @var{r}: +conveniently if you put their names in registers. You may use @kbd{C-x +r F} to place the currently visited file in a register. + +Here's the Lisp code used to put a file @var{name} into register @var{r}: @smallexample -(set-register @var{r} '(file . @var{name})) +(file-to-register @var{r} @var{name}) @end smallexample @need 3000 @@ -303,7 +305,7 @@ used to put a file @var{name} into register @var{r}: For example, @smallexample -(set-register ?z '(file . "/gd/gnu/emacs/19.0/src/ChangeLog")) +(file-to-register ?z "/gd/gnu/emacs/19.0/src/ChangeLog") @end smallexample @noindent @@ -314,12 +316,13 @@ puts the file name shown in register @samp{z}. restore a frame configuration.) Similarly, if there are certain buffers you visit frequently, you -can put their names in registers. For instance, if you visit the +can put their names in registers. You may use @kbd{C-x r B} to store +the current buffer in a register. Or, for instance, if you visit the @samp{*Messages*} buffer often, you can use the following snippet to put that buffer into the @samp{m} register: @smallexample -(set-register ?m '(buffer . "*Messages*")) +(buffer-to-register ?m "*Messages*") @end smallexample To switch to the buffer whose name is in register @var{r}, type -- 2.43.0 --=-=-=--