From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 54508@debbugs.gnu.org
Cc: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Subject: [bug#54508] [PATCH 1/2] build: emacs-utils: Add a (as-display) subform to `emacs-substitute-variables'.
Date: Mon, 21 Mar 2022 13:43:14 -0400 [thread overview]
Message-ID: <20220321174315.15097-1-maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <20220321174130.14998-1-maxim.cournoyer@gmail.com>
* 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 <mhw@netris.org>
;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
-;;; Copyright © 2018, 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2018, 2020, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2019 Liliana Marie Prikler <liliana.prikler@gmail.com>
;;;
;;; 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
next prev parent reply other threads:[~2022-03-21 17:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-21 17:41 [bug#54508] [PATCH 0/2] Extend emacs-substitute-variables and patch emacs-gnugo Maxim Cournoyer
2022-03-21 17:43 ` Maxim Cournoyer [this message]
2022-03-21 17:43 ` [bug#54508] [PATCH 2/2] gnu: emacs-gnugo: Patch 'gnugo-program' variable Maxim Cournoyer
2022-04-04 3:57 ` bug#54508: [PATCH 0/2] Extend emacs-substitute-variables and patch emacs-gnugo Maxim Cournoyer
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=20220321174315.15097-1-maxim.cournoyer@gmail.com \
--to=maxim.cournoyer@gmail.com \
--cc=54508@debbugs.gnu.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).