unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Sesquicolon -- Alternative to Shebang
@ 2002-09-08  6:39 John H Swaby
  2002-09-08 11:38 ` Miles Bader
  2002-09-09 23:31 ` Marius Vollmer
  0 siblings, 2 replies; 5+ messages in thread
From: John H Swaby @ 2002-09-08  6:39 UTC (permalink / raw)
  Cc: Pavel, miles, emacs-devel

I see no reason to modify Emacs.  The sesquicolon, :;, does the job,
essentially, of the shebang, #!.  Permit me to elaborate.

The shebang works for many languages because their comment character
is a number sign, #, and they require only two arguments to run a
script.

The sesquicolon works for Emacs because it allows for more than two
arguments and it is compatible with the Lisp comment character, the
semicolon.

In many versions of Unix, if the first two characters of a script are
the shebang, then the program specified after the shebang is run with,
optionally, the one argument that can appear on the shebang line.  The
program is then passed, as its last argument, the script to be
interpreted.

If the first two characters of the file are not the shebang; but the
first character is a number sign, #, then the C Shell, csh, will be
invoked to interpret the script.

If neither of the above, then the Bourne Shell, sh, will be invoked as
the interpreter (keeping in mind that on some systems either the Korn
Shell, ksh, or the Bourne Again Shell, bash, will stand in for the
Bourne Shell).

Emacs requires more than two arguments to run a script; but the
sesquicolon allows for this.  Since the first two characters of the
script are the sesquicolon, :;, the third of the cases described above
is the one that applies and, hence, sh (or ksh or bash, as the case
may be) is invoked as the interpreter.

The colon is a null command in sh, ksh, or bash, and so does nothing.
The semicolon is a command delimiter in all three shells.  And, in all
three shells, the exec command has the same meaning.  Hence,

  :;exec emacs -batch -l $0 -f main $*

will have Emacs interpreting the current script, with the entry
function being "main".  [ For the Korn shell, replace "$0" with "$_".]

When Emacs loads the script the colon evaluates to itself (the colon
is a self-evaluating constant in current versions of Emacs) and the
remainder of the line is ignored as a comment.  [ For older versions
of Emacs, adding the arguments "-eval '(setq : t)'" to the sesquicolon
line will take care of Emacs's evaluation of the colon. ]

The remaining arguments, $*, are accessabile by way of the variable
"command-line-args-left".  Setting this variable to nil or calling the
function kill-emacs at the exit point of the script will prevent Emacs
from loading the remaining arguments as files or directories into
buffers if that is so desired.

So, in my humble opinion, Emacs is already quite fit as an interpreter
of scripts.  For Emacs use the sesquicolon, for other languages use
the shebang.  Emacs marches to a different drummer -- all the better.

Sincerely,  John H. Swaby
            polymath@uwyo.edu

P.S. Another sample script (takes two absolute paths as arguments and
produces two strings.  The second is a repeat of the first argument
and the first is the relative path from the first argument to the
second argument):

:;exec emacs -batch -l $0 -f : $* # -*- Emacs-Lisp -*-
(defun : ()
  (setq args command-line-args-left command-line-args-left ())
  (cond ((null (cdr args))
         (princ (format "Usage: %s absolute_path1 absolute_path2\n"
                        (file-name-nondirectory (nth 2 command-line-args))))
         (kill-emacs 1)))
  (set 'p (pre-link (split-string (nth 0 args) "/")
                    (split-string (nth 1 args) "/")))
  (if p (print-link p) (princ "."))
  (princ (format " %s\n" (car args))))

(defun pre-link (p1 p2)
  (if (and (cdr p1) p2 (equal (car p1) (car p2))) (pre-link (cdr p1) (cdr p2))
    (append (if p1 (dot-dot-list p1) '(())) p2)))

(defun dot-dot-list (ls) (if (cdr ls) (cons ".." (dot-dot-list (cdr ls)))))

(defun print-link (ls)
  (if (car ls) (princ (car ls)))
  (if (or (cdr ls) (null (car ls))) (princ "/"))
  (if (cdr ls) (print-link (cdr ls))))
;;; end of relink

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

* Re: Sesquicolon -- Alternative to Shebang
  2002-09-08  6:39 Sesquicolon -- Alternative to Shebang John H Swaby
@ 2002-09-08 11:38 ` Miles Bader
  2002-09-09 23:31 ` Marius Vollmer
  1 sibling, 0 replies; 5+ messages in thread
From: Miles Bader @ 2002-09-08 11:38 UTC (permalink / raw)
  Cc: rms, Pavel, emacs-devel

On Sun, Sep 08, 2002 at 12:39:48AM -0600, John H Swaby wrote:
> I see no reason to modify Emacs.  The sesquicolon, :;, does the job,
> essentially, of the shebang, #!.  Permit me to elaborate.
...
> If the first two characters of the file are not the shebang; but the
> first character is a number sign, #, then the C Shell, csh, will be
> invoked to interpret the script.
>
> If neither of the above, then the Bourne Shell, sh, will be invoked as
> the interpreter (keeping in mind that on some systems either the Korn
> Shell, ksh, or the Bourne Again Shell, bash, will stand in for the
> Bourne Shell).

My impression is that not all unix-like OSes can be relied upon do all the
above, and that `#!' is more consistently implemented.  Morever, an explicit
`#!' is so widespread that it's going to be much more familiar to users (you
may know all the above arcana, but many people don't).

In any case, `#!' is already implemented, and it's so trivial that there's no
reason to _not_ do it.

-Miles
-- 
P.S.  All information contained in the above letter is false,
      for reasons of military security.

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

* Re: Sesquicolon -- Alternative to Shebang
  2002-09-08  6:39 Sesquicolon -- Alternative to Shebang John H Swaby
  2002-09-08 11:38 ` Miles Bader
@ 2002-09-09 23:31 ` Marius Vollmer
  2002-09-10  4:05   ` John H Swaby
  1 sibling, 1 reply; 5+ messages in thread
From: Marius Vollmer @ 2002-09-09 23:31 UTC (permalink / raw)
  Cc: emacs-devel

John H Swaby <polymath@uwyo.edu> writes:

>   :;exec emacs -batch -l $0 -f main $*
[...]  
> [ For older versions of Emacs, adding the arguments "-eval
> '(setq : t)'" to the sesquicolon line will take care of Emacs's
> evaluation of the colon. ]

You could start the script with

    ":";exec emacs ...

since ":" is the same as : to the shell and is self-evaluating in all
versions of Emacs.  The would be a quosesquicolon, then, right?  Or a
sequoscilon?

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405

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

* Re: Sesquicolon -- Alternative to Shebang
  2002-09-09 23:31 ` Marius Vollmer
@ 2002-09-10  4:05   ` John H Swaby
  2002-09-10 22:08     ` Marius Vollmer
  0 siblings, 1 reply; 5+ messages in thread
From: John H Swaby @ 2002-09-10  4:05 UTC (permalink / raw)
  Cc: emacs-devel

Great Idea!

On Tue, 10 Sep 2002, Marius Vollmer wrote:

> John H Swaby <polymath@uwyo.edu> writes:
> 
> >   :;exec emacs -batch -l $0 -f main $*
> [...]  
> > [ For older versions of Emacs, adding the arguments "-eval
> > '(setq : t)'" to the sesquicolon line will take care of Emacs's
> > evaluation of the colon. ]
> 
> You could start the script with
> 
>     ":";exec emacs ...
> 
> since ":" is the same as : to the shell and is self-evaluating in all
> versions of Emacs.  The would be a quosesquicolon, then, right?  Or a
> sequoscilon?
> 
> -- 
> GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405
> 

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

* Re: Sesquicolon -- Alternative to Shebang
  2002-09-10  4:05   ` John H Swaby
@ 2002-09-10 22:08     ` Marius Vollmer
  0 siblings, 0 replies; 5+ messages in thread
From: Marius Vollmer @ 2002-09-10 22:08 UTC (permalink / raw)
  Cc: emacs-devel

John H Swaby <polymath@uwyo.edu> writes:

> Great Idea!

It's from "Teach Yourself Scheme in Fixnum Days" by Dorai Sitaram.
(At least, that's where I got it from.)

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405

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

end of thread, other threads:[~2002-09-10 22:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-08  6:39 Sesquicolon -- Alternative to Shebang John H Swaby
2002-09-08 11:38 ` Miles Bader
2002-09-09 23:31 ` Marius Vollmer
2002-09-10  4:05   ` John H Swaby
2002-09-10 22:08     ` Marius Vollmer

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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