all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* --script and --quick
@ 2015-05-26 14:44 Michael Heerdegen
  2015-05-26 16:49 ` Óscar Fuentes
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2015-05-26 14:44 UTC (permalink / raw)
  To: Emacs mailing list

Hello,

when I write an "Emacs script", a file starting with "#!/usr/bin/emacs
--script" or similar, is there any way to force a quick start (as -Q
would do for a regular Emacs invocation) when the script will be
executed?  I mean, apart from using something hackish like

--8<---------------cut here---------------start------------->8---
#!/bin/sh
":"; exec emacs --quick --script "$0" "$@" # -*- mode: emacs-lisp -*-
--8<---------------cut here---------------end--------------->8---

as first file lines instead.


Thanks,

Michael.



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

* Re: --script and --quick
  2015-05-26 14:44 --script and --quick Michael Heerdegen
@ 2015-05-26 16:49 ` Óscar Fuentes
  2015-05-26 17:05   ` Michael Heerdegen
  0 siblings, 1 reply; 15+ messages in thread
From: Óscar Fuentes @ 2015-05-26 16:49 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> when I write an "Emacs script", a file starting with "#!/usr/bin/emacs
> --script" or similar, is there any way to force a quick start (as -Q
> would do for a regular Emacs invocation) when the script will be
> executed?  I mean, apart from using something hackish like
>
> #!/bin/sh
> ":"; exec emacs --quick --script "$0" "$@" # -*- mode: emacs-lisp -*-
>
> as first file lines instead.

Untested:

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




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

* Re: --script and --quick
  2015-05-26 16:49 ` Óscar Fuentes
@ 2015-05-26 17:05   ` Michael Heerdegen
  2015-05-26 20:53     ` Bob Proulx
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2015-05-26 17:05 UTC (permalink / raw)
  To: help-gnu-emacs

Óscar Fuentes <ofv@wanadoo.es> writes:

> Untested:
>
> #!/usr/bin/emacs -Q --script

Thanks, but sadly, this obvious seeming thing doesn't do it.  In that
case, neither -Q nor --script is respected.

I read somewhere that the "#!" thing doesn't allow to specify multiple
arguments.

Michael.




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

* Re: --script and --quick
  2015-05-26 17:05   ` Michael Heerdegen
@ 2015-05-26 20:53     ` Bob Proulx
  2015-05-27  3:48       ` Yuri Khan
  2015-05-28 12:35       ` Michael Heerdegen
  0 siblings, 2 replies; 15+ messages in thread
From: Bob Proulx @ 2015-05-26 20:53 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen wrote:
> Óscar Fuentes writes:
> > Untested:
> > #!/usr/bin/emacs -Q --script
> 
> Thanks, but sadly, this obvious seeming thing doesn't do it.  In that
> case, neither -Q nor --script is respected.
> 
> I read somewhere that the "#!" thing doesn't allow to specify multiple
> arguments.

Correct.  It is an old interface with a lot of history.  It is most
often coded to accept exactly one argument.  Although different
systems have implemented it variously.

Here is the pertinent parts from the GNU/Linux man page documentation
on it.

  $ man 2 execve

       execve() executes the program pointed to by filename.  filename must be
       either a binary executable, or a script starting with  a  line  of  the
       form:

           #! interpreter [optional-arg]

       For details of the latter case, see "Interpreter scripts" below.
  ...
   Interpreter scripts
       An  interpreter  script  is  a  text  file  that has execute permission
       enabled and whose first line is of the form:

           #! interpreter [optional-arg]

       The interpreter must be a valid pathname for an executable which is not
       itself  a  script.   If  the filename argument of execve() specifies an
       interpreter script, then interpreter will be invoked with the following
       arguments:

           interpreter [optional-arg] filename arg...

       where arg...  is the series of words pointed to by the argv argument of
       execve(), starting at argv[1].

       For portable use, optional-arg should either be absent, or be specified
       as  a  single word (i.e., it should not contain white space); see NOTES
       below.
  ...

   Interpreter scripts
       A  maximum  line length of 127 characters is allowed for the first line
       in an interpreter scripts.

       The semantics of the optional-arg argument  of  an  interpreter  script
       vary across implementations.  On Linux, the entire string following the
       interpreter name is passed as a single argument to the interpreter, and
       this string can include white space.  However, behavior differs on some
       other systems.  Some systems use the first  white  space  to  terminate
       optional-arg.  On some systems, an interpreter script can have multiple
       arguments, and white spaces in optional-arg are  used  to  delimit  the
       arguments.

One of the best articles chronicling the details is Sven Mascheck's
site.

  http://www.in-ulm.de/~mascheck/various/shebang/

Bob



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

* Re: --script and --quick
  2015-05-26 20:53     ` Bob Proulx
@ 2015-05-27  3:48       ` Yuri Khan
  2015-05-27  6:55         ` Gian Uberto Lauri
       [not found]         ` <mailman.3742.1432709757.904.help-gnu-emacs@gnu.org>
  2015-05-28 12:35       ` Michael Heerdegen
  1 sibling, 2 replies; 15+ messages in thread
From: Yuri Khan @ 2015-05-27  3:48 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

On Wed, May 27, 2015 at 2:53 AM, Bob Proulx <bob@proulx.com> wrote:
>> > #!/usr/bin/emacs -Q --script
>>
>> Thanks, but sadly, this obvious seeming thing doesn't do it.  In that
>> case, neither -Q nor --script is respected.
>>
>> I read somewhere that the "#!" thing doesn't allow to specify multiple
>> arguments.
>
> Correct.  It is an old interface with a lot of history.  It is most
> often coded to accept exactly one argument.

This begs for an obvious solution: --script should have a
single-letter alias. Single-character options can [usually] be
combined in a single argument:

#!/usr/bin/emacs -Qs



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

* Re: --script and --quick
  2015-05-27  3:48       ` Yuri Khan
@ 2015-05-27  6:55         ` Gian Uberto Lauri
  2015-05-27 11:51           ` Michael Heerdegen
       [not found]         ` <mailman.3742.1432709757.904.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 15+ messages in thread
From: Gian Uberto Lauri @ 2015-05-27  6:55 UTC (permalink / raw)
  To: Yuri Khan; +Cc: help-gnu-emacs@gnu.org

Yuri Khan writes:
 > This begs for an obvious solution: --script should have a
 > single-letter alias. Single-character options can [usually] be
 > combined in a single argument:
 > 
 > #!/usr/bin/emacs -Qs

You are using a shell, the magic of shebang and you are not
considering a shell script?

This one works.

---------------------------------8<----------------------
#!/bin/bash

emacs --quick --script $@
---------------------------------8<----------------------

-- 
 /\           ___                                    Ubuntu: ancient
/___/\_|_|\_|__|___Gian Uberto Lauri_____               African word
  //--\| | \|  |   Integralista GNUslamico            meaning "I can
\/                 coltivatore diretto di software       not install
     già sistemista a tempo (altrui) perso...                Debian"

Warning: gnome-config-daemon considered more dangerous than GOTO



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

* Re: --script and --quick
       [not found]         ` <mailman.3742.1432709757.904.help-gnu-emacs@gnu.org>
@ 2015-05-27  7:18           ` Chris F.A. Johnson
  2015-05-27 12:39             ` Gian Uberto Lauri
  0 siblings, 1 reply; 15+ messages in thread
From: Chris F.A. Johnson @ 2015-05-27  7:18 UTC (permalink / raw)
  To: help-gnu-emacs

On 2015-05-27, Gian Uberto Lauri wrote:
> Yuri Khan writes:
> > This begs for an obvious solution: --script should have a
> > single-letter alias. Single-character options can [usually] be
> > combined in a single argument:
> > 
> > #!/usr/bin/emacs -Qs
>
> You are using a shell, the magic of shebang and you are not
> considering a shell script?
>
> This one works.
>
> ---------------------------------8<----------------------
> #!/bin/bash
>
> emacs --quick --script $@
> ---------------------------------8<----------------------

  That one could fail; it should be:

emacs --quick --script "$@"

-- 
Chris F.A. Johnson


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

* Re: --script and --quick
  2015-05-27  6:55         ` Gian Uberto Lauri
@ 2015-05-27 11:51           ` Michael Heerdegen
  2015-05-27 12:02             ` saint
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2015-05-27 11:51 UTC (permalink / raw)
  To: help-gnu-emacs

"Gian Uberto Lauri" <saint@eng.it> writes:

> ---------------------------------8<----------------------
> #!/bin/bash
>
> emacs --quick --script $@
> ---------------------------------8<----------------------

And put the code into a different file?  That's what I want to avoid,
and this approach would also work without using --script; then I could
just use -l.


Thanks,

Michael.




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

* Re: --script and --quick
  2015-05-27 11:51           ` Michael Heerdegen
@ 2015-05-27 12:02             ` saint
  2015-05-27 12:34               ` Michael Heerdegen
  0 siblings, 1 reply; 15+ messages in thread
From: saint @ 2015-05-27 12:02 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

Michael Heerdegen writes:
 > "Gian Uberto Lauri" <saint@eng.it> writes:
 > 
 > > ---------------------------------8<----------------------
 > > #!/bin/bash
 > >
 > > emacs --quick --script $@
 > > ---------------------------------8<----------------------
 > 
 > And put the code into a different file?

*This* is the interpreter (a wrapper for Emacs). Use it for all your
 scripts.

-------------------------8<--------------------------
#!/home/saint/bin/esh
(find-file "paperoga")
(insert (concat "hello" "world"))
(save-buffer)
-------------------------8<--------------------------

This is a script .

BTW, I often use emacsclient --eval to invoke functions in a running
and is faster, but could block the foreground Emacs for a while.

My favourite strategy is a little shell script that targets the files
and processes them within Emacs.

-- 
 /\           ___                                    Ubuntu: ancient
/___/\_|_|\_|__|___Gian Uberto Lauri_____               African word
  //--\| | \|  |   Integralista GNUslamico            meaning "I can
\/                 coltivatore diretto di software       not install
     già sistemista a tempo (altrui) perso...                Debian"

Warning: gnome-config-daemon considered more dangerous than GOTO



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

* Re: --script and --quick
  2015-05-27 12:02             ` saint
@ 2015-05-27 12:34               ` Michael Heerdegen
  2015-05-27 12:39                 ` Gian Uberto Lauri
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2015-05-27 12:34 UTC (permalink / raw)
  To: help-gnu-emacs

saint@eng.it writes:

> *This* is the interpreter (a wrapper for Emacs). Use it for all your
> scripts.

Ah, I see.  Would this have any advantages compared to a --quick-script
option in Emacs when that existed?

>> -------------------------8<--------------------------
> #!/home/saint/bin/esh
> (find-file "paperoga")
> (insert (concat "hello" "world"))
> (save-buffer)
> -------------------------8<--------------------------
>
> This is a script.

Not bad.  Even lexical binding can be used this way (by adding 

;; -*- lexical-binding: t -*-

as second line), and also the argv variable holds the arguments as
expected.


Thanks,

Michael.




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

* Re: --script and --quick
  2015-05-27 12:34               ` Michael Heerdegen
@ 2015-05-27 12:39                 ` Gian Uberto Lauri
  2015-05-27 12:52                   ` Michael Heerdegen
  0 siblings, 1 reply; 15+ messages in thread
From: Gian Uberto Lauri @ 2015-05-27 12:39 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

Michael Heerdegen writes:
 > saint@eng.it writes:
 > 
 > > *This* is the interpreter (a wrapper for Emacs). Use it for all your
 > > scripts.
 > 
 > Ah, I see.  Would this have any advantages compared to a --quick-script
 > option in Emacs when that existed?

Is available now.

-- 
 /\           ___                                    Ubuntu: ancient
/___/\_|_|\_|__|___Gian Uberto Lauri_____               African word
  //--\| | \|  |   Integralista GNUslamico            meaning "I can
\/                 coltivatore diretto di software       not install
     già sistemista a tempo (altrui) perso...                Debian"

Warning: gnome-config-daemon considered more dangerous than GOTO



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

* Re: --script and --quick
  2015-05-27  7:18           ` Chris F.A. Johnson
@ 2015-05-27 12:39             ` Gian Uberto Lauri
  0 siblings, 0 replies; 15+ messages in thread
From: Gian Uberto Lauri @ 2015-05-27 12:39 UTC (permalink / raw)
  To: newsgroups; +Cc: help-gnu-emacs

Chris F.A. Johnson writes:
 > > ---------------------------------8<----------------------
 > > #!/bin/bash
 > >
 > > emacs --quick --script $@
 > > ---------------------------------8<----------------------
 > 
 >   That one could fail; it should be:
 > 
 > emacs --quick --script "$@"

Right, thank you!

-- 
                                                Gian
                                       Friends will be friends
                                          right to the end!



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

* Re: --script and --quick
  2015-05-27 12:39                 ` Gian Uberto Lauri
@ 2015-05-27 12:52                   ` Michael Heerdegen
  2015-05-28 14:27                     ` Michael Heerdegen
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2015-05-27 12:52 UTC (permalink / raw)
  To: help-gnu-emacs

"Gian Uberto Lauri" <saint@eng.it> writes:

>  > Ah, I see.  Would this have any advantages compared to a
>  > --quick-script option in Emacs when that existed?
>
> Is available now.

;-)




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

* Re: --script and --quick
  2015-05-26 20:53     ` Bob Proulx
  2015-05-27  3:48       ` Yuri Khan
@ 2015-05-28 12:35       ` Michael Heerdegen
  1 sibling, 0 replies; 15+ messages in thread
From: Michael Heerdegen @ 2015-05-28 12:35 UTC (permalink / raw)
  To: help-gnu-emacs

Bob Proulx <bob@proulx.com> writes:

> Correct.  It is an old interface with a lot of history.  It is most
> often coded to accept exactly one argument.  Although different
> systems have implemented it variously.

> [...]

Many thanks Bob for the expositions!


Michael.



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

* Re: --script and --quick
  2015-05-27 12:52                   ` Michael Heerdegen
@ 2015-05-28 14:27                     ` Michael Heerdegen
  0 siblings, 0 replies; 15+ messages in thread
From: Michael Heerdegen @ 2015-05-28 14:27 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> > Is available now.
>
> ;-)

I've made a bug report:

  https://lists.gnu.org/archive/html/bug-gnu-emacs/2015-05/msg00949.html

Thanks to everybody for the discussion.


Regards,

Michael.




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

end of thread, other threads:[~2015-05-28 14:27 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-26 14:44 --script and --quick Michael Heerdegen
2015-05-26 16:49 ` Óscar Fuentes
2015-05-26 17:05   ` Michael Heerdegen
2015-05-26 20:53     ` Bob Proulx
2015-05-27  3:48       ` Yuri Khan
2015-05-27  6:55         ` Gian Uberto Lauri
2015-05-27 11:51           ` Michael Heerdegen
2015-05-27 12:02             ` saint
2015-05-27 12:34               ` Michael Heerdegen
2015-05-27 12:39                 ` Gian Uberto Lauri
2015-05-27 12:52                   ` Michael Heerdegen
2015-05-28 14:27                     ` Michael Heerdegen
     [not found]         ` <mailman.3742.1432709757.904.help-gnu-emacs@gnu.org>
2015-05-27  7:18           ` Chris F.A. Johnson
2015-05-27 12:39             ` Gian Uberto Lauri
2015-05-28 12:35       ` Michael Heerdegen

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.