guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#55420] [PATCH 0/2] Add a function to parse emacs elisp's package he


From: Fredrik Salomonsson
Subject: [bug#55420] [PATCH 0/2] Add a function to parse emacs elisp's package header
Date: Thu, 02 Jun 2022 02:53:42 +0000

Hi Ludo,

Ludovic Courtès <ludo@gnu.org> writes:

> Hi Fredrik,
>
> The patches LGTM modulo cosmetic issues:
>
> Fredrik Salomonsson <plattfot@posteo.net> skribis:
>
>> * guix/build/emacs-utils.scm (emacs-batch-script): New procedure.
>
> [...]
>
>> +(define (emacs-batch-script expr)
>> +  "Execute the Elisp code EXPR in Emacs batch mode and return output."
>> +  (call-with-port
>> +      (open-pipe*
>> +       OPEN_READ
>> +       (%emacs) "--quick" "--batch"
>> +       (string-append "--eval=" (expr->string expr)))
>> +    read-string))
>
> I suggest something like:
>
>   (let* ((pipe (open-pipe* …))
>          (output (read-string pipe))
>          (status (close-pipe pipe)))
>     (unless (zero? status)
>       ;; Use SRFI-34 + either a &message condition or (better)
>       ;; a dedicate SRFI-35 condition type for the error.
>       (raise (condition …)))
>     output)
>
> That way, execution failures would be caught and reported.

Thank you for the feedback. I update the procedure to use a dedicated
SRFI-35 condition type. But I cannot figure out how to capture the error
message from emacs, as I want the condition type to contain both the
expression as well as the error you get from emacs.

Here is what I have so far:

    (define-condition-type &emacs-batch-error &error
      emacs-batch-error?
      (expression emacs-batch-error-expression)
      (message emacs-batch-error-message))
    
    (define (emacs-batch-script expr)
      "Execute the Elisp code EXPR in Emacs batch mode and return output."
      (let* ((error-pipe (open-output-string))
             (pipe (with-error-to-port error-pipe
                     (lambda ()
                       (open-pipe*
                        OPEN_READ
                        (%emacs) "--quick" "--batch"
                        (string-append "--eval=" (expr->string expr))))))
             (output (read-string pipe))
             (error (get-output-string error-pipe))
             (status (close-pipe pipe)))
        (unless (zero? status)
          (raise (condition (&emacs-batch-error
                             (expression expr)
                             (message error)))))
        output))

Here is the output when I test it out in the guix repl:
--------------------------------------------------------------------------------
scheme@(guix-user)> (use-modules (guix build emacs-utils))
(use-modules (guix build emacs-utils))
scheme@(guix-user)> (emacs-batch-script '(prog (princ "hello")))
(emacs-batch-script '(prog (princ "hello")))
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Wrong type (expecting exact integer): #<&emacs-batch-error expression: (prog 
(princ "hello")) message: "">

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guix-user) [1]> 
--------------------------------------------------------------------------------

Note the message is empty in #<&emacs-batch-error…>. It should contain:

Debugger entered--Lisp error: (void-function prog)
  (prog (princ "hello"))
  command-line-1(("--eval=(prog (princ \"hello\"))"))
  command-line()
  normal-top-level()

Any idea what I'm doing wrong?

Thanks

-- 
s/Fred[re]+i[ck]+/Fredrik/g





reply via email to

[Prev in Thread] Current Thread [Next in Thread]