From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id wBeeNLy5OGLG5wAAgWs5BA (envelope-from ) for ; Mon, 21 Mar 2022 18:45:32 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 6OVtLby5OGJiXgEAG6o9tA (envelope-from ) for ; Mon, 21 Mar 2022 18:45:32 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3CF91359C7 for ; Mon, 21 Mar 2022 18:45:32 +0100 (CET) Received: from localhost ([::1]:36888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nWM5y-0001Sj-Jb for larch@yhetil.org; Mon, 21 Mar 2022 13:45:31 -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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1647884732; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=ZXUgy2F3KowESGc3uqZerlnShvOri7oGPC/+uPz2YNc=; b=LCVTDc6ZJdj6O+xUdu9wrhJIV2BHUozV8CwXHRSg+scOF3SiHzmFEN7W8jKJ0HPJFlL/nO IBuORWX9GTybxHkJR/GM59mab0L+YTVQIn2PKw4csesAYrk27uApzPXrQcRc7um4Iu2k/I ArKtzW/Hk4+sW1vmPAypDhw6DQeiYgK3hRAlPDBGkSxbUqXG1JGdHa0AdNlnXNA+ANxvYj D0eQjxFQMjDbDhJCspCCXgQ42GvNyHD+pjrKA39BxHHb7XubSaLCccf7qfQhQA8rD9/VY8 sK432463Cqf+9zlG6/L6SvPlVX26CLJ9B9P5iesbDcF0lSbJ2cxeL2WwT0Vk2w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1647884732; a=rsa-sha256; cv=none; b=hg4LuKJKTwUNgmG6Hmqi7N2KzhjRFmU91dE1fSV7hTlZX0QgL79dN7OT2HlGQKweqW5SD9 yQx4j5/ltAPT0jfg6fMS/MjKlnla2Je0znsEgcIu4FsSrt+ZDYIND6xYk80qdVfrUPY3y/ TlpMeWL8gSn96VwxyUPu5I6D0mxSkkOXO9xxh2GLvSeZqFeTqj2nb21U2IYRSHu2wTQ1Li 8Xn93gybeeGCUTZkffdbpP8gVuL0SDme+ZqCO1WetPVk9zKZl9TfopRbrb2L71uP9TPPdE I37I9Un0+bpRUyT/gz3DRzoyEu67i4qldeXhNMLmk2MdepdFUVrrdYViPrO9EQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=P6QHh4c7; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 5.88 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=P6QHh4c7; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 3CF91359C7 X-Spam-Score: 5.88 X-Migadu-Scanner: scn1.migadu.com X-TUID: EBX97k0HsBWM * 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 -- 2.34.0