• Start Emacs with a minimal bash and emacs lisp mix script for testing.

    From hongyi.zhao@gmail.com@21:1/5 to All on Tue Aug 3 00:16:27 2021
    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 code example given on <https://github.com/hlissner/doom-emacs/blob/develop/bin/doom>.

    Any hints for fixing these problems?

    Regards,
    HY

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Waitzmann@21:1/5 to All on Tue Aug 3 19:20:49 2021
    "hongy...@gmail.com" <hongyi.zhao@gmail.com>:

    [An 123 characters long line deleted]


    Please make use of your return key to avoid overly long lines
    (maximum of 78 characters) when posting via the google web.

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

    […]

    ----------- end --------------

    [Another overly long line deleted]


    $ bash the-bash-elisp-mix-script

    [Another overly long line deleted]


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

    […]

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

    Any hints for fixing these problems?


    Yes.  Answer the following question:  What complains about the token
    ';;' in line 7 and why does it complain?

    Your question reveals, that you don't have any clue about the
    mechanism of the script, so the real answer should be:  If you don't understand it, don't run it.


    You might try


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

    rather than


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

    in that script and see whether that works for you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Helmut Waitzmann on Tue Aug 3 17:53:31 2021
    On Wednesday, August 4, 2021 at 1:21:32 AM UTC+8, Helmut Waitzmann wrote:
    "hongy...@gmail.com" <hongy...@gmail.com>:

    [An 123 characters long line deleted]


    Please make use of your return key to avoid overly long lines
    (maximum of 78 characters) when posting via the google web.

    What about the long URL? Does this break the URL auto recognition by web browser?

    ----------- 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)
    […]

    ----------- end --------------

    [Another overly long line deleted]


    $ bash the-bash-elisp-mix-script

    [Another overly long line deleted]
    init.the-bash-elisp-mix-script: line 7: syntax error near
    unexpected token `;;'
    […]
    The above idea is based on code example given on ><https://github.com/hlissner/doom-emacs/blob/develop/bin/doom>.

    Any hints for fixing these problems?

    Yes. Answer the following question: What complains about the token
    ';;' in line 7 and why does it complain?

    Got it. They are not valid bash command sequences. See the following testings:

    $ ;;
    bash: syntax error near unexpected token `;;'
    $ ;
    bash: syntax error near unexpected token `;'
    $ :;
    $

    Your question reveals, that you don't have any clue about the
    mechanism of the script, so the real answer should be: If you don't understand it, don't run it.


    You might try


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

    Yes, it does the trick, as well as the following one:

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

    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:

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

    rather than
    :; emacs -Q --load "$(realpath -e $0)" -- "$@"
    in that script and see whether that works for you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Javier@21:1/5 to hongy...@gmail.com on Wed Aug 4 06:24:33 2021
    hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
    Please make use of your return key to avoid overly long lines
    (maximum of 78 characters) when posting via the google web.

    What about the long URL? Does this break the URL auto recognition by
    web browser?

    The long URLS you don't need to break, but please break the text
    pararagraphs at 72 chars (or at maximum 78).

    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:

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

    rather than
    :; emacs -Q --load "$(realpath -e $0)" -- "$@"
    in that script and see whether that works for you.

    You just use --script it in the shebang line with no bash code

    #!/usr/bin/emacs --script
    ; elisp code here
    ; ...

    But with --script emacs is executed in batch mode and does not enter interactive mode as your previous example, so it might not be what you
    are looking for.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Javier on Wed Aug 4 07:11:54 2021
    On Wednesday, August 4, 2021 at 7:24:38 PM UTC+8, Javier wrote:
    hongy...@gmail.com <hongy...@gmail.com> wrote:
    Please make use of your return key to avoid overly long lines
    (maximum of 78 characters) when posting via the google web.

    What about the long URL? Does this break the URL auto recognition by
    web browser?
    The long URLS you don't need to break, but please break the text pararagraphs at 72 chars (or at maximum 78).
    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:

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

    rather than
    :; emacs -Q --load "$(realpath -e $0)" -- "$@"
    in that script and see whether that works for you.
    You just use --script it in the shebang line with no bash code

    #!/usr/bin/emacs --script

    Based on my tries, the only shebang line can't start Emacs, while the following can

    #!/usr/local/bin/emacs -Q --script
    or
    #!/usr/local/bin/emacs -q --script

    But they all will load the already existing configurations.

    ; elisp code here
    ; ...

    OTOH, I also tried the following method:

    ------------------- begin ---------------------------
    #!/usr/bin/env bash
    emacs -Q --load <(tail -n +4 "$0")
    exit

    ;;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 ---------------------------

    Though the above method can start Emacs, but I'll see the following info in the *Messages* buffer:

    For information about GNU Emacs and the GNU system, type C-h C-a.
    eval-buffer: Symbol’s function definition is void: straight-use-package


    But with --script emacs is executed in batch mode and does not enter interactive mode as your previous example, so it might not be what you
    are looking for.

    Thank you for your explanation.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Javier@21:1/5 to hongy...@gmail.com on Wed Aug 4 11:03:10 2021
    hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
    On Wednesday, August 4, 2021 at 7:24:38 PM UTC+8, Javier wrote:
    You just use --script it in the shebang line with no bash code

    #!/usr/bin/emacs --script

    Based on my tries, the only shebang line can't start Emacs

    As I told you before '#!/usr/bin/emacs --script' will start emacs in
    batch mode. This means that emacs will exectute the elisp code and
    exit without asking for anything interactive. You will not see an
    emacs window popping up with --script.

    while the following can

    #!/usr/local/bin/emacs -Q --script

    But they all will load the already existing configurations.

    You see an emacs window that loads the existing (~/.emacs I guess) configuration because neither of the -Q nor --script configurations

    You will most likely see a error message in emacs at startup

    Unknown option ‘-Q --script’

    That's because the shebang line can only send 1 command-line option to
    emacs. The shebang line is unable to send two options to emacs (or
    any other program for the matter).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Javier on Wed Aug 4 16:42:37 2021
    On Thursday, August 5, 2021 at 12:03:15 AM UTC+8, Javier wrote:
    hongy...@gmail.com <hongy...@gmail.com> wrote:
    On Wednesday, August 4, 2021 at 7:24:38 PM UTC+8, Javier wrote:
    You just use --script it in the shebang line with no bash code

    #!/usr/bin/emacs --script

    Based on my tries, the only shebang line can't start Emacs
    As I told you before '#!/usr/bin/emacs --script' will start emacs in
    batch mode. This means that emacs will exectute the elisp code and
    exit without asking for anything interactive. You will not see an
    emacs window popping up with --script.
    while the following can

    #!/usr/local/bin/emacs -Q --script

    But they all will load the already existing configurations.
    You see an emacs window that loads the existing (~/.emacs I guess) configuration because neither of the -Q nor --script configurations

    You will most likely see a error message in emacs at startup

    Unknown option ‘-Q --script’

    I confirm that the following info is shown in *Messages* buffer:

    command-line-1: Unknown option ‘-Q --script’

    That's because the shebang line can only send 1 command-line option to emacs. The shebang line is unable to send two options to emacs (or
    any other program for the matter).

    Then, what about the following trick, as I've posted:


    #!/usr/bin/env bash
    emacs -Q --load <(tail -n +4 "$0")
    exit

    [elisp code comes here]

    HY

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)