help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to open a file in sh-mode


From: Giorgos Keramidas
Subject: Re: How to open a file in sh-mode
Date: Thu, 14 Aug 2008 16:27:24 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix)

On Thu, 14 Aug 2008 15:01:02 +0200, "Francis Moreau" <francis.moro@gmail.com> 
wrote:
> On Thu, Aug 14, 2008 at 2:24 PM, Giorgos Keramidas
> <keramida@ceid.upatras.gr> wrote:
>>
>> You can probably write a short wrapper script that is used as $FCEDIT to
>> run the equivalent of:
>>
>>    emacs --eval "(setq-default default-major-mode 'sh-mode)" file1 file2 ...
>>
>
> Hmm I don't why I need a wrapper script in that case, do you have an idea ?
>
> If I try without the wrapper I get:
>
> $ export FCEDIT="emacs -nw --eval \"(setq-default default-major-mode
> 'sh-mode)\""
> $ fc
>
> <emacs is started but I get an error in the Messages window>
>
> ("emacs" "--eval" "\"(setq-default" "default-major-mode" "'sh-mode)\""
> "/tmp/bash-fc-247955888988243")

See how the command-line arguments have been split in multiple places by
the shell that evaluated $FCEDIT?

That's why I suggested a wrapper script.  To avoid all the obnoxiously
stupid things expansion of $FCEDIT would do, and make sure that there is
only *one* level of quoting you would have to use.

The parenthesized list quoted above shows that Emacs tried to --eval the
expression "\"(setq-default", which isn't a complete Lisp s-exp (and
this is what Emacs is trying to say with the error message).

Using a shell wrapper makes expansion of the --eval argument much more
predictable here, so I tend to prefer that:

    $ cat > /tmp/fcedit.sh
    #!/bin/sh
    emacs --eval "(setq-default default-major-mode 'sh-mode)" "$@"
    ^D
    $ chmod 0755 /tmp/fcedit.sh
    $ export FCEDIT='/tmp/fcedit.sh -nw'
    $ fc

I have a few of these wrappers in my `~/bin' directory, to help me fire
up Emacs with a variety of options, i.e.:

    ~/bin/emacs-no-gui

        This runs `emacs -nw "$@"'.

    ~/bin/utf-emacs

        This sets up LANG, and LC_ALL, clears every other LC_XXX locale
        variable, and then fires up Emacs in `utf-8 mode'.

and so on.

I really hate having to fight with backslashes to get everything right
in tons of nested quotes, quoted quotes and quoted-quoted quotes ad
infinitum, so that's why I like throwing a wrapper here and there :)





reply via email to

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