[PATCH 0/2] Extend emacs-substitute-variables and patch emacs-gnugo.

DoneSubmitted by Maxim Cournoyer.
Details
One participant
  • Maxim Cournoyer
Owner
unassigned
Severity
normal
M
M
Maxim Cournoyer wrote on 21 Mar 18:41 +0100
(address . guix-patches@gnu.org)(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)
20220321174130.14998-1-maxim.cournoyer@gmail.com
Hello,

This allows formatting sexps using "~a" (display) instead of "~s" (write) when
using `emacs-substitute-variables', as shown in patch 2/2.

Thanks,

Maxim Cournoyer (2):
build: emacs-utils: Add a (as-display) subform to
`emacs-substitute-variables'.
gnu: emacs-gnugo: Patch 'gnugo-program' variable.

gnu/packages/emacs-xyz.scm | 26 ++++++++++++---------
guix/build/emacs-utils.scm | 47 +++++++++++++++++++++++++++++---------
2 files changed, 51 insertions(+), 22 deletions(-)

--
2.34.0
M
M
Maxim Cournoyer wrote on 21 Mar 18:43 +0100
[PATCH 1/2] build: emacs-utils: Add a (as-display) subform to `emacs-substitute-variables'.
(address . 54508@debbugs.gnu.org)(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)
20220321174315.15097-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(-)

Toggle diff (91 lines)
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
M
M
Maxim Cournoyer wrote on 21 Mar 18:43 +0100
[PATCH 2/2] gnu: emacs-gnugo: Patch 'gnugo-program' variable.
(address . 54508@debbugs.gnu.org)(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)
20220321174315.15097-2-maxim.cournoyer@gmail.com
* gnu/packages/emacs-xyz.scm (emacs-gnugo)
[phases]{configure-default-gnugo-xpms-variable}: Rename to...
{configure}: ... this. Patch the 'gnugo-program' variable.
[inputs]: Add gnugo.
[description]: Describe basic usage entry points.
---
gnu/packages/emacs-xyz.scm | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)

Toggle diff (57 lines)
diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index 42fc13f4c2..167d706c05 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -31,7 +31,7 @@
 ;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com>
 ;;; Copyright © 2017–2021 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2017 Mike Gerwitz <mtg@gnu.org>
-;;; Copyright © 2017, 2018, 2019, 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2017, 2018, 2019, 2020, 2021, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2018 Sohom Bhattacharjee <soham.bhattacharjee15@gmail.com>
 ;;; Copyright © 2018, 2019 Mathieu Lirzin <mthl@gnu.org>
 ;;; Copyright © 2018, 2019, 2020, 2021 Pierre Neidhardt <mail@ambrevar.xyz>
@@ -157,6 +157,7 @@ (define-module (gnu packages emacs-xyz)
   #:use-module (gnu packages emacs)
   #:use-module (gnu packages fonts)
   #:use-module (gnu packages freedesktop)
+  #:use-module (gnu packages games)
   #:use-module (gnu packages golang)
   #:use-module (gnu packages guile)
   #:use-module (gnu packages gtk)
@@ -14752,20 +14753,23 @@ (define-public emacs-gnugo
          "138gzdyi8scqimvs49da66j8f5a43bhgpasn1bxzdj2zffwlwp6g"))))
     (build-system emacs-build-system)
     (arguments
-     `(#:phases (modify-phases %standard-phases
-                  (add-after 'unpack 'configure-default-gnugo-xpms-variable
-                    (lambda _
-                      (substitute* "gnugo.el"
-                        (("defvar gnugo-xpms nil")
-                         "defvar gnugo-xpms #'gnugo-imgen-create-xpms"))
-                      #t)))))
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'configure
+           (lambda* (#:key inputs #:allow-other-keys)
+             (emacs-substitute-variables "gnugo.el"
+               ("gnugo-xpms" "#'gnugo-imgen-create-xpms" (as-display))
+               ("gnugo-program" (search-input-file inputs "/bin/gnugo"))))))))
+    (inputs (list gnugo))
     (propagated-inputs
      (list emacs-ascii-art-to-unicode emacs-xpm))
     (home-page "https://elpa.gnu.org/packages/gnugo.html")
     (synopsis "Emacs major mode for playing GNU Go")
-    (description "This package provides an Emacs based interface for GNU Go.
-It has a graphical mode where the board and stones are drawn using XPM images
-and supports the use of a mouse.")
+    (description "This package provides an Emacs based interface for GNU Go,
+which can be started via @samp{M-x gnugo}.  It has a graphical mode where the
+board and stones are drawn using XPM images and supports the use of a mouse.
+You can switch to the graphical mode by running @samp{M-x
+gnugo-image-display-mode}.")
     (license license:gpl3+)))
 
 (define-public emacs-gnuplot
-- 
2.34.0
M
M
Maxim Cournoyer wrote on 4 Apr 05:57 +0200
Re: bug#54508: [PATCH 0/2] Extend emacs-substitute-variables and patch emacs-gnugo.
(address . 54508-done@debbugs.gnu.org)
87ee2d1owj.fsf_-_@gmail.com
Hello,

Pushed as 4ddbcbb6b8d134d9ce9a8d191ba3f0079084eaf8.

Closing.

Maxim
Closed
?
Your comment

This issue is archived.

To comment on this conversation send email to 54508@debbugs.gnu.org