all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#68008] [PATCH] home-fish-configuration: Improve support for abbreviation declaration.
@ 2023-12-24 17:31 lgcoelho--- via Guix-patches via
  0 siblings, 0 replies; only message in thread
From: lgcoelho--- via Guix-patches via @ 2023-12-24 17:31 UTC (permalink / raw)
  To: 68008


[-- Attachment #1.1: Type: text/plain, Size: 668 bytes --]

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 #1.2: Type: text/html, Size: 929 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-home-fish-configuration-Use-records-for-better-abbre.patch --]
[-- Type: text/x-diff; name=0002-home-fish-configuration-Use-records-for-better-abbre.patch, Size: 4384 bytes --]

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

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-24 19:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-24 17:31 [bug#68008] [PATCH] home-fish-configuration: Improve support for abbreviation declaration lgcoelho--- via Guix-patches via

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.