GNU bug report logs - #63909
[PATCH] home: Add inputrc service.

Previous Next

Package: guix-patches;

Reported by: Efraim Flashner <efraim <at> flashner.co.il>

Date: Mon, 5 Jun 2023 12:20:01 UTC

Severity: normal

Tags: patch

Done: Efraim Flashner <efraim <at> flashner.co.il>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 63909 in the body.
You can then email your comments to 63909 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to , guix-patches <at> gnu.org:
bug#63909; Package guix-patches. (Mon, 05 Jun 2023 12:20:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Efraim Flashner <efraim <at> flashner.co.il>:
New bug report received and forwarded. Copy sent to , guix-patches <at> gnu.org. (Mon, 05 Jun 2023 12:20:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Efraim Flashner <efraim <at> flashner.co.il>
To: guix-patches <at> gnu.org
Cc: Efraim Flashner <efraim <at> flashner.co.il>
Subject: [PATCH] home: Add inputrc service.
Date: Mon,  5 Jun 2023 15:19:24 +0300
* gnu/home/services/shells.scm (home-inputrc-service-type,
home-inputrc-configuration): New variables.
(serialize-inputrc-key-bindings, serialize-inputrc-variables,
serialize-inputrc-conditional-constructs,
serialize-inputrc-extra-content, generate-home-inputrc-documentation):
New procedures.
---
 gnu/home/services/shells.scm | 145 ++++++++++++++++++++++++++++++++++-
 1 file changed, 144 insertions(+), 1 deletion(-)

diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index f05f2221d6..bc3daf7a21 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021 Andrew Tropin <andrew <at> trop.in>
 ;;; Copyright © 2021 Xinglu Chen <public <at> yoctocell.xyz>
+;;; Copyright © 2023 Efraim Flashner <efraim <at> flashner.co.il>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -44,7 +45,10 @@ (define-module (gnu home services shells)
 
             home-fish-service-type
             home-fish-configuration
-            home-fish-extension))
+            home-fish-extension
+
+            home-inputrc-service-type
+            home-inputrc-configuration))
 
 ;;; Commentary:
 ;;;
@@ -626,6 +630,138 @@ (define home-fish-service-type
                 (description "\
 Install and configure Fish, the friendly interactive shell.")))
 
+
+;;;
+;;; Readline.
+;;;
+
+(define (serialize-inputrc-key-bindings field-name val)
+  #~(string-append
+     #$@(map
+         (match-lambda
+           ((key . value)
+            #~(string-append #$key ": " #$value "\n")))
+         val)))
+
+(define (serialize-inputrc-variables field-name val)
+  #~(string-append
+     #$@(map
+         (match-lambda
+           ((key . #f)
+            #~(string-append "set " #$key " off\n"))
+           ((key . #t)
+            #~(string-append "set " #$key " on\n"))
+           ((key . value)
+            #~(string-append "set " #$key " " #$value "\n")))
+         val)))
+
+(define (serialize-inputrc-conditional-constructs field-name val)
+  #~(string-append
+     #$@(map
+         (match-lambda
+           (("$endif" . _)
+            "$endif\n")
+           (("$include" . value)
+            #~(string-append "$include " #$value "\n"))
+           ;; TODO: key can only be "$if" or "$else".
+           ((key . value)
+            #~(string-append #$key "\n"
+                             #$(serialize-configuration
+                                 value
+                                 home-inputrc-configuration-fields))))
+         val)))
+
+(define (serialize-inputrc-extra-content field-name value)
+  #~(if (string=? #$value "") "" (string-append #$value "\n")))
+
+(define-configuration home-inputrc-configuration
+  (key-bindings
+   (alist '())
+   "Association list of readline key bindings to be added to the @code{.inputrc}
+file.  This is where code like this:
+
+@lisp
+'((\"Control-l\" . \"clear-screen\"))
+@end lisp
+
+turns into
+
+@example
+Control-l: clear-screen
+@end example"
+   (serializer serialize-inputrc-key-bindings))
+  (variables
+   (alist '())
+   "Association list of readline variables to set.  This is where configuration
+options like this:
+
+@lisp
+'((\"bell-style\" . \"visible\")
+  (\"colored-completion-prefix\" . #t))
+@end lisp
+
+turns into
+
+@example
+set bell-style visible
+set colored-completion-prefix on
+@end example"
+   (serializer serialize-inputrc-variables))
+  (conditional-constructs
+   (alist '())
+   "Association list of conditionals to add to the intialization file.  This
+includes @command{$if}, @command{else}, @command{endif} and @{include} and they
+receive a value of another @command{home-inputrc-configuration}.
+
+@lisp
+(conditional-constructs
+ `((\"$if mode=vi\" .
+     ,(home-inputrc-configuration
+        (variables
+         `((\"show-mode-in-prompt\" . #t)))))
+   (\"$else\" .
+     ,(home-inputrc-configuration
+        (key-bindings
+         `((\"Control-l\" . \"clear-screen\")))))
+   (\"$endif\" . #t)))
+@end lisp
+
+turns into
+
+@example
+$if mode=vi
+set show-mode-in-prompt on
+$else
+Control-l: clear-screen
+$endif
+@end example"
+   (serializer serialize-inputrc-conditional-constructs))
+  (extra-content
+   (string "")
+   "Extra content appended as-is to the configuration file.  Run @command{man
+readline} for more information about all the configuration options."
+   (serializer serialize-inputrc-extra-content)))
+
+(define (home-inputrc-files config)
+  (list
+   `(".inputrc"
+     ,(mixed-text-file "inputrc"
+                       (serialize-configuration
+                         config
+                         home-inputrc-configuration-fields)))))
+
+(define home-inputrc-service-type
+  (service-type (name 'inputrc)
+                (extensions
+                 (list (service-extension home-files-service-type
+                                          home-inputrc-files)))
+                (default-value (home-inputrc-configuration))
+                (description "Configure readline in @code{.inputrc}.")))
+
+
+;;;
+;;; Documentation.
+;;;
 
 (define (generate-home-shell-profile-documentation)
   (generate-documentation
@@ -662,3 +798,10 @@ (define (generate-home-fish-documentation)
     `((home-fish-extension
        ,home-fish-extension-fields))
     'home-fish-extension)))
+
+(define (generate-home-inputrc-documentation)
+  (string-append
+   (generate-documentation
+    `((home-inputrc-configuration
+       ,home-inputrc-configuration-fields))
+    'home-inputrc-configuration)))

base-commit: 940665301de4effd065d24c167f619286f2adf4c
-- 
Efraim Flashner   <efraim <at> flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted





Information forwarded to guix-patches <at> gnu.org:
bug#63909; Package guix-patches. (Fri, 16 Jun 2023 13:41:02 GMT) Full text and rfc822 format available.

Message #8 received at 63909 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Efraim Flashner <efraim <at> flashner.co.il>
Cc: paren <at> disroot.org, 63909 <at> debbugs.gnu.org, Andrew Tropin <andrew <at> trop.in>
Subject: Re: bug#63909: [PATCH] home: Add inputrc service.
Date: Fri, 16 Jun 2023 15:40:09 +0200
Hi!

Efraim Flashner <efraim <at> flashner.co.il> skribis:

> * gnu/home/services/shells.scm (home-inputrc-service-type,
> home-inputrc-configuration): New variables.
> (serialize-inputrc-key-bindings, serialize-inputrc-variables,
> serialize-inputrc-conditional-constructs,
> serialize-inputrc-extra-content, generate-home-inputrc-documentation):
> New procedures.

Nice!

I’d like Andrew and ( to chime in more often :-) but here’s my take.

> +
> +;;;
> +;;; Documentation.
> +;;;
>  
>  (define (generate-home-shell-profile-documentation)
>    (generate-documentation
> @@ -662,3 +798,10 @@ (define (generate-home-fish-documentation)
>      `((home-fish-extension
>         ,home-fish-extension-fields))
>      'home-fish-extension)))
> +
> +(define (generate-home-inputrc-documentation)
> +  (string-append
> +   (generate-documentation
> +    `((home-inputrc-configuration
> +       ,home-inputrc-configuration-fields))
> +    'home-inputrc-configuration)))

I don’t think we need to keep these procedures in the file.

Overall it LGTM, except for one thing: could you add it to
‘doc/guix.texi’?  (The usual template is: an intro giving context and a
cross-reference to the upstream manual, one or two configuration
examples with an explanation, and then the reference.)

Thanks!

Ludo’.




Information forwarded to , guix-patches <at> gnu.org:
bug#63909; Package guix-patches. (Sun, 18 Jun 2023 08:50:03 GMT) Full text and rfc822 format available.

Message #11 received at 63909 <at> debbugs.gnu.org (full text, mbox):

From: Efraim Flashner <efraim <at> flashner.co.il>
To: guix-patches <at> gnu.org,
	Ludovic Courtès <ludo <at> gnu.org>
Cc: paren <at> disroot.org, 63909 <at> debbugs.gnu.org,
 Efraim Flashner <efraim <at> flashner.co.il>, Andrew Tropin <andrew <at> trop.in>
Subject: [PATCH v2] home: Add inputrc service.
Date: Sun, 18 Jun 2023 11:49:15 +0300
* gnu/home/services/shells.scm (home-inputrc-service-type,
home-inputrc-configuration): New variables.
(serialize-inputrc-key-bindings, serialize-inputrc-variables,
serialize-inputrc-conditional-constructs,
serialize-inputrc-extra-content): New procedures.
* doc/guix.texi (Shells Home Services): Document it.
---
 doc/guix.texi                | 129 +++++++++++++++++++++++++++++++++
 gnu/home/services/shells.scm | 134 ++++++++++++++++++++++++++++++++++-
 2 files changed, 262 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 9232c82b4b..72ab941243 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -42797,6 +42797,135 @@ Shells Home Services
 
 @end deftp
 
+@subsubheading Inputrc Profile Service
+@cindex inputrc
+@cindex readline
+
+The @uref{https://tiswww.cwru.edu/php/chet/readline/rltop.html, GNU
+Readline package} includes Emacs and vi editing modes, with the ability
+to customize the configuration with settings in the @file{~/.inputrc}
+file.  With the @code{gnu home services shells} module, you can setup
+your readline configuration in a predictable manner, as shown below.
+For more information about configuring an @file{~/.inputrc} file,
+@pxref{Readline Init File,,, readline, GNU Readline}.
+
+@defvar home-inputrc-service-type
+
+This is the service to setup various @file{.inputrc} configurations. The
+settings in @file{.inputrc} are read by all programs which are linked
+with GNU Readline.
+
+Here is an example of a service and its configuration that you could add
+to the @code{services} field of your @code{home-environment}:
+
+@lisp
+(service home-inputrc-service-type
+         (home-inputrc-configuration
+           (key-bindings
+            `(("Control-l" . "clear-screen")))
+           (variables
+            `(("bell-style" . "visible")
+              ("colored-completion-prefix" . #t)
+              ("editing-mode" . "vi")
+              ("show-mode-in-prompt" . #t)))
+           (conditional-constructs
+            `(("$if mode=vi" .
+               ,(home-inputrc-configuration
+                  (variables
+                   `(("colored-stats" . #t)
+                     ("enable-bracketed-paste" . #t)))))
+              ("$else" .
+               ,(home-inputrc-configuration
+                  (variables
+                   `(("show-all-if-ambiguous" . #t)))))
+              ("endif" . #t)
+              ("$include" . "/etc/inputrc")
+              ("$include" . ,(file-append
+                               (specification->package "readline")
+                               "/etc/inputrc"))))))
+@end lisp
+
+The example above starts with a combination of @code{key-bindings} and
+@code{variables}.  The @code{conditional-constructs} show how it is
+possible to add conditionals and includes.  In the example above
+@code{colored-stats} is only enabled if the editing mode is @code{vi}
+style, and it also reads any additional configuration located in
+@file{/etc/inputrc} or in @file{/gnu/store/@dots{}-readline/etc/inputrc}.
+
+The value associated with a @code{home-inputrc-service-type} instance
+must be a @code{home-inputrc-configuration} record, as described below.
+
+@end defvar
+
+@anchor{home-inputrc-configuration}
+@deftp {Data Type} home-inputrc-configuration
+Available @code{home-inputrc-configuration} fields are:
+
+@table @asis
+@item @code{key-bindings} (default: @code{'()}) (type: alist)
+Association list of readline key bindings to be added to the
+@file{~/.inputrc} file.
+
+@lisp
+'((\"Control-l\" . \"clear-screen\"))
+@end lisp
+
+turns into
+
+@example
+Control-l: clear-screen
+@end example
+
+@item @code{variables} (default: @code{'()}) (type: alist)
+Association list of readline variables to set.
+
+@lisp
+'((\"bell-style\" . \"visible\")
+  (\"colored-completion-prefix\" . #t))
+@end lisp
+
+turns into
+
+@example
+set bell-style visible
+set colored-completion-prefix on
+@end example
+
+@item @code{conditional-constructs} (default: @code{'()}) (type: alist)
+Association list of conditionals to add to the initialization file.  This
+includes @command{$if}, @command{else}, @command{endif} and @command{include}
+and they receive a value of another @command{home-inputrc-configuration}.
+
+@lisp
+(conditional-constructs
+ `((\"$if mode=vi\" .
+     ,(home-inputrc-configuration
+        (variables
+         `((\"show-mode-in-prompt\" . #t)))))
+   (\"$else\" .
+     ,(home-inputrc-configuration
+        (key-bindings
+         `((\"Control-l\" . \"clear-screen\")))))
+   (\"$endif\" . #t)))
+@end lisp
+
+turns into
+
+@example
+$if mode=vi
+set show-mode-in-prompt on
+$else
+Control-l: clear-screen
+$endif
+@end example
+
+@item @code{extra-content} (default: @code{""}) (type: text-config)
+Extra content appended as-is to the configuration file.  Run @command{man
+readline} for more information about all the configuration options.
+
+@end table
+@end deftp
+
 @node Mcron Home Service
 @subsection Scheduled User's Job Execution
 
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index f05f2221d6..415b5470c5 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021 Andrew Tropin <andrew <at> trop.in>
 ;;; Copyright © 2021 Xinglu Chen <public <at> yoctocell.xyz>
+;;; Copyright © 2023 Efraim Flashner <efraim <at> flashner.co.il>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -44,7 +45,10 @@ (define-module (gnu home services shells)
 
             home-fish-service-type
             home-fish-configuration
-            home-fish-extension))
+            home-fish-extension
+
+            home-inputrc-service-type
+            home-inputrc-configuration))
 
 ;;; Commentary:
 ;;;
@@ -626,6 +630,134 @@ (define home-fish-service-type
                 (description "\
 Install and configure Fish, the friendly interactive shell.")))
 
+
+;;;
+;;; Readline.
+;;;
+
+(define (serialize-inputrc-key-bindings field-name val)
+  #~(string-append
+     #$@(map
+         (match-lambda
+           ((key . value)
+            #~(string-append #$key ": " #$value "\n")))
+         val)))
+
+(define (serialize-inputrc-variables field-name val)
+  #~(string-append
+     #$@(map
+         (match-lambda
+           ((key . #f)
+            #~(string-append "set " #$key " off\n"))
+           ((key . #t)
+            #~(string-append "set " #$key " on\n"))
+           ((key . value)
+            #~(string-append "set " #$key " " #$value "\n")))
+         val)))
+
+(define (serialize-inputrc-conditional-constructs field-name val)
+  #~(string-append
+     #$@(map
+         (match-lambda
+           (("$endif" . _)
+            "$endif\n")
+           (("$include" . value)
+            #~(string-append "$include " #$value "\n"))
+           ;; TODO: key can only be "$if" or "$else".
+           ((key . value)
+            #~(string-append #$key "\n"
+                             #$(serialize-configuration
+                                 value
+                                 home-inputrc-configuration-fields))))
+         val)))
+
+(define (serialize-inputrc-extra-content field-name value)
+  #~(if (string=? #$value "") "" (string-append #$value "\n")))
+
+(define-configuration home-inputrc-configuration
+  (key-bindings
+   (alist '())
+   "Association list of readline key bindings to be added to the
+@code{~/.inputrc} file.  This is where code like this:
+
+@lisp
+'((\"Control-l\" . \"clear-screen\"))
+@end lisp
+
+turns into
+
+@example
+Control-l: clear-screen
+@end example"
+   (serializer serialize-inputrc-key-bindings))
+  (variables
+   (alist '())
+   "Association list of readline variables to set.  This is where configuration
+options like this:
+
+@lisp
+'((\"bell-style\" . \"visible\")
+  (\"colored-completion-prefix\" . #t))
+@end lisp
+
+turns into
+
+@example
+set bell-style visible
+set colored-completion-prefix on
+@end example"
+   (serializer serialize-inputrc-variables))
+  (conditional-constructs
+   (alist '())
+   "Association list of conditionals to add to the initialization file.  This
+includes @command{$if}, @command{else}, @command{endif} and @command{include}
+and they receive a value of another @command{home-inputrc-configuration}.
+
+@lisp
+(conditional-constructs
+ `((\"$if mode=vi\" .
+     ,(home-inputrc-configuration
+        (variables
+         `((\"show-mode-in-prompt\" . #t)))))
+   (\"$else\" .
+     ,(home-inputrc-configuration
+        (key-bindings
+         `((\"Control-l\" . \"clear-screen\")))))
+   (\"$endif\" . #t)))
+@end lisp
+
+turns into
+
+@example
+$if mode=vi
+set show-mode-in-prompt on
+$else
+Control-l: clear-screen
+$endif
+@end example"
+   (serializer serialize-inputrc-conditional-constructs))
+  (extra-content
+   (string "")
+   "Extra content appended as-is to the configuration file.  Run @command{man
+readline} for more information about all the configuration options."
+   (serializer serialize-inputrc-extra-content)))
+
+(define (home-inputrc-files config)
+  (list
+   `(".inputrc"
+     ,(mixed-text-file "inputrc"
+                       (serialize-configuration
+                         config
+                         home-inputrc-configuration-fields)))))
+
+(define home-inputrc-service-type
+  (service-type (name 'inputrc)
+                (extensions
+                 (list (service-extension home-files-service-type
+                                          home-inputrc-files)))
+                (default-value (home-inputrc-configuration))
+                (description "Configure readline in @code{.inputrc}.")))
+
 
 (define (generate-home-shell-profile-documentation)
   (generate-documentation

base-commit: e4087930f3ad60918689be5f4bca4ce3e22429f5
-- 
Efraim Flashner   <efraim <at> flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted





Reply sent to Efraim Flashner <efraim <at> flashner.co.il>:
You have taken responsibility. (Thu, 06 Jul 2023 13:22:01 GMT) Full text and rfc822 format available.

Notification sent to Efraim Flashner <efraim <at> flashner.co.il>:
bug acknowledged by developer. (Thu, 06 Jul 2023 13:22:02 GMT) Full text and rfc822 format available.

Message #16 received at 63909-done <at> debbugs.gnu.org (full text, mbox):

From: Efraim Flashner <efraim <at> flashner.co.il>
To: 64148-done <at> debbugs.gnu.org, 63909-done <at> debbugs.gnu.org
Subject: Re: bug#64148: Acknowledgement ([PATCH v2] home: Add inputrc service.)
Date: Thu, 6 Jul 2023 16:21:48 +0300
[Message part 1 (text/plain, inline)]
Patch pushed

-- 
Efraim Flashner   <efraim <at> flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
[signature.asc (application/pgp-signature, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 04 Aug 2023 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 265 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.