unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Start Emacs with a minimal bash and Emacs lisp mixed script for testing.
@ 2021-08-03  8:52 Hongyi Zhao
  2021-08-03 15:55 ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 6+ messages in thread
From: Hongyi Zhao @ 2021-08-03  8:52 UTC (permalink / raw)
  To: help-gnu-emacs

On Ubuntu 20.04, I'm using the following minimal bash and emacs lisp
mix script to test/debug specific Emacs configurations:
----------- begin --------------
#!/usr/bin/env bash
:; set -e # -*- mode: emacs-lisp; lexical-binding: t -*-
:; # https://github.com/abo-abo/swiper/issues/2899#issuecomment-889926472
:; # https://github.com/hlissner/doom-emacs/blob/develop/bin/doom
:; emacs -Q --load "$(realpath -e $0)" -- "$@"

;;Bootstrap straight
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el"
user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)
[...]
----------- end --------------

I find the above script can start Emacs successfully with the
following calling method:

$ bash the-bash-elisp-mix-script

But when quit Emacs with `C-x C-c', the script always complains the
following info:

init.the-bash-elisp-mix-script: line 7: syntax error near unexpected token `;;'


OTOH, if I change the Emacs command line in the above script into the following:

:; emacs -Q --script "$(realpath -e $0)" -- "$@"

The script will refuse to start, and the following info will be
triggered immediately:

$ bash init.the-bash-elisp-mix-script
init.the-bash-elisp-mix-script: line 7: syntax error near unexpected token `;;'
$

The above idea is based on the code example given on
<https://github.com/hlissner/doom-emacs/blob/develop/bin/doom>.

Any hints for fixing these problems?

Regards,
HY
--
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Start Emacs with a minimal bash and Emacs lisp mixed script for testing.
  2021-08-03  8:52 Start Emacs with a minimal bash and Emacs lisp mixed script for testing Hongyi Zhao
@ 2021-08-03 15:55 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-03 16:08   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-03 15:55 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

> #!/usr/bin/env bash
> :; set -e # -*- mode: emacs-lisp; lexical-binding: t -*-
> :; # https://github.com/abo-abo/swiper/issues/2899#issuecomment-889926472
> :; # https://github.com/hlissner/doom-emacs/blob/develop/bin/doom
> :; emacs -Q --load "$(realpath -e $0)" -- "$@"
>
> ;;Bootstrap straight
> [...]
>
> But when quit Emacs with `C-x C-c', the script always complains the
> following info:
>
> init.the-bash-elisp-mix-script: line 7: syntax error near
> unexpected token `;;'

The bash script will continue to execute after you kill Emacs.

Try:

  #! /bin/bash

  :; set -e
  :; emacs -Q --load "$(realpath -e $0)" -- "$@"; exit

  (setq test-var 3)

Then type test-var and do `eval-last-sexp'.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Start Emacs with a minimal bash and Emacs lisp mixed script for testing.
  2021-08-03 15:55 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-03 16:08   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-04  0:26     ` Hongyi Zhao
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-03 16:08 UTC (permalink / raw)
  To: help-gnu-emacs

> Try:
>
>   #! /bin/bash
>
>   :; set -e
>   :; emacs -Q --load "$(realpath -e $0)" -- "$@"; exit
>
>   (setq test-var 3)
>
> Then type test-var and do `eval-last-sexp'.

Or even more minimal:

  #! /bin/zsh

  ; emacs -Q --load "$(realpath -e $0)"; exit

  (setq test-var 1)

(I changed the shell to zsh because that's what I use.)

And you don't have to do 'bash SCRIPT', instead just
'chmod +x SCRIPT', put in $PATH, and 'SCRIPT'.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Start Emacs with a minimal bash and Emacs lisp mixed script for testing.
  2021-08-03 16:08   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-04  0:26     ` Hongyi Zhao
  2021-08-04  0:34       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 6+ messages in thread
From: Hongyi Zhao @ 2021-08-04  0:26 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

On Wed, Aug 4, 2021 at 12:09 AM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> > Try:
> >
> >   #! /bin/bash
> >
> >   :; set -e
> >   :; emacs -Q --load "$(realpath -e $0)" -- "$@"; exit
> >
> >   (setq test-var 3)
> >
> > Then type test-var and do `eval-last-sexp'.
>
> Or even more minimal:
>
>   #! /bin/zsh
>
>   ; emacs -Q --load "$(realpath -e $0)"; exit

Wonderful. The key point is the `exit' command used here, which will
fix the error I encountered. After I posted this email, I found
another similar usage [1], which is exactly the trick you suggested
above.

Another question: how to do the same job with the `--script' option of
Emacs? I've tried with the following command, but failed to start
Emacs:

:; emacs -Q --script $(realpath -e $0); exit


[1] https://github.com/alphapapa/matrix-client.el/blob/d2ac55293c96d4c95971ed8e2a3f6f354565c5ed/matrix-client-standalone.el.sh#L64-L81

>   (setq test-var 1)
>
> (I changed the shell to zsh because that's what I use.)
>
> And you don't have to do 'bash SCRIPT', instead just
> 'chmod +x SCRIPT', put in $PATH, and 'SCRIPT'.

Thank you for your suggestion.

Best regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Start Emacs with a minimal bash and Emacs lisp mixed script for testing.
  2021-08-04  0:26     ` Hongyi Zhao
@ 2021-08-04  0:34       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-04  0:56         ` Hongyi Zhao
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-04  0:34 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

> Another question: how to do the same job with the `--script'
> option of Emacs? I've tried with the following command, but
> failed to start Emacs:
>
> :; emacs -Q --script $(realpath -e $0); exit

#! /bin/zsh

; emacs -Q --script "$(realpath -e $0)"; exit

(message "what's up what's up wanna party or what say

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Start Emacs with a minimal bash and Emacs lisp mixed script for testing.
  2021-08-04  0:34       ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-04  0:56         ` Hongyi Zhao
  0 siblings, 0 replies; 6+ messages in thread
From: Hongyi Zhao @ 2021-08-04  0:56 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

On Wed, Aug 4, 2021 at 8:34 AM Emanuel Berg via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > Another question: how to do the same job with the `--script'
> > option of Emacs? I've tried with the following command, but
> > failed to start Emacs:
> >
> > :; emacs -Q --script $(realpath -e $0); exit
>
> #! /bin/zsh
>
> ; emacs -Q --script "$(realpath -e $0)"; exit

This can also be written as:

; exec emacs -Q --script "$(realpath -e $0)"

See <https://groups.google.com/g/comp.unix.shell/c/krxzfCd_8qM/m/W2Lc5W-jCAAJ>
for more detailed discussion.

> (message "what's up what's up wanna party or what say

Should be:

(message "what's up what's up wanna party or what say")

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-04  0:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-03  8:52 Start Emacs with a minimal bash and Emacs lisp mixed script for testing Hongyi Zhao
2021-08-03 15:55 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-03 16:08   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-04  0:26     ` Hongyi Zhao
2021-08-04  0:34       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-04  0:56         ` Hongyi Zhao

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).