[PATCH] home-fish-configuration: Improve support for abbreviation declaration.

  • Open
  • quality assurance status badge
Details
One participant
  • lgcoelho
Owner
unassigned
Submitted by
lgcoelho
Severity
normal
L
L
lgcoelho wrote on 24 Dec 2023 18:31
(address . guix-patches@gnu.org)
ea296ea7f586db97f28bae211b11537d@disroot.org
The current support for abbreviations in home-fish-configuration is very
limited, one can only specify the abbreviation name and expansion, or if
determined enough, specify additional options like this:

--8<---------------cut
here------------------------end--------------->8---

`(("--position anywhere abbreviation-name" . "expansion"))
--8<---------------cut
here------------------------end--------------->8---

Which is quite weird, and gets weirder when additional options like
marker, function, pattern and others are specified. The new abbreviation
record type solves this issue, making abbreviation declaration more
consistent with the usual Guix style.
Attachment: file
From 7bce71c883499802bc52d55b6ca9718abb317468 Mon Sep 17 00:00:00 2001
From: Luis Guilherme Coelho <lgcoelho@disroot.org>
Date: Sun, 24 Dec 2023 14:12:52 -0300
Subject: [PATCH 2/2] home-fish-configuration: Use records for better
abbreviation support

---
gnu/home/services/shells.scm | 62 +++++++++++++++++++++++++++++++-----
1 file changed, 54 insertions(+), 8 deletions(-)

Toggle diff (112 lines)
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index 9dd56f634a..0ae7ac2358 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -2,6 +2,7 @@
;;; Copyright © 2021 Andrew Tropin <andrew@trop.in>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2023 Luis Guilherme Coelho <lgcoelho@disroot.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -29,6 +30,7 @@ (define-module (gnu home services shells)
#:use-module (guix packages)
#:use-module (guix records)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-9)
#:use-module (srfi srfi-26)
#:use-module (ice-9 match)
@@ -47,6 +49,18 @@ (define-module (gnu home services shells)
home-fish-configuration
home-fish-extension
+ abbreviation
+ abbreviation-expansion
+ abbreviation-marker
+ abbreviation-position
+ abbreviation-pattern
+ abbreviation-name
+ abbreviation?
+
+ fish-function
+ fish-function-name
+ fish-function?
+
home-inputrc-service-type
home-inputrc-configuration))
@@ -517,12 +531,44 @@ (define (serialize-fish-aliases field-name val)
(_ ""))
val)))
+(define-record-type <fish-function>
+ (fish-function name)
+ fish-function?
+ (name fish-function-name))
+
+(define-record-type* <abbreviation>
+ abbreviation make-abbreviation
+ abbreviation?
+ (name abbreviation-name) ; string | symbol
+ (pattern abbreviation-pattern ; string | #f
+ (default #f))
+ (position abbreviation-position ; 'command | 'anywhere | #f
+ (default #f)) ; defaults to 'command -´
+ (marker abbreviation-marker ; char
+ (default #\%))
+ (expansion abbreviation-expansion)) ; string | <fish-function>
+
+(define list-of-abbreviations?
+ (list-of abbreviation?))
+
(define (serialize-fish-abbreviations field-name val)
#~(string-append
- #$@(map (match-lambda
- ((key . value)
- #~(string-append "abbr --add " #$key " " #$value "\n"))
- (_ ""))
+ #$@(map (match-record-lambda <abbreviation>
+ (name pattern position marker expansion)
+ #~((@@ (ice-9 format) format) #f
+ "~%abbr --add '~a' \\~%~
+ ~@[ --position ~a \\~%~]~
+ ~@[ --regex \"~a\" \\~%~]~
+ ~@[ --set-cursor=~a \\~%~]~
+ ~@[ ~a~]~%"
+ '#$name
+ '#$position
+ #$pattern
+ #$marker
+ #$(if (fish-function? expansion)
+ (format #f "--function ~a"
+ (fish-function-name expansion))
+ (format #f "\"~a\"" expansion))))
val)))
(define (serialize-fish-env-vars field-name val)
@@ -556,9 +602,9 @@ (define-configuration home-fish-configuration
shells, see the @code{abbreviations} field."
(serializer serialize-fish-aliases))
(abbreviations
- (alist '())
- "Association list of abbreviations for Fish. These are words that,
-when typed in the shell, will automatically expand to the full text."
+ (list-of-abbreviations '())
+ "List of abbreviations for Fish. These are words that, when
+typed in the shell, will automatically expand to the full text."
(serializer serialize-fish-abbreviations)))
(define (fish-files-service config)
@@ -597,7 +643,7 @@ (define-configuration/no-serialization home-fish-extension
(alist '())
"Association list of Fish aliases.")
(abbreviations
- (alist '())
+ (list-of-abbreviations '())
"Association list of Fish abbreviations."))
(define (home-fish-extensions original-config extension-configs)
--
2.41.0
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 68008@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 68008
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch