From patchwork Mon Mar 21 17:43:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 37980 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 C3C6027BBEA; Mon, 21 Mar 2022 17:45:28 +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=-3.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable 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 4A5B427BBE9 for ; Mon, 21 Mar 2022 17:45:28 +0000 (GMT) Received: from localhost ([::1]:36888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nWM5v-0001Sj-EA for patchwork@mira.cbaines.net; Mon, 21 Mar 2022 13:45:27 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWM4a-0001Po-2f for guix-patches@gnu.org; Mon, 21 Mar 2022 13:44:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44239) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nWM4Y-0005xa-Qm for guix-patches@gnu.org; Mon, 21 Mar 2022 13:44:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nWM4Y-0006X2-PI for guix-patches@gnu.org; Mon, 21 Mar 2022 13:44:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54508] [PATCH 1/2] build: emacs-utils: Add a (as-display) subform to `emacs-substitute-variables'. References: <20220321174130.14998-1-maxim.cournoyer@gmail.com> In-Reply-To: <20220321174130.14998-1-maxim.cournoyer@gmail.com> Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 21 Mar 2022 17:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54508 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54508@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 54508-submit@debbugs.gnu.org id=B54508.164788461425042 (code B ref 54508); Mon, 21 Mar 2022 17:44:02 +0000 Received: (at 54508) by debbugs.gnu.org; 21 Mar 2022 17:43:34 +0000 Received: from localhost ([127.0.0.1]:38132 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nWM46-0006Vq-AA for submit@debbugs.gnu.org; Mon, 21 Mar 2022 13:43:34 -0400 Received: from mail-qv1-f53.google.com ([209.85.219.53]:39711) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nWM44-0006Vb-6j for 54508@debbugs.gnu.org; Mon, 21 Mar 2022 13:43:33 -0400 Received: by mail-qv1-f53.google.com with SMTP id kj22so1527048qvb.6 for <54508@debbugs.gnu.org>; Mon, 21 Mar 2022 10:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZXUgy2F3KowESGc3uqZerlnShvOri7oGPC/+uPz2YNc=; b=P6QHh4c7mDXAyFUIk/MpCGVuGoHlGtyHlwMWsA5dXgXo7XJUY6NGFs/047ePqZDsJN W1BwQJGZYNr38DrDUeE1SwHNXCTb2u1P9w1/+zB69Mi4LANv5787EjZshTpMOYexteDC 52ax+PFJYRTc6C8BnBMUX+++LC2hJYSPHGY/hO/Drqm2ZFSLgDm5pEENIhLGlsGpWlTL EkBE5BQnDn/Ey/HbAcNwf2ojcSnlLxAb5pFK5uWlc9jpxy9+ptTGlbyWLi5GuH8BVF8N g59fqdH5bMfo2lRMqSCw26fkyAB32G7+p4kvPUkQKEf+1Z34RduBbjUKlPdKPpgNmtv2 iXxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZXUgy2F3KowESGc3uqZerlnShvOri7oGPC/+uPz2YNc=; b=x9mb5ZCLXV5cmU02RSnkgVYKgxDXb8zwx7YCMYyi9ri/KQJ6GK/PU3eGozvPf04A7Z yM9EvJ+CKDafzml4AVXirrvfbMgVvo4KkvfNzZDWIluC4SHqcXcIcWpiNjf7ENiIgmT8 5UwdpGCbe9JR2dgZwYfExbb2SQ44UDzxl8DjImdYWb09vlUEl+XC9tNsl72wCeYzOAiZ AId54+wysPfkdTnywVbhv32x9qwv69rz8pPgZmavF8+fEJahkIjsRLdN/i3tzJkTNLmA mrUHpCARvQ6O2cJOwVLLR5Jld4n8uStSsHKwl55fFT3dOJTzR6SUT2Y5EhhHT9RaD1Vd 2yXg== X-Gm-Message-State: AOAM5308uNu/KFqqY4ChnFpiH5i8yLhjbnkalTN9x1zb0HcsOD7/+j7/ c0ZuAOE9uMq/+gG1P99fO3V41j9vOVA= X-Google-Smtp-Source: ABdhPJysrxVEmsLcFWBC3ndQ+TJieDaLFahqiMKUHl6DjUgNj8/nBceKcrHadDlTyn7WjlRKScCbGg== X-Received: by 2002:a05:6214:19e7:b0:435:c187:ff7d with SMTP id q7-20020a05621419e700b00435c187ff7dmr17093133qvc.109.1647884606471; Mon, 21 Mar 2022 10:43:26 -0700 (PDT) Received: from localhost.localdomain (dsl-10-148-199.b2b2c.ca. [72.10.148.199]) by smtp.gmail.com with ESMTPSA id f206-20020a379cd7000000b0067e620f0d1dsm4479940qke.129.2022.03.21.10.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 10:43:25 -0700 (PDT) From: Maxim Cournoyer Date: Mon, 21 Mar 2022 13:43:14 -0400 Message-Id: <20220321174315.15097-1-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/build/emacs-utils.scm (as-display): New variable. (replacement-helper): New syntax helper. (emacs-substitute-sexps): Use it and update doc. (emacs-substitute-variables): Add an optional 'modifier' datum to the replacement specification, and document it. --- guix/build/emacs-utils.scm | 47 +++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm index 64ef40e25a..60a754b9e9 100644 --- a/guix/build/emacs-utils.scm +++ b/guix/build/emacs-utils.scm @@ -1,7 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014, 2018 Mark H Weaver ;;; Copyright © 2014 Alex Kost -;;; Copyright © 2018, 2020 Maxim Cournoyer +;;; Copyright © 2018, 2020, 2022 Maxim Cournoyer ;;; Copyright © 2019 Liliana Marie Prikler ;;; ;;; This file is part of GNU Guix. @@ -28,6 +28,8 @@ (define-module (guix build emacs-utils) emacs-batch-disable-compilation emacs-generate-autoloads emacs-byte-compile-directory + + as-display emacs-substitute-sexps emacs-substitute-variables)) @@ -82,6 +84,24 @@ (define* (emacs-byte-compile-directory dir) (byte-recompile-directory (file-name-as-directory ,dir) 0 1)))) (emacs-batch-eval expr))) +(define as-display ;syntactic keyword for 'emacs-substitute-sexps' + '(as display)) + +(define-syntax replacement-helper + (syntax-rules (as-display) + ((_ (leading-regexp replacement (as-display))) + `(progn (goto-char (point-min)) + (re-search-forward ,leading-regexp) + (kill-sexp) + (insert " ") + (insert ,(format #f "~a" replacement)))) + ((_ (leading-regexp replacement)) + `(progn (goto-char (point-min)) + (re-search-forward ,leading-regexp) + (kill-sexp) + (insert " ") + (insert ,(format #f "~s" replacement)))))) + (define-syntax emacs-substitute-sexps (syntax-rules () "Substitute the S-expression immediately following the first occurrence of @@ -95,14 +115,15 @@ (define-syntax emacs-substitute-sexps This replaces the default values of the `w3m-command' and `w3m-image-viewer' variables declared in `w3m.el' with the results of the `string-append' calls -above. Note that LEADING-REGEXP uses Emacs regexp syntax." - ((emacs-substitute-sexps file (leading-regexp replacement) ...) +above. Note that LEADING-REGEXP uses Emacs regexp syntax. + +Here is another example that uses the '(as-display)' subform to avoid having +the Elisp procedure symbol from being double quoted: + (emacs-substitute-sexps \"gnugo.el\" + (\"defvar gnugo-xpms\" \"#'gnugo-imgen-create-xpms\" (as-display))" + ((_ file replacement-spec ...) (emacs-batch-edit-file file - `(progn (progn (goto-char (point-min)) - (re-search-forward ,leading-regexp) - (kill-sexp) - (insert " ") - (insert ,(format #f "~S" replacement))) + `(progn ,(replacement-helper replacement-spec) ... (basic-save-buffer)))))) @@ -117,11 +138,15 @@ (define-syntax emacs-substitute-variables This replaces the default values of the `w3m-command' and `w3m-image-viewer' variables declared in `w3m.el' with the results of the `string-append' calls -above." - ((emacs-substitute-variables file (variable replacement) ...) +above. Similarly to `emacs-substitute-sexps', the '(as-display)' subform can +be used to have the replacement formatted like `display' would, which can be +useful to avoid double quotes being added when the replacement is provided as +a string." + ((_ file (variable replacement modifier ...) ...) (emacs-substitute-sexps file ((string-append "(def[a-z]+[[:space:]\n]+" variable "\\>") - replacement) + replacement + modifier ...) ...)))) ;;; emacs-utils.scm ends here