From patchwork Sun Dec 24 17:31:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: guix--- via Guix-patches via X-Patchwork-Id: 58043 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6F32B27BBEB; Sun, 24 Dec 2023 19:25:29 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HTML_MESSAGE,MAILING_LIST_MULTI,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 25E7927BBE9 for ; Sun, 24 Dec 2023 19:25:28 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rHU5T-0003Ph-FM; Sun, 24 Dec 2023 14:24:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rHSLQ-000439-Gy for guix-patches@gnu.org; Sun, 24 Dec 2023 12:32:56 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rHSLQ-0008GU-8y for guix-patches@gnu.org; Sun, 24 Dec 2023 12:32:56 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rHSLW-0001wN-7U for guix-patches@gnu.org; Sun, 24 Dec 2023 12:33:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68008] [PATCH] home-fish-configuration: Improve support for abbreviation declaration. Resent-From: lgcoelho@disroot.org Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 24 Dec 2023 17:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68008 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68008@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.17034391417402 (code B ref -1); Sun, 24 Dec 2023 17:33:01 +0000 Received: (at submit) by debbugs.gnu.org; 24 Dec 2023 17:32:21 +0000 Received: from localhost ([127.0.0.1]:53481 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rHSKq-0001vK-BI for submit@debbugs.gnu.org; Sun, 24 Dec 2023 12:32:20 -0500 Received: from lists.gnu.org ([2001:470:142::17]:43002) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rHSKo-0001v6-KM for submit@debbugs.gnu.org; Sun, 24 Dec 2023 12:32:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rHSKc-0003yv-MA for guix-patches@gnu.org; Sun, 24 Dec 2023 12:32:06 -0500 Received: from layka.disroot.org ([178.21.23.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rHSKX-00085p-TH for guix-patches@gnu.org; Sun, 24 Dec 2023 12:32:06 -0500 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id D716141300 for ; Sun, 24 Dec 2023 18:31:51 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jLJrpO7quVw0 for ; Sun, 24 Dec 2023 18:31:51 +0100 (CET) MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1703439110; bh=wLsSaP53Q04C3APUaSeBQn3zns+4qHcz+e6EwpFRyYM=; h=Date:From:To:Subject; b=Eek0/a5pLgf8uvfSHSoDWfw3vZorWp4gQWOKCnmSfjWniyS2nLHUPSJrG916ugSJQ QQS35p43fkNlSh/5mdPQVHtTIs9x/OtT/g1V1ryzlvP+bHqzolexcBjPBgTeyyNIpX dCp1HHBAOMZfyWg0OtRnE8HAh17gxwoERl6FAKgSmBZ7U53OXA8ZXmtV5BgiiksFUW u3F68xsqm/DydJUvV6azmGta3rlQyNloUVvf0OExrp0ZP+GlKCxnzpQK+cWg9/7BoH MpnXWtwIpQkorpvw501JuvdsRRpX40bTIuRCcGzGaZOUclBrxoU90Ry3Vn3GchZmog 347gnFR8cSHLg== Date: Sun, 24 Dec 2023 17:31:50 +0000 Message-ID: X-Sender: lgcoelho@disroot.org Received-SPF: pass client-ip=178.21.23.139; envelope-from=lgcoelho@disroot.org; helo=layka.disroot.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Mailman-Approved-At: Sun, 24 Dec 2023 14:24:33 -0500 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: lgcoelho@disroot.org X-ACL-Warn: , lgcoelho--- via Guix-patches X-Patchwork-Original-From: lgcoelho--- via Guix-patches via From: guix--- via Guix-patches via Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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. From 7bce71c883499802bc52d55b6ca9718abb317468 Mon Sep 17 00:00:00 2001 From: Luis Guilherme Coelho 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 ;;; Copyright © 2021 Xinglu Chen ;;; Copyright © 2023 Efraim Flashner +;;; Copyright © 2023 Luis Guilherme Coelho ;;; ;;; 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 name) + fish-function? + (name fish-function-name)) + +(define-record-type* + 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 | + +(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 + (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