unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: �o�ӡ����Yһ�� <andpuke@foxmail.com>
To: 36219@debbugs.gnu.org
Subject: bug#36219: GNU Emacs 26.1 --eval rejects trailing whitespace
Date: Sat, 15 Jun 2019 10:39:10 +0800	[thread overview]
Message-ID: <tencent_91A99E388C179D45ABA5BF4CB78B6E24C707@qq.com> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 2117 bytes --]

Since commit a90d5e6309c0306d931d398506b242c3eb4f40d7 which fixes bug #23159
the `--eval' command line option signals (error "Trailing garbage following
expression: %s") on more than one expression recevied.

===
$ Emacs --batch --eval "1 2"
Trailing garbage following expression:  2
===

However if there's trailing white space even single valid expression would be
rejected after the fix.

===
$ Emacs --batch --eval "1  "
Trailing garbage following expression:   
===

This causes some old shell script snippets which has trailing newline for
formatting no longer works, such as the follow script from
https://orgmode.org/manual/Batch-Execution.html#Batch-Execution

===
#!/bin/sh
# Tangle files with Org mode
#
emacs -Q --batch --eval "
    (progn
      (require 'ob-tangle)
      (dolist (file command-line-args-left)
        (with-current-buffer (find-file-noselect file)
          (org-babel-tangle))))
  " "$@"
===

From the proposal in bug#23159
https://lists.gnu.org/archive/html/bug-gnu-emacs/2016-07/msg00097.html

> I¡¯d suggest (error =22Trailing garbage following expression¡±)
> for consistency with the eval-expression function.
>
>                 Peace
>                         ¡ªDevon


Since `eval-expression' accepts additional white space and newlines after a
single expression, this mismatch behavior of `--eval' should be considered as a
bug.

My proposed fix is apply `string-trim-right` to received string of expression.

--- lisp/startup.el.old	2019-06-15 10:31:59.000000000 +0800
+++ lisp/startup.el	2019-06-15 10:34:51.000000000 +0800
@@ -2360,7 +2360,9 @@
 
                     ((member argi '("-eval" "-execute"))
                      (setq inhibit-startup-screen t)
-                     (let* ((str-expr (or argval (pop command-line-args-left)))
+                     (let* ((str-expr
+                             (string-trim-right
+                              (or argval (pop command-line-args-left))))
                             (read-data (read-from-string str-expr))
                             (expr (car read-data))
                             (end (cdr read-data)))

             reply	other threads:[~2019-06-15  2:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-15  2:39 �o�ӡ����Yһ�� [this message]
2019-06-15 13:33 ` bug#36219: GNU Emacs 26.1 --eval rejects trailing whitespace Noam Postavsky
2019-06-15 13:54   ` Eli Zaretskii
2019-06-15 14:06     ` Noam Postavsky
2019-06-15 14:24       ` Eli Zaretskii
2019-06-15 21:46         ` Noam Postavsky

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://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_91A99E388C179D45ABA5BF4CB78B6E24C707@qq.com \
    --to=andpuke@foxmail.com \
    --cc=36219@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/emacs.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).