5

man emacs:

--script file
    Run file as an Emacs Lisp script.
-l file, --load file
    Load the lisp code in the file file.

I think that --load uses usual convention to boot from compiled file version firstly and --script does not. But I am unsure...

gavenkoa
  • 3,352
  • 19
  • 36

2 Answers2

9

See the documentation within emacs for more information.

  • The --script FILE option runs emacs in batch mode (See below to know more about this mode) and executes the code in the FILE.
    • This option implies the -q option.
  • The --load=FILE loads the FILE library using the load function (and tries to find that library in load-path if FILE is not an absolute path).
    • This option does not imply the -q option.
    • It is very common to use the -l FILE option to see how a package/library works by itself without loading the user's emacs config. Example: emacs -Q -l SOME-PACKAGE.el.

From C-h i g (emacs) Initial Options:

‘-batch’
‘--batch’
     Run Emacs in "batch mode".  Batch mode is used for running programs
     written in Emacs Lisp from shell scripts, makefiles, and so on.  To
     invoke a Lisp program, use the ‘-batch’ option in conjunction with
     one or more of ‘-l’, ‘-f’ or ‘--eval’ (*note Action Arguments::).
     *Note Command Example::, for an example.

     In batch mode, Emacs does not display the text being edited, and
     the standard terminal interrupt characters such as ‘C-z’ and ‘C-c’
     have their usual effect.  Emacs functions that normally print a
     message in the echo area will print to either the standard output
     stream (‘stdout’) or the standard error stream (‘stderr’) instead.
     (To be precise, functions like ‘prin1’, ‘princ’ and ‘print’ print
     to ‘stdout’, while ‘message’ and ‘error’ print to ‘stderr’.)
     Functions that normally read keyboard input from the minibuffer
     take their input from the terminal’s standard input stream
     (‘stdin’) instead.

     ‘--batch’ implies ‘-q’ (do not load an initialization file), but
     ‘site-start.el’ is loaded nonetheless.  It also causes Emacs to
     exit after processing all the command options.  In addition, it
     disables auto-saving except in buffers for which auto-saving is
     explicitly requested, and when saving files it omits the ‘fsync’
     system call unless otherwise requested.

‘--script FILE’
     Run Emacs in batch mode, like ‘--batch’, and then read and execute
     the Lisp code in FILE.

     The normal use of this option is in executable script files that
     run Emacs.  They can start with this text on the first line

          #!/usr/bin/emacs --script

     which will invoke Emacs with ‘--script’ and supply the name of the
     script file as FILE.  Emacs Lisp then treats the ‘#!’ on this first
     line as a comment delimiter.

From C-h i g (emacs) Action Arguments:

‘-l FILE’
‘--load=FILE’
     Load a Lisp library named FILE with the function ‘load’.  If FILE
     is not an absolute file name, Emacs first looks for it in the
     current directory, then in the directories listed in ‘load-path’
     (*note Lisp Libraries::).

     *Warning:* If previous command-line arguments have visited files,
     the current directory is the directory of the last file visited.

How I found the above exact Info nodes?

  • Open emacs Info manual (C-h r).
  • Search (s --script or s --load for your examples).
  • The exact node name gets copied when you hit w in an Info node.

Do C-h i h to learn more on using Info from within emacs.

Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
3

--script expands to load, see lisp/startup.el in Emacs sources:

;; This is used to handle -script.  It's not clear
;; we need to document it (it is totally internal).
((member argi '("-scriptload"))
 (let* ((file (command-line-normalize-file-name
               (or argval (pop command-line-args-left))))
        ;; Take file from default dir.
        (file-ex (expand-file-name file)))
   (load file-ex nil t t)))

However, it passes t for NOSUFFIX, and thus does not try to expand the file name by adding .el or .elc automatically, unlike -load which tries to add the suffix. Also unlike -load, --script never looks into load-path: Relative file names are looked up in the current working directory.

In other words, --script loads the literal file name given as argument, whereas -load loads a “library”, by consulting load-path and adding file name suffixes as needed.

The code above says -scriptload, but the main argument processing in src/emacs.c converts --script to -scriptload:

if (argmatch (argv, argc, "-script", "--script", 3, &junk, &skip_args))
  {
    noninteractive = 1; /* Set batch mode.  */
    /* Convert --script to -scriptload, un-skip it, and sort again
       so that it will be handled in proper sequence.  */
    /* FIXME broken for --script=FILE - is that supposed to work?  */
    argv[skip_args - 1] = (char *) "-scriptload";
    skip_args -= 2;
    sort_args (argc, argv);
  }

As you can see that's also where Emacs enables batch mode for --script.

Don't ask me for the reason for this convoluted process of converting --script to -scriptload. As with many Emacs internals I think it's better not to ask and not to know

  • this is led by the problem with sorting, accordingly to the docs: `emacs.c:1704` https://github.com/emacs-mirror/emacs/blob/master/src/emacs.c#L1704-L1708 – test30 Feb 29 '16 at 12:58