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#73308: [PATCH] Add file-to-register and buffer-to-register. Date: Tue, 17 Sep 2024 00:32:40 +0100 Message-ID: <877cbbrx7r.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="22335"; mail-complaints-to="usenet@ciao.gmane.io" To: 73308@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 17 01:44:16 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 1sqLOB-0005eH-7H for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 17 Sep 2024 01:44:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqLNq-0000rz-2I; Mon, 16 Sep 2024 19:43:54 -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 1sqLNl-0000rf-DB for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 19:43: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 1sqLNl-0001Kf-37 for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 19:43: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=SNfOai85pvqkdvDv7dyJQ63bIsS+bRq8EbaiVYSaFh4=; b=GrcovoAA5NErU+xUBEtxci7q1MbVY6T88lidL3RJIx5zjhvt1GVVdf24NQwicQcFSVb33ZzessHy3KpiylbZ8WAK9NwQ5xNz5kMn0P+ApXvKIjDfOnWYtbgW7P3hOId7MrKxQei6cXb3oWPhbSb7Li9xYHsoND6/ZPBVfNi9P61ICvmQnmzmeSSSpJr8krdN2anFH3pfUYc/7ks9k1k6bGFw7kDLCuq4W1q1To6JLeqvbtuXrQnMcMtLBw9G+qn2nfA8EZfU3enU8dQ+j3k7hstSywAo0GJqdxAfdjUxoPiMprmhQ6tQnwafrVUtKGrnPCaYckdJNyf1HPu+fPZYMg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sqLNy-0000PG-O4 for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 19:44:02 -0400 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: Mon, 16 Sep 2024 23:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73308 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.17265301891441 (code B ref -1); Mon, 16 Sep 2024 23:44:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Sep 2024 23:43:09 +0000 Original-Received: from localhost ([127.0.0.1]:53614 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqLN6-0000NB-Uh for submit@debbugs.gnu.org; Mon, 16 Sep 2024 19:43:09 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:55750) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqLN5-0000N3-3v for submit@debbugs.gnu.org; Mon, 16 Sep 2024 19:43:08 -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 1sqLMp-0000ko-PS for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 19:42:52 -0400 Original-Received: from abi149bb127.cwl1.oracleemaildelivery.com ([129.149.22.127]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqLMm-0001IF-39 for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 19:42:51 -0400 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:List-Unsubscribe:List-Unsubscribe-Post; bh=SNfOai85pvqkdvDv7dyJQ63bIsS+bRq8EbaiVYSaFh4=; b=PXHLG495fp0zfU0NhtXVHfwI9huWVQVbCV2pT6WFGjQumVR45i54olCuoq194klTPHEr4jVagWTW +Mxx9n8kd0CdjSePEaU6TdxIhFqdYACsRbk9WkSnJA0PKkjP6CXBxO4ywPZSdK6+uDFowYWvH2xw zvu0OzjZ98kiEms34nXQGBouOtmXrAAVSvGZhgIVj3U7kMw49Xv4b8VM0+pM65368ZU5S+7/vpp7 rdNIHrEDoFZCHC/CJ9Gznc/ml/fEPjjI+eC5dzRB2a9qrgaB0BWsd0QLxFoas8kVQb8w56fTQhfT vr7H4QS+jcyEsgbVKEVZ5NxHoxm1xosuEHHWGQ== 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:List-Unsubscribe:List-Unsubscribe-Post; bh=SNfOai85pvqkdvDv7dyJQ63bIsS+bRq8EbaiVYSaFh4=; b=gmUEk74J2qUquloYTHzlWBUOrvPhfOJH4p+Qzs4PoBSL0WVOmJihGJc/RTNog3afLWEwwit0GI5K wKKlX3I3Ts/3BDwE+YTyZcv93S5UTiQVwddydAezwL+fj9boKWFjLsr4fDERysgo1dCbvnEcQ4mp /1rtNw91MAZp9mC7opq2RoGJw9LaYalf++icwjXm5OB4oJtJa7zdfBPjNM+XLTlw8d4b6WCofmPW OXTcH3H+5NRNefof/2JziO+w61ZA9NFqgOU4XdGfSiNq2cBwm6j4gtecWyCljXTggGBMoE7ISQv5 7uUVgfRnlt/tZGLx2yHnfxjQQiBbvgTn9wIQVA== Original-Received: by omta-ad1-fd3-401-uk-cardiff-1.omtaad1.vcndpcwl.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20240709 64bit (built Jul 9 2024)) with ESMTPS id <0SJX00KUNIQG8180@omta-ad1-fd3-401-uk-cardiff-1.omtaad1.vcndpcwl.oraclevcn.com> for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 23:32:40 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click Reporting-Meta: AAEiSvJMsoK/fd4ND1ccLt9JEks7TzRo81AXoZDHvvG4In182p89Ztz5hTRVstfx 6y7aaWk/j3aopGZJv8x6o7ZBwhJX6ZwHPeHUZusjt53uS/LvYPLMMw777XQ82NJe pXkRZa1ZXvftKseTQDTk6w9TyIMg2Y4UEgOu3ANoktTxf98nULjYj+TOGSCgxTjB uEJVBSInkqQFan9iJMFIVO4lc2FFw2zBGT/dvqVG/xD+Kk65SBYJmuruh4Hh7ZfN JSkHW4xzZvD6YC57DzvhGBb4b8igt1ZZIEhbD6hKDGGW7Dn7ZFGXXdOWTDqG97t+ kcduXHoVJgqOsJ79euVRIwgOX/hRDIpvUcVmdw2rffB1qfRu9CTbU/j/Nr09iHSz +qj1Qi0aVfPH4v/wnwtzQSPnvai2vurAfNhK2Ou/72pwc+Q8xRkXRVbsYbrSPlMJ uzpxBtfdw1bbqZC10wY0zeuI4FNUBvQepH6g5TqG/mo9tP0RacmCX76A Received-SPF: pass client-ip=129.149.22.127; envelope-from=bounces+bug-gnu-emacs=gnu.org@cwl1.rp.oracleemaildelivery.com; helo=abi149bb127.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 autolearn=no 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:291920 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Tags: patch This patch adds two new functions and keybindings for them, file-to-register and buffer-to-register. These functions make it simpler to put a file/buffer into a register, which I have personally found to be useful when working with projects where I don't wish to disturb the point or to pull up notes files. (Previously submitted, but I was unfortunately unable to follow it up at the time due to life getting busy!) Questions and comments appreciated, previously assigned copyright. In GNU Emacs 29.4 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.43, cairo version 1.18.0) Windowing system distributor 'The X.Org Foundation', version 11.0.12101013 System Description: Arch Linux Configured using: 'configure --sysconfdir=/etc --prefix=/usr --libexecdir=/usr/lib --with-tree-sitter --localstatedir=/var --with-cairo --disable-build-details --with-harfbuzz --with-libsystemd --with-modules --with-x-toolkit=gtk3 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -g -ffile-prefix-map=/build/emacs/src=/usr/src/debug/emacs -flto=auto' 'LDFLAGS=-Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,pack-relative-relocs -flto=auto'' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-file-to-register-and-buffer-to-register.patch >From 29a160f087a0e530e415a9f2676abb390c54f910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= Date: Tue, 17 Sep 2024 00:11:11 +0100 Subject: [PATCH] Add file-to-register and buffer-to-register. * lisp/bindings.el (ctl-x-r-map): Add bindings to the register keymap for the two new functions. 'F' for file-to-register and 'B' for buffer-to-register. * lisp/register.el (register-command-info): Registers the two new functions, file-to-register and buffer-to-register as commands. (file-to-register): New function, stores a file into a register. Used interactively, prompts for REGISTER using `register-read-with-preview'. With a prefix-argument, prompts for FILE-NAME using `read-file-name', otherwise, uses the currently visited file or directory for FILE-NAME. (buffer-to-register): New function, stores a buffer into a register. Used interactively, prompts for REGISTER using `register-read-with-preview'. With a prefix-argument, prompts for BUFFER-NAME using `read-buffer', otherwise, uses the current buffer. * doc/emacs/regs.texi (File and Buffer Registers): Added documentation for the new file-to-register and buffer-to-register commands, replacing the elisp snippet that was used previously. --- doc/emacs/regs.texi | 55 ++++++++++++++++++++++++--------------------- lisp/bindings.el | 4 +++- lisp/register.el | 41 +++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 26 deletions(-) diff --git a/doc/emacs/regs.texi b/doc/emacs/regs.texi index 734d704a272..446b42395ba 100644 --- a/doc/emacs/regs.texi +++ b/doc/emacs/regs.texi @@ -289,41 +289,46 @@ File and Buffer Registers @section Keeping File and Buffer Names in Registers @cindex saving file name in a register @cindex saving buffer name in a register +@kindex C-x r F +@kindex C-x r B 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. Here's how you can +put a file into a buffer. -@smallexample -(set-register @var{r} '(file . @var{name})) -@end smallexample - -@need 3000 -@noindent -For example, - -@smallexample -(set-register ?z '(file . "/gd/gnu/emacs/19.0/src/ChangeLog")) -@end smallexample - -@noindent -puts the file name shown in register @samp{z}. +@table @kbd +@item C-x r F @var{r} +@kindex C-x r F +@findex file-to-register +Store the currently visited file or directory into register @var{r} (@code{file-to-register}). +@item C-u C-x r F @var{r} +@kindex C-x r F +@findex file-to-register +Prompt for a file, and store into register @var{r} (@code{file-to-register}). +@end table To visit the file whose name is in register @var{r}, type @kbd{C-x r j @var{r}}. (This is the same command used to jump to a position or 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 -@samp{*Messages*} buffer often, you can use the following snippet to -put that buffer into the @samp{m} register: + Similarly, if there are certain buffers you visit frequently, you can +put their names in registers. You can use the following command to put a +buffer into a register. -@smallexample -(set-register ?m '(buffer . "*Messages*")) -@end smallexample +@table @kbd +@item C-x r B @var{r} +@kindex C-x r B +@findex buffer-to-register +Store the current buffer into register @var{r} (@code{buffer-to-register}). +@item C-u C-x r B @var{r} +@kindex C-x r B +@findex buffer-to-register +Prompt for a buffer, and store into register @var{r} (@code{buffer-to-register}). +@end table - To switch to the buffer whose name is in register @var{r}, type -@kbd{C-x r j @var{r}}. + To visit the buffer whose name is in register @var{r}, type @kbd{C-x r + j @var{r}}. (This is the same command used to jump to a position or + restore a frame configuration.) @node Keyboard Macro Registers @section Keyboard Macro Registers diff --git a/lisp/bindings.el b/lisp/bindings.el index 6b34c5750c1..06a488fa9fa 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -1574,7 +1574,9 @@ ctl-x-r-map "n" #'number-to-register "+" #'increment-register "w" #'window-configuration-to-register - "f" #'frameset-to-register) + "f" #'frameset-to-register + "F" #'file-to-register + "B" #'buffer-to-register) (define-key ctl-x-map "r" ctl-x-r-map) (define-key esc-map "q" 'fill-paragraph) diff --git a/lisp/register.el b/lisp/register.el index 497848ded1e..01be41314c5 100644 --- a/lisp/register.el +++ b/lisp/register.el @@ -300,6 +300,18 @@ register-command-info :act 'set :noconfirm (memq register-use-preview '(nil never)) :smatch t)) +(cl-defmethod register-command-info ((_command (eql file-to-register))) + (make-register-preview-info + :types '(all) + :msg "File to register `%s'" + :act 'set + :noconfirm (memq register-use-preview '(nil never)))) +(cl-defmethod register-command-info ((_command (eql buffer-to-register))) + (make-register-preview-info + :types '(all) + :msg "Buffer to register `%s'" + :act 'set + :noconfirm (memq register-use-preview '(nil never)))) (defun register-preview-forward-line (arg) "Move to next or previous line in register preview buffer. @@ -688,6 +700,35 @@ jump-to-register (let ((val (get-register register))) (register-val-jump-to val delete))) +(defun file-to-register (file-name register) + "Inserts FILE-NAME in REGISTER. +To visit the file, use \\[jump-to-register]. + +Interactively, prompts for REGISTER using `register-read-with-preview'. +With a prefix-argument, prompts for FILE-NAME using `read-file-name', +otherwise, uses the currently visited file or directory for FILE-NAME." + (interactive (list (if (eq current-prefix-arg nil) + (if (eq major-mode 'dired-mode) + (dired-current-directory) + (buffer-file-name)) + (read-file-name "File: ")) + (register-read-with-preview "File to register: "))) + (unless (eq file-name nil) + (set-register register (cons 'file file-name)))) + +(defun buffer-to-register (buffer register) + "Inserts BUFFER in REGISTER. +To visit the buffer, use \\[jump-to-register]. + +Interactively, prompts for REGISTER using `register-read-with-preview'. +With a prefix-argument, prompts for BUFFER-NAME using `read-buffer', +otherwise, uses the current buffer." + (interactive (list (if (eq current-prefix-arg nil) + (current-buffer) + (read-buffer "Buffer: ")) + (register-read-with-preview "Buffer to register: "))) + (set-register register (cons 'buffer 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.46.1 --=-=-=--