* How to open a file in sh-mode @ 2008-08-14 7:53 Francis Moreau 2008-08-14 8:16 ` Henrik Austad 2008-08-14 8:26 ` David Hansen 0 siblings, 2 replies; 28+ messages in thread From: Francis Moreau @ 2008-08-14 7:53 UTC (permalink / raw) To: gnu-emacs-help Hello, I'm trying to open a file with emacs automatically set on sh-mode. The file name can't be used to guess that emacs should be in sh-mode when opening it. So I tried: $ emacs -f sh-mode foo But that doesn't work. Could anybody give me some advices ? Thanks -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 7:53 How to open a file in sh-mode Francis Moreau @ 2008-08-14 8:16 ` Henrik Austad 2008-08-14 9:03 ` Francis Moreau 2008-08-14 8:26 ` David Hansen 1 sibling, 1 reply; 28+ messages in thread From: Henrik Austad @ 2008-08-14 8:16 UTC (permalink / raw) To: help-gnu-emacs On Thursday 14 August 2008 09:53:39 Francis Moreau wrote: > Hello, > > I'm trying to open a file with emacs automatically set on sh-mode. > The file name can't be used to guess that emacs should be in sh-mode > when opening it. > > So I tried: > > $ emacs -f sh-mode foo > > But that doesn't work. > > Could anybody give me some advices ? 1) which version of emacs are you using? 2) is it a valid-sh file? i.e. does it start with #!/bin/bash on the first line? 3) have you enabled syntax-highlighting in the first place? if unsure, add (global-font-lock-mode t) to your ~/.emacs I've testet a file foo with the following content #!/bin/bash echo "Hello World" and emacs syntax-highlight this with versions 21, 22, 23.0.50 and 23.0.60 (although I expect that if it works in one version, it'll work in all). -- Med vennlig hilsen - Yours Sincerely Henrik Austad ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 8:16 ` Henrik Austad @ 2008-08-14 9:03 ` Francis Moreau 2008-08-14 10:03 ` Henrik Austad 0 siblings, 1 reply; 28+ messages in thread From: Francis Moreau @ 2008-08-14 9:03 UTC (permalink / raw) To: Henrik Austad; +Cc: help-gnu-emacs On Thu, Aug 14, 2008 at 10:16 AM, Henrik Austad <henrikau@stud.ntnu.no> wrote: > On Thursday 14 August 2008 09:53:39 Francis Moreau wrote: >> Hello, >> >> I'm trying to open a file with emacs automatically set on sh-mode. >> The file name can't be used to guess that emacs should be in sh-mode >> when opening it. >> >> So I tried: >> >> $ emacs -f sh-mode foo >> >> But that doesn't work. >> >> Could anybody give me some advices ? > > 1) which version of emacs are you using? > 2) is it a valid-sh file? i.e. does it start with #!/bin/bash on the first > line? No, it's actually the file created by fc(1) to edit the bash history. It uses the FCEDIT env variable to launch the editor it going to use. So I'd like to set it to: export FCEDIT="emacs -f sh-mode" so that fc(1) uses emacs as editor in sh-mode directly. Note that the name of the temporary file is *appended* to what you specified in FCEDIT. -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 9:03 ` Francis Moreau @ 2008-08-14 10:03 ` Henrik Austad 2008-08-14 10:06 ` Francis Moreau [not found] ` <mailman.16667.1218708430.18990.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 28+ messages in thread From: Henrik Austad @ 2008-08-14 10:03 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 1844 bytes --] On Thursday 14 August 2008 11:03:07 Francis Moreau wrote: > On Thu, Aug 14, 2008 at 10:16 AM, Henrik Austad <henrikau@stud.ntnu.no> wrote: > > On Thursday 14 August 2008 09:53:39 Francis Moreau wrote: > >> Hello, > >> > >> I'm trying to open a file with emacs automatically set on sh-mode. > >> The file name can't be used to guess that emacs should be in sh-mode > >> when opening it. > >> > >> So I tried: > >> > >> $ emacs -f sh-mode foo > >> > >> But that doesn't work. > >> > >> Could anybody give me some advices ? > > > > 1) which version of emacs are you using? > > 2) is it a valid-sh file? i.e. does it start with #!/bin/bash on the > > first line? > > No, it's actually the file created by fc(1) to edit the bash history. > > It uses the FCEDIT env variable to launch the editor it going to use. > > So I'd like to set it to: > > export FCEDIT="emacs -f sh-mode" > > so that fc(1) uses emacs as editor in sh-mode directly. > > Note that the name of the temporary file is *appended* to what you > specified in FCEDIT. so, basically you are looking for a way of putting #!/bin/bash before the output of fc is included? I don't see any obvious ways of doing this, but, you could, if you wanted to, use .bash_history (or the appropriate history-file for your shell) and grep for what you want there? When you set emacs to be the editor, remember that you call emacs with a new file as argument, i.e. if you specify foo as a file, emacs will open *both* foo and the new file from fc. You could, perhaps, add a hook in .emacs as all files created by fc starts with [shell]-fc-<numbers> so basically, I think the question boils down to: """ How do I create a hook in my .emacs so that all files starting with bash-fc-* will load sh-mode? """ -- mvh Henrik Austad [-- Attachment #2: This is a digitally signed message part. --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 10:03 ` Henrik Austad @ 2008-08-14 10:06 ` Francis Moreau 2008-08-14 11:17 ` David Hansen 2008-08-14 11:36 ` Henrik Austad [not found] ` <mailman.16667.1218708430.18990.help-gnu-emacs@gnu.org> 1 sibling, 2 replies; 28+ messages in thread From: Francis Moreau @ 2008-08-14 10:06 UTC (permalink / raw) To: henrikau; +Cc: help-gnu-emacs On Thu, Aug 14, 2008 at 12:03 PM, Henrik Austad <henrikau@stud.ntnu.no> wrote: > > so basically, I think the question boils down to: > > """ > How do I create a hook in my .emacs so that all files starting with bash-fc-* > will load sh-mode? > """ > Well that would be the last thing I would do. My question is: """ How do I start emacs in sh-mode from the shell with a file name appended at the end of the command """ It doesn't seem to be all that complex ! -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 10:06 ` Francis Moreau @ 2008-08-14 11:17 ` David Hansen 2008-08-14 11:36 ` Henrik Austad 1 sibling, 0 replies; 28+ messages in thread From: David Hansen @ 2008-08-14 11:17 UTC (permalink / raw) To: help-gnu-emacs On Thu, 14 Aug 2008 12:06:59 +0200 Francis Moreau wrote: > """ > How do I start emacs in sh-mode from the shell with a file name > appended at the end of the command > """ emacs --eval '(progn (find-file "tmp/tst.c") (sh-mode))' You'll have to write some wrapper script for your use in an env var. > It doesn't seem to be all that complex! It will become complex when the file name contains special characters (mixing sh and emacs quoting is very nasty and I don't know about any solution). David ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 10:06 ` Francis Moreau 2008-08-14 11:17 ` David Hansen @ 2008-08-14 11:36 ` Henrik Austad 2008-08-14 11:51 ` Francis Moreau 1 sibling, 1 reply; 28+ messages in thread From: Henrik Austad @ 2008-08-14 11:36 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 938 bytes --] On Thursday 14 August 2008 12:06:59 Francis Moreau wrote: > On Thu, Aug 14, 2008 at 12:03 PM, Henrik Austad <henrikau@stud.ntnu.no> wrote: > > so basically, I think the question boils down to: > > > > """ > > How do I create a hook in my .emacs so that all files starting with > > bash-fc-* will load sh-mode? > > """ > > Well that would be the last thing I would do. > > My question is: > > """ > How do I start emacs in sh-mode from the shell with a file name > appended at the end of the command > """ > > It doesn't seem to be all that complex ! ok, I think I got something that works, thanks to all the guys at #emacs for this (ams, pgas, bpalmer) In .emacs add the following: (add-to-list 'auto-mode-alist '("bash-fc" . sh-mode)) then; export FCEDIT="emacs" then sh-mode will be loaded when you open files starting with bash-fc as a test; echo "Hello World" && fc -- mvh Henrik Austad [-- Attachment #2: This is a digitally signed message part. --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 11:36 ` Henrik Austad @ 2008-08-14 11:51 ` Francis Moreau 2008-08-14 11:57 ` Lennart Borgman (gmail) 0 siblings, 1 reply; 28+ messages in thread From: Francis Moreau @ 2008-08-14 11:51 UTC (permalink / raw) To: Henrik Austad; +Cc: help-gnu-emacs On Thu, Aug 14, 2008 at 1:36 PM, Henrik Austad <henrikau@orakel.ntnu.no> wrote: > ok, I think I got something that works, thanks to all the guys at #emacs for > this (ams, pgas, bpalmer) > > In .emacs add the following: > (add-to-list 'auto-mode-alist '("bash-fc" . sh-mode)) > > then; > export FCEDIT="emacs" > > then sh-mode will be loaded when you open files starting with bash-fc > > as a test; > echo "Hello World" && fc > thanks for that but emacs command line option usage look soooo weird -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 11:51 ` Francis Moreau @ 2008-08-14 11:57 ` Lennart Borgman (gmail) 0 siblings, 0 replies; 28+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-14 11:57 UTC (permalink / raw) To: Francis Moreau; +Cc: help-gnu-emacs Francis Moreau wrote: > On Thu, Aug 14, 2008 at 1:36 PM, Henrik Austad <henrikau@orakel.ntnu.no> wrote: >> ok, I think I got something that works, thanks to all the guys at #emacs for >> this (ams, pgas, bpalmer) >> >> In .emacs add the following: >> (add-to-list 'auto-mode-alist '("bash-fc" . sh-mode)) >> >> then; >> export FCEDIT="emacs" >> >> then sh-mode will be loaded when you open files starting with bash-fc >> >> as a test; >> echo "Hello World" && fc >> > > thanks for that but emacs command line option usage look soooo weird Maybe, but as I tried to say before: it is emacsclient, not emacs that you normally use to open files in Emacs. ^ permalink raw reply [flat|nested] 28+ messages in thread
[parent not found: <mailman.16667.1218708430.18990.help-gnu-emacs@gnu.org>]
* Re: How to open a file in sh-mode [not found] ` <mailman.16667.1218708430.18990.help-gnu-emacs@gnu.org> @ 2008-08-14 12:24 ` Giorgos Keramidas 2008-08-14 13:01 ` Francis Moreau 0 siblings, 1 reply; 28+ messages in thread From: Giorgos Keramidas @ 2008-08-14 12:24 UTC (permalink / raw) To: help-gnu-emacs On Thu, 14 Aug 2008 12:06:59 +0200, "Francis Moreau" <francis.moro@gmail.com> wrote: > On Thu, Aug 14, 2008 at 12:03 PM, Henrik Austad <henrikau@stud.ntnu.no> wrote: >> >> so basically, I think the question boils down to: >> >> """ >> How do I create a hook in my .emacs so that all files starting with bash-fc-* >> will load sh-mode? >> """ > > Well that would be the last thing I would do. > > My question is: > > """ > How do I start emacs in sh-mode from the shell with a file name > appended at the end of the command > """ > > It doesn't seem to be all that complex ! 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 ... That's a bit like "cheating", but it does work. You are essentially firing up Emacs with a default-mode of `sh-mode' for new files, which is nice for editing shell history output. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 12:24 ` Giorgos Keramidas @ 2008-08-14 13:01 ` Francis Moreau 2008-08-14 13:27 ` Giorgos Keramidas 0 siblings, 1 reply; 28+ messages in thread From: Francis Moreau @ 2008-08-14 13:01 UTC (permalink / raw) To: Giorgos Keramidas; +Cc: help-gnu-emacs 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") Loading encoded-kb...done Loading /usr/share/emacs/site-lisp/site-start.d/focus-init.el (source)...done Loading /usr/share/emacs/site-lisp/site-start.d/igrep-init.el (source)...done Loading /usr/share/emacs/site-lisp/site-start.d/php-mode-init.el (source)...done Loading /usr/share/emacs/site-lisp/site-start.d/po-mode-init.el (source)...done Loading /usr/share/emacs/site-lisp/site-start.d/rpm-spec-mode-init.el (source)...done Loading easy-mmode...done Loading easymenu...done Loading cl-macs...done Loading paren...done .... command-line-1: End of file during parsing Loading cl-seq...done > That's a bit like "cheating", but it does work. yes. -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 13:01 ` Francis Moreau @ 2008-08-14 13:27 ` Giorgos Keramidas 2008-08-14 13:48 ` Francis Moreau 0 siblings, 1 reply; 28+ messages in thread From: Giorgos Keramidas @ 2008-08-14 13:27 UTC (permalink / raw) To: Francis Moreau; +Cc: help-gnu-emacs 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 :) ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 13:27 ` Giorgos Keramidas @ 2008-08-14 13:48 ` Francis Moreau 2008-08-14 14:23 ` Giorgos Keramidas 0 siblings, 1 reply; 28+ messages in thread From: Francis Moreau @ 2008-08-14 13:48 UTC (permalink / raw) To: Giorgos Keramidas; +Cc: help-gnu-emacs On Thu, Aug 14, 2008 at 3:27 PM, Giorgos Keramidas <keramida@ceid.upatras.gr> wrote: > 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? > hmm not really. Could you tell me what's wrong here ? IOW how emacs have been launched ? thanks -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 13:48 ` Francis Moreau @ 2008-08-14 14:23 ` Giorgos Keramidas 0 siblings, 0 replies; 28+ messages in thread From: Giorgos Keramidas @ 2008-08-14 14:23 UTC (permalink / raw) To: Francis Moreau; +Cc: help-gnu-emacs On Thu, 14 Aug 2008 15:48:57 +0200, Francis Moreau wrote: > On Thu, Aug 14, 2008 at 3:27 PM, Giorgos Keramidas wrote: >> On Thu, 14 Aug 2008 15:01:02 +0200, Francis Moreau wrote: >>> <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? > > hmm not really. > > Could you tell me what's wrong here ? IOW how emacs have been launched? It has been launched with the following command-line arguments: arg[0] = "emacs" arg[1] = "--eval" arg[2] = "\"(setq-default" arg[3] = "default-major-mode" arg[4] = "'sh-mode)\"" arg[5] = "/tmp/bash-fc-247955888988243" The shell that launched $FCEDIT as an editor, looked at its value, saw that it had space characters in it, and split the $FCEDIT value to several separate arguments at every unquoted space. Try firing up Emacs with the following two commands, and look at the *Messages* buffer to spot the difference: emacs -nw "foo" "bar" emacs -nw "foo bar" The first should display: ("emacs" "-nw" "foo" "bar") but the second should display: ("emacs" "-nw" "foo bar") It may be possible to quote FCEDIT's value in some complex manner to achieve the effect of second list, where the s-exp passed to --eval is a single entry in the command-line argument list. Is it worth all the trouble to get it `right'? My own personal preference at this point is to say `No, not really. I can write a shell wrapper, and be done with it in half a minute or so' :-) ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 7:53 How to open a file in sh-mode Francis Moreau 2008-08-14 8:16 ` Henrik Austad @ 2008-08-14 8:26 ` David Hansen 2008-08-14 9:04 ` Francis Moreau 1 sibling, 1 reply; 28+ messages in thread From: David Hansen @ 2008-08-14 8:26 UTC (permalink / raw) To: help-gnu-emacs On Thu, 14 Aug 2008 09:53:39 +0200 Francis Moreau wrote: > Could anybody give me some advices ? Put "#!/bin/sh" or "# -*- mode: sh; -*-" in the first line of the file. David ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 8:26 ` David Hansen @ 2008-08-14 9:04 ` Francis Moreau 2008-08-14 9:23 ` Thierry Volpiatto 2008-08-14 10:58 ` Peter Dyballa 0 siblings, 2 replies; 28+ messages in thread From: Francis Moreau @ 2008-08-14 9:04 UTC (permalink / raw) To: help-gnu-emacs On Thu, Aug 14, 2008 at 10:26 AM, David Hansen <david.hansen@gmx.net> wrote: > On Thu, 14 Aug 2008 09:53:39 +0200 Francis Moreau wrote: > >> Could anybody give me some advices ? > > Put "#!/bin/sh" or "# -*- mode: sh; -*-" in the first line of the file. > As I previously replied I can't. Please see my answer to Henrik. But IMHO that's an ugly workaround anyways Thanks -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 9:04 ` Francis Moreau @ 2008-08-14 9:23 ` Thierry Volpiatto 2008-08-14 9:34 ` Francis Moreau 2008-08-14 10:58 ` Peter Dyballa 1 sibling, 1 reply; 28+ messages in thread From: Thierry Volpiatto @ 2008-08-14 9:23 UTC (permalink / raw) To: Francis Moreau; +Cc: help-gnu-emacs "Francis Moreau" <francis.moro@gmail.com> writes: > On Thu, Aug 14, 2008 at 10:26 AM, David Hansen <david.hansen@gmx.net> wrote: >> On Thu, 14 Aug 2008 09:53:39 +0200 Francis Moreau wrote: >> >>> Could anybody give me some advices ? >> >> Put "#!/bin/sh" or "# -*- mode: sh; -*-" in the first line of the file. >> > > As I previously replied I can't. Please see my answer to Henrik. > > But IMHO that's an ugly workaround anyways ?? starting a shell script without any headers is not very nice i think! -- A + Thierry Volpiatto Location: Saint-Cyr-Sur-Mer - France ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 9:23 ` Thierry Volpiatto @ 2008-08-14 9:34 ` Francis Moreau 0 siblings, 0 replies; 28+ messages in thread From: Francis Moreau @ 2008-08-14 9:34 UTC (permalink / raw) To: Thierry Volpiatto; +Cc: help-gnu-emacs On Thu, Aug 14, 2008 at 11:23 AM, Thierry Volpiatto <thierry.volpiatto@gmail.com> wrote: > "Francis Moreau" <francis.moro@gmail.com> writes: > >> On Thu, Aug 14, 2008 at 10:26 AM, David Hansen <david.hansen@gmx.net> wrote: >>> On Thu, 14 Aug 2008 09:53:39 +0200 Francis Moreau wrote: >>> >>>> Could anybody give me some advices ? >>> >>> Put "#!/bin/sh" or "# -*- mode: sh; -*-" in the first line of the file. >>> >> >> As I previously replied I can't. Please see my answer to Henrik. >> >> But IMHO that's an ugly workaround anyways > > ?? starting a shell script without any headers is not very nice i think! Please have a look in my previous reply to see how is it going to be used... -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 9:04 ` Francis Moreau 2008-08-14 9:23 ` Thierry Volpiatto @ 2008-08-14 10:58 ` Peter Dyballa 2008-08-14 11:02 ` Francis Moreau 1 sibling, 1 reply; 28+ messages in thread From: Peter Dyballa @ 2008-08-14 10:58 UTC (permalink / raw) To: Francis Moreau; +Cc: help-gnu-emacs Am 14.08.2008 um 11:04 schrieb Francis Moreau: >> Put "#!/bin/sh" or "# -*- mode: sh; -*-" in the first line of the >> file. >> > > As I previously replied I can't. You could set up auto-mode-alist to use a particular mode (Shell- script mode) for a particular type of file name ... -- Greetings Pete People say that if you play Microsoft CD's backwards, you hear satanic things, but that's nothing, because if you play them forwards, they install MS Windows. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 10:58 ` Peter Dyballa @ 2008-08-14 11:02 ` Francis Moreau 2008-08-14 11:20 ` Lennart Borgman (gmail) 2008-08-14 12:06 ` Peter Dyballa 0 siblings, 2 replies; 28+ messages in thread From: Francis Moreau @ 2008-08-14 11:02 UTC (permalink / raw) To: Peter Dyballa; +Cc: help-gnu-emacs On Thu, Aug 14, 2008 at 12:58 PM, Peter Dyballa <Peter_Dyballa@web.de> wrote: > > Am 14.08.2008 um 11:04 schrieb Francis Moreau: > >>> Put "#!/bin/sh" or "# -*- mode: sh; -*-" in the first line of the file. >>> >> >> As I previously replied I can't. > > > You could set up auto-mode-alist to use a particular mode (Shell-script > mode) for a particular type of file name ... > yes that would be possible, but I fail to understand why I can't start emacs in a specific mode from the command line. IOW why can't I simply do ? $ emacs -f sh-mode FOO thanks -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 11:02 ` Francis Moreau @ 2008-08-14 11:20 ` Lennart Borgman (gmail) 2008-08-14 11:36 ` Francis Moreau 2008-08-14 12:06 ` Peter Dyballa 1 sibling, 1 reply; 28+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-14 11:20 UTC (permalink / raw) To: Francis Moreau; +Cc: help-gnu-emacs Francis Moreau wrote: > yes that would be possible, but I fail to understand why I can't start > emacs in a specific > mode from the command line. > > IOW why can't I simply do ? > > $ emacs -f sh-mode FOO Because you are doing it in the wrong order. sh-mode will apply to the current buffer. Try $emacs FOO -f sh-mode But ... - do you really want to do this? It means you are using a new eamcs instance for every file. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 11:20 ` Lennart Borgman (gmail) @ 2008-08-14 11:36 ` Francis Moreau 2008-08-14 11:46 ` Lennart Borgman (gmail) 0 siblings, 1 reply; 28+ messages in thread From: Francis Moreau @ 2008-08-14 11:36 UTC (permalink / raw) To: Lennart Borgman (gmail); +Cc: help-gnu-emacs On Thu, Aug 14, 2008 at 1:20 PM, Lennart Borgman (gmail) <lennart.borgman@gmail.com> wrote: > Francis Moreau wrote: >> >> yes that would be possible, but I fail to understand why I can't start >> emacs in a specific >> mode from the command line. >> >> IOW why can't I simply do ? >> >> $ emacs -f sh-mode FOO > > Because you are doing it in the wrong order. sh-mode will apply to the > current buffer. Try > > $emacs FOO -f sh-mode > > But ... - do you really want to do this? It means you are using a new eamcs > instance for every file. > So you mean that I need to this: $ cat > emacs-ui-is-dumb.sh<<EOF #! /bin/sh file=$1; shift emacs "$@" $file EOF and do: $ export FCEDIT="emacs-ui-is-dumb.sh" -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 11:36 ` Francis Moreau @ 2008-08-14 11:46 ` Lennart Borgman (gmail) 0 siblings, 0 replies; 28+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-14 11:46 UTC (permalink / raw) To: Francis Moreau; +Cc: help-gnu-emacs Francis Moreau wrote: > On Thu, Aug 14, 2008 at 1:20 PM, Lennart Borgman (gmail) > <lennart.borgman@gmail.com> wrote: >> Francis Moreau wrote: >>> yes that would be possible, but I fail to understand why I can't start >>> emacs in a specific >>> mode from the command line. >>> >>> IOW why can't I simply do ? >>> >>> $ emacs -f sh-mode FOO >> Because you are doing it in the wrong order. sh-mode will apply to the >> current buffer. Try >> >> $emacs FOO -f sh-mode >> >> But ... - do you really want to do this? It means you are using a new eamcs >> instance for every file. >> > > So you mean that I need to this: > > $ cat > emacs-ui-is-dumb.sh<<EOF > #! /bin/sh > > file=$1; shift > emacs "$@" $file > EOF > > and do: > > $ export FCEDIT="emacs-ui-is-dumb.sh" I do not think I mean that, but maybe if you try to explain your intention ... ;-) ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 11:02 ` Francis Moreau 2008-08-14 11:20 ` Lennart Borgman (gmail) @ 2008-08-14 12:06 ` Peter Dyballa 2008-08-14 12:22 ` Francis Moreau 1 sibling, 1 reply; 28+ messages in thread From: Peter Dyballa @ 2008-08-14 12:06 UTC (permalink / raw) To: Francis Moreau; +Cc: help-gnu-emacs Am 14.08.2008 um 13:02 schrieb Francis Moreau: > IOW why can't I simply do ? > > $ emacs -f sh-mode FOO Could be it needs to be: emacs -f '(sh-mode)' FOO See also the documentation on the function sh-mode. -- Greetings Pete ’Twas a woman who drove me to drink, and I never had the courtesy to thank her for it. — W.C. Fields ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 12:06 ` Peter Dyballa @ 2008-08-14 12:22 ` Francis Moreau 0 siblings, 0 replies; 28+ messages in thread From: Francis Moreau @ 2008-08-14 12:22 UTC (permalink / raw) To: Peter Dyballa; +Cc: help-gnu-emacs On Thu, Aug 14, 2008 at 2:06 PM, Peter Dyballa <Peter_Dyballa@web.de> wrote: > > Am 14.08.2008 um 13:02 schrieb Francis Moreau: > >> IOW why can't I simply do ? >> >> $ emacs -f sh-mode FOO > > > Could be it needs to be: > > emacs -f '(sh-mode)' FOO > > See also the documentation on the function sh-mode. > thanks for the tip. -- Francis ^ permalink raw reply [flat|nested] 28+ messages in thread
[parent not found: <mailman.16658.1218700648.18990.help-gnu-emacs@gnu.org>]
* Re: How to open a file in sh-mode [not found] <mailman.16658.1218700648.18990.help-gnu-emacs@gnu.org> @ 2008-08-14 8:28 ` Sebastian Kaps 2008-08-14 10:29 ` Xah 1 sibling, 0 replies; 28+ messages in thread From: Sebastian Kaps @ 2008-08-14 8:28 UTC (permalink / raw) To: help-gnu-emacs // Francis Moreau writes: > I'm trying to open a file with emacs automatically set on sh-mode. > The file name can't be used to guess that emacs should be in sh-mode > when opening it. Put ,---- | # -*- mode:sh -*- `---- at the beginning of that file. -- Ciao, Sebastian ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode [not found] <mailman.16658.1218700648.18990.help-gnu-emacs@gnu.org> 2008-08-14 8:28 ` Sebastian Kaps @ 2008-08-14 10:29 ` Xah 2008-09-11 1:35 ` David Combs 1 sibling, 1 reply; 28+ messages in thread From: Xah @ 2008-08-14 10:29 UTC (permalink / raw) To: help-gnu-emacs On Aug 14, 12:53 am, "Francis Moreau" <francis.m...@gmail.com> wrote: > Hello, > > I'm trying to open a file with emacs automatically set on sh-mode. > The file name can't be used to guess that emacs should be in sh-mode > when opening it. If the file content's first line starts with “#!”, then you could use the magic-mode-alist. ----------------------------------- How Emacs Choose Modes Emacs determines what mode to use primarily by 2 mechanisms, in order: (1) Check the first line in the file, using “magic-mode-alist”. (2) Check the file name's suffix, using “auto-mode-alist”. The “magic-mode-alist” is a list that emacs use to match the first line of a file with a mode. For example, if you want files that begin with the line “<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...” to always use nxml-mode, then add the following to your “.emacs”: (add-to-list 'magic-mode-alist '("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0" . nxml-mode)) The magic-mode-alist is a list. In the above example, the string with the “DOCTYPE” is a regex, used to match the first line of a file. If emacs goes thru magic-mode-alist and didn't find any match, then it'll use auto-mode-alist to check on file name suffix. The “auto-mode- alist” associates a file name suffix with a mode. For example, if you want files ending in “.js” to always open with js2-mode, then do: (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) Note: The double backslash in the string “\\.js\\'” is used to escape the backslash. So, the regex engine just got “\.js\'”. The “\.” is to match a period. The “\'” is one of emacs special regex syntax, to match end of a string. (See also: Text Pattern Matching in Emacs) Reference: Elisp Manual: Regexp-Backslash. You can see what are the values of magic-mode-alist or auto-mode-alist by typing “Alt+x describe-variable”. There are few minor details about how emacs determines what mode to load, but the above should cover vast majority of needs. For detail, see emacs manual. Reference: (info "(emacs)Choosing Modes"). -------------------------------------------- above from: http://xahlee.org/emacs/emacs_installing_packages.html Xah ∑ http://xahlee.org/ ☄ ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: How to open a file in sh-mode 2008-08-14 10:29 ` Xah @ 2008-09-11 1:35 ` David Combs 0 siblings, 0 replies; 28+ messages in thread From: David Combs @ 2008-09-11 1:35 UTC (permalink / raw) To: help-gnu-emacs [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 2848 bytes --] In article <64d8ebaf-0c89-4e9d-9aee-86b4e9414449@o40g2000prn.googlegroups.com>, Xah <xahlee@gmail.com> wrote: >On Aug 14, 12:53 am, "Francis Moreau" <francis.m...@gmail.com> wrote: >> Hello, >> >> I'm trying to open a file with emacs automatically set on sh-mode. >> The file name can't be used to guess that emacs should be in sh-mode >> when opening it. > >If the file content's first line starts with “#!”, then you could use >the magic-mode-alist. > Xah -- question about the characters in your posts: If I or someone sees eg a url in one of your posts, and wants to go to that url (because you've suggested doing that, maybe), it's a little difficult to just cut-n-paste your string, what with all the extra control or whatever they are characters mixed in. What is that stuff, why is it there, and is it really necessary for you to include it. Thanks, David >----------------------------------- >How Emacs Choose Modes > >Emacs determines what mode to use primarily by 2 mechanisms, in order: >(1) Check the first line in the file, using “magic-mode-alist”. (2) >Check the file name's suffix, using “auto-mode-alist”. > >The “magic-mode-alist” is a list that emacs use to match the first >line of a file with a mode. For example, if you want files that begin >with the line “<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...” to >always use nxml-mode, then add the following to your “.emacs”: > >(add-to-list > 'magic-mode-alist > '("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0" . nxml-mode)) > >The magic-mode-alist is a list. In the above example, the string with >the “DOCTYPE” is a regex, used to match the first line of a file. > >If emacs goes thru magic-mode-alist and didn't find any match, then >it'll use auto-mode-alist to check on file name suffix. The “auto-mode- >alist” associates a file name suffix with a mode. For example, if you >want files ending in “.js” to always open with js2-mode, then do: > >(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) > >Note: The double backslash in the string “\\.js\\'” is used to escape >the backslash. So, the regex engine just got “\.js\'”. The “\.” is to >match a period. The “\'” is one of emacs special regex syntax, to >match end of a string. (See also: Text Pattern Matching in Emacs) > >Reference: Elisp Manual: Regexp-Backslash. > >You can see what are the values of magic-mode-alist or auto-mode-alist >by typing “Alt+x describe-variable”. > >There are few minor details about how emacs determines what mode to >load, but the above should cover vast majority of needs. For detail, >see emacs manual. > >Reference: (info "(emacs)Choosing Modes"). > >-------------------------------------------- >above from: >http://xahlee.org/emacs/emacs_installing_packages.html > > Xah >∑ http://xahlee.org/ > >☄ ^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2008-09-11 1:35 UTC | newest] Thread overview: 28+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-08-14 7:53 How to open a file in sh-mode Francis Moreau 2008-08-14 8:16 ` Henrik Austad 2008-08-14 9:03 ` Francis Moreau 2008-08-14 10:03 ` Henrik Austad 2008-08-14 10:06 ` Francis Moreau 2008-08-14 11:17 ` David Hansen 2008-08-14 11:36 ` Henrik Austad 2008-08-14 11:51 ` Francis Moreau 2008-08-14 11:57 ` Lennart Borgman (gmail) [not found] ` <mailman.16667.1218708430.18990.help-gnu-emacs@gnu.org> 2008-08-14 12:24 ` Giorgos Keramidas 2008-08-14 13:01 ` Francis Moreau 2008-08-14 13:27 ` Giorgos Keramidas 2008-08-14 13:48 ` Francis Moreau 2008-08-14 14:23 ` Giorgos Keramidas 2008-08-14 8:26 ` David Hansen 2008-08-14 9:04 ` Francis Moreau 2008-08-14 9:23 ` Thierry Volpiatto 2008-08-14 9:34 ` Francis Moreau 2008-08-14 10:58 ` Peter Dyballa 2008-08-14 11:02 ` Francis Moreau 2008-08-14 11:20 ` Lennart Borgman (gmail) 2008-08-14 11:36 ` Francis Moreau 2008-08-14 11:46 ` Lennart Borgman (gmail) 2008-08-14 12:06 ` Peter Dyballa 2008-08-14 12:22 ` Francis Moreau [not found] <mailman.16658.1218700648.18990.help-gnu-emacs@gnu.org> 2008-08-14 8:28 ` Sebastian Kaps 2008-08-14 10:29 ` Xah 2008-09-11 1:35 ` David Combs
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.