[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/07: build: emacs-utils: Add a (as-display) subform to `emacs-substitu
From: |
guix-commits |
Subject: |
02/07: build: emacs-utils: Add a (as-display) subform to `emacs-substitute-variables'. |
Date: |
Mon, 4 Apr 2022 00:22:09 -0400 (EDT) |
apteryx pushed a commit to branch master
in repository guix.
commit 360e2eb3aca8566e6eaddda68ffdbe6730a49125
Author: Maxim Cournoyer <maxim.cournoyer@gmail.com>
AuthorDate: Mon Mar 21 12:40:50 2022 -0400
build: emacs-utils: Add a (as-display) subform to
`emacs-substitute-variables'.
* 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 @@
emacs-batch-disable-compilation
emacs-generate-autoloads
emacs-byte-compile-directory
+
+ as-display
emacs-substitute-sexps
emacs-substitute-variables))
@@ -82,6 +84,24 @@ true, evaluate using dynamic scoping."
(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 @@ LEADING-REGEXP by the string returned by REPLACEMENT in
FILE. For example:
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 @@ REPLACEMENT in FILE. For example:
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
- branch master updated (32b713e016 -> 367048036d), guix-commits, 2022/04/04
- 01/07: import: pypi: Use new style for the conditional unzip input., guix-commits, 2022/04/04
- 02/07: build: emacs-utils: Add a (as-display) subform to `emacs-substitute-variables'.,
guix-commits <=
- 03/07: gnu: emacs-gnugo: Patch 'gnugo-program' variable., guix-commits, 2022/04/04
- 05/07: gnu: emacs-elpy: Update to 1746e70., guix-commits, 2022/04/04
- 06/07: gnu: git: Update to 2.35.1., guix-commits, 2022/04/04
- 04/07: gnu: emacs-poet-theme: Update to 16eb694., guix-commits, 2022/04/04
- 07/07: gnu: stgit: Update to 1.5., guix-commits, 2022/04/04