unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: lgcoelho--- via Guix-patches via <guix-patches@gnu.org>
To: 68008@debbugs.gnu.org
Subject: [bug#68008] [PATCH] home-fish-configuration: Improve support for abbreviation declaration.
Date: Sun, 24 Dec 2023 17:31:50 +0000	[thread overview]
Message-ID: <ea296ea7f586db97f28bae211b11537d@disroot.org> (raw)


[-- 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


                 reply	other threads:[~2023-12-24 19:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ea296ea7f586db97f28bae211b11537d@disroot.org \
    --to=guix-patches@gnu.org \
    --cc=68008@debbugs.gnu.org \
    --cc=lgcoelho@disroot.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.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).