unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#68921: File and Buffer register functions.
@ 2024-02-03 20:50 Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-02-04  6:30 ` Thierry Volpiatto
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-02-03 20:50 UTC (permalink / raw)
  To: 68921

[-- Attachment #1: Type: text/plain, Size: 238 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Added-buffer-and-file-to-register-functions.patch --]
[-- Type: text/x-patch, Size: 2779 bytes --]

From d697dc8b3fb66fb3c37851ab1d33af665870ae1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Added-bindings-for-the-new-to-register-functions.patch --]
[-- Type: text/x-patch, Size: 981 bytes --]

From f53b313bbf9e033ca0aea9e1e1e4a547d6b5b194 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-Basic-error-checking-for-new-register-functions.patch --]
[-- Type: text/x-patch, Size: 1578 bytes --]

From 23dcde96046a9edc04bca68579174300dde5cd44 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-Documentation-in-Info-for-new-register-commands.patch --]
[-- Type: text/x-patch, Size: 2165 bytes --]

From cf28598990cb374f6e3bedb0b5c49e0ccc861477 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#68921: File and Buffer register functions.
  2024-02-03 20:50 bug#68921: File and Buffer register functions Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-02-04  6:30 ` Thierry Volpiatto
  2024-02-04  6:45   ` Thierry Volpiatto
  2024-02-04  7:15   ` Thierry Volpiatto
  2024-02-04  7:00 ` Eli Zaretskii
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 7+ messages in thread
From: Thierry Volpiatto @ 2024-02-04  6:30 UTC (permalink / raw)
  To: 68921; +Cc: barra

Barra Ó Catháin via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:

> Hello!
>
> I noticed that files and buffers don't have "to-register" functions of
> their own, rather, relying on (set-register).

The reason is that when your use `point-to-register`, a position is
recorded in the buffer, and when you kill this buffer your register
record (a marker) is transformed in a file-query register:

Example:

If I do C-x r SPC in init.el, register record a register like this:

    (119 . #<marker at 76829 in init.el>)

Then I kill init.el buffer, I have now in register-alist instead of the
register above:

    (122 file-query "/path/to/init.el" 76829) 

This register is writable i.e. you can save it for further emacs
sessions.

So there is no really needs for function that register files or buffers.

That said if you really want to add such functions, you will have to add
for each function the corresponding defmethod, here an example with a
delete register function, you will find other examples in register.el:

    (defun register-delete (register)
        (interactive (list (register-read-with-preview "Delete register: ")))
        (setq register-alist (delete (assoc register register-alist)
                                     register-alist)))

    (cl-defmethod register-preview-command-info ((_command (eql register-delete)))
            (make-register-preview-info
             :types '(all)
             :msg "Delete register `%s'"
             :act 'modify
             :smatch t))

> To that end, I have written 4 functions that I feel may be useful and
> "complete the set" of register functions.
>
> From d697dc8b3fb66fb3c37851ab1d33af665870ae1d Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
> 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
>
> From f53b313bbf9e033ca0aea9e1e1e4a547d6b5b194 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
> 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
>
> From 23dcde96046a9edc04bca68579174300dde5cd44 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
> 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
>
> From cf28598990cb374f6e3bedb0b5c49e0ccc861477 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
> 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

-- 
Thierry





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#68921: File and Buffer register functions.
  2024-02-04  6:30 ` Thierry Volpiatto
@ 2024-02-04  6:45   ` Thierry Volpiatto
  2024-02-04  7:15   ` Thierry Volpiatto
  1 sibling, 0 replies; 7+ messages in thread
From: Thierry Volpiatto @ 2024-02-04  6:45 UTC (permalink / raw)
  To: 68921; +Cc: barra

Thierry Volpiatto <thievol@posteo.net> writes:

> Barra Ó Catháin via "Bug reports for GNU Emacs, the Swiss army knife of
> text editors" <bug-gnu-emacs@gnu.org> writes:
>
>> Hello!
>>
>> I noticed that files and buffers don't have "to-register" functions of
>> their own, rather, relying on (set-register).
>
> The reason is that when your use `point-to-register`, a position is
> recorded in the buffer, and when you kill this buffer your register
> record (a marker) is transformed in a file-query register:
>
> Example:
>
> If I do C-x r SPC in init.el, register record a register like this:
>
>     (119 . #<marker at 76829 in init.el>)
>
> Then I kill init.el buffer, I have now in register-alist instead of the
> register above:
>
>     (122 file-query "/path/to/init.el" 76829) 
       ^^^
       119

Sorry, for the error when copying.

-- 
Thierry





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#68921: File and Buffer register functions.
  2024-02-03 20:50 bug#68921: File and Buffer register functions Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-02-04  6:30 ` Thierry Volpiatto
@ 2024-02-04  7:00 ` Eli Zaretskii
  2024-02-06 22:42 ` Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-03-28 15:31 ` Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
  3 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2024-02-04  7:00 UTC (permalink / raw)
  To: Barra Ó Catháin, Thierry Volpiatto; +Cc: 68921

> Date: Sat, 03 Feb 2024 20:50:45 +0000
> From:  Barra Ó Catháin via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> 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.

Thanks.  I posted some comments on emacs-devel, where you posted these
patches as well.  Let's continue discussing only here, so that the
discussion is recorded by the bug tracker.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#68921: File and Buffer register functions.
  2024-02-04  6:30 ` Thierry Volpiatto
  2024-02-04  6:45   ` Thierry Volpiatto
@ 2024-02-04  7:15   ` Thierry Volpiatto
  1 sibling, 0 replies; 7+ messages in thread
From: Thierry Volpiatto @ 2024-02-04  7:15 UTC (permalink / raw)
  To: 68921; +Cc: barra

Thierry Volpiatto <thievol@posteo.net> writes:

> That said if you really want to add such functions, you will have to add
> for each function the corresponding defmethod, here an example with a
> delete register function, you will find other examples in register.el:
>
>     (defun register-delete (register)
>         (interactive (list (register-read-with-preview "Delete register: ")))
>         (setq register-alist (delete (assoc register register-alist)
>                                      register-alist)))
>
>     (cl-defmethod register-preview-command-info ((_command (eql register-delete)))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Read here           register-command-info instead.
I use register-preview-command-info for my personal usage on Emacs-29,
the real thing is register-command-info.

Sorry again.

-- 
Thierry





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#68921: File and Buffer register functions.
  2024-02-03 20:50 bug#68921: File and Buffer register functions Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-02-04  6:30 ` Thierry Volpiatto
  2024-02-04  7:00 ` Eli Zaretskii
@ 2024-02-06 22:42 ` Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-03-28 15:31 ` Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
  3 siblings, 0 replies; 7+ messages in thread
From: Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-02-06 22:42 UTC (permalink / raw)
  To: 68921

[-- Attachment #1: Type: text/plain, Size: 487 bytes --]

Here follows (hopefully) much improved versions of the patches. I have
to admit, a lot of the "decisions" of the last one were just plain
sillyness, but I hope I've correctly formatted the documentation. I
rendered it and it looked correct to my eyes, but that's my own eyes.

Both commands now take a prefix argument to pick a specific file or
buffer, and otherwise default to the currently visited one.

Further comments would be appreciated!

Thanks,
Barra Ó Catháin.


[-- Attachment #2: 0001-Added-buffer-and-file-to-register-functions.patch --]
[-- Type: text/plain, Size: 3060 bytes --]

From d7d6878664ae22c622f60608e9304fbffe29676c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
Date: Tue, 6 Feb 2024 22:33:32 +0000
Subject: [PATCH] Added buffer and file to register functions.

* lisp/register.el (register-command-info): Register two new functions.
(file-to-register): New function.
(buffer-to-register): New function.
---
 lisp/register.el | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/lisp/register.el b/lisp/register.el
index 822467a0d72..645bbc4b0ec 100644
--- a/lisp/register.el
+++ b/lisp/register.el
@@ -297,6 +297,18 @@ If NOCONFIRM is non-nil, request confirmation of register name by RET."
    :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.
@@ -685,6 +697,35 @@ Interactively, prompt for REGISTER using `register-read-with-preview'."
   (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.43.0


[-- Attachment #3: 0002-lisp-bindings.el-ctl-x-r-map.patch --]
[-- Type: text/plain, Size: 897 bytes --]

From c38e70ad2a93269e46343ea2b1a366ea064cdf84 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
Date: Tue, 6 Feb 2024 14:18:47 +0000
Subject: [PATCH 2/3] * lisp/bindings.el (ctl-x-r-map): Added file-to-register
 and buffer-to-register in to keymap, under "F", and "B"

---
 lisp/bindings.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/bindings.el b/lisp/bindings.el
index 4690897fed4..64f83efbb0a 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -1570,7 +1570,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)
-- 
2.43.0


[-- Attachment #4: 0003-Wrote-documentation-for-new-to-register-functions.patch --]
[-- Type: text/plain, Size: 3153 bytes --]

From 6c6524f70f93b88378c54be5bf4a7c21f422a8fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= <barra@ocathain.ie>
Date: Tue, 6 Feb 2024 22:01:14 +0000
Subject: [PATCH 3/3] Wrote documentation for new to register functions.

* doc/emacs/regs.texi (File and Buffer Registers):
Revised documentation to explain the new commands, rather than the
set-register elisp.
---
 doc/emacs/regs.texi | 55 ++++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/doc/emacs/regs.texi b/doc/emacs/regs.texi
index cac5b32c566..9dce7557de2 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
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#68921: File and Buffer register functions.
  2024-02-03 20:50 bug#68921: File and Buffer register functions Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
                   ` (2 preceding siblings ...)
  2024-02-06 22:42 ` Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-03-28 15:31 ` Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
  3 siblings, 0 replies; 7+ messages in thread
From: Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-03-28 15:31 UTC (permalink / raw)
  To: barra, 68921

Just thought I'd follow this up, since I have some time on my hands at
the moment.

Additionally, my copyright assignment is completed.
-- 
============================
Barry Kane | Barra Ó Catháin

	"It's probably DNS."
============================
	Website: ocathain.ie

	PGP Key Fingerprint:
  C8DC 7443 991F B346 DE28
  8FFA 85DE 3153 96B7 FFC6
============================





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-28 15:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-03 20:50 bug#68921: File and Buffer register functions Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-04  6:30 ` Thierry Volpiatto
2024-02-04  6:45   ` Thierry Volpiatto
2024-02-04  7:15   ` Thierry Volpiatto
2024-02-04  7:00 ` Eli Zaretskii
2024-02-06 22:42 ` Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-28 15:31 ` Barra Ó Catháin via Bug reports for GNU Emacs, the Swiss army knife of text editors

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).