home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-18.59-src.tgz / emacs-18.59-src.tar / fsf / emacs18 / lisp / startup.el < prev    next >
Lisp/Scheme  |  1996-09-28  |  9KB  |  243 lines

  1. ;; Process Emacs shell arguments
  2. ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 1, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. ; These are processed only at the beginning of the argument list.
  22. ; -batch        execute noninteractively (messages go to stdout,
  23. ;             variable noninteractive set to t)
  24. ;             This option must be the first in the arglist.
  25. ;             Processed by `main' in emacs.c -- never seen by lisp
  26. ; -t file        Specify to use file rather than stdin/stdout
  27. ;             as the terminal.
  28. ;             This option must be the first in the arglist.
  29. ;             Processed by `main' in emacs.c -- never seen by lisp
  30. ; -nw            Inhibit the use of any window-system-specific display
  31. ;             code; use the current virtual terminal.
  32. ;             This option must be the first in the arglist.
  33. ;             Processed by `main' in emacs.c -- never seen by lisp
  34. ; -q            load no init file
  35. ; -no-init-file        same
  36. ; -u user        load user's init file
  37. ; -user user        same
  38.  
  39. ; These are processed in the order encountered.
  40. ; -f function        execute function
  41. ; -funcall function    same
  42. ; -l file        load file
  43. ; -load file        same
  44. ; -i file        insert file into buffer
  45. ; -insert file        same
  46. ; file            visit file
  47. ; -kill            kill (exit) emacs
  48.  
  49. (setq top-level '(normal-top-level))
  50.  
  51. (defvar command-line-processed nil "t once command line has been processed")
  52.  
  53. (defconst inhibit-startup-message nil
  54.   "*Non-nil inhibits the initial startup messages.
  55. This is for use in your personal init file, once you are familiar
  56. with the contents of the startup message.")
  57.  
  58. (defconst inhibit-default-init nil
  59.   "*Non-nil inhibits loading the `default' library.")
  60.  
  61. (defconst command-switch-alist nil
  62.   "Alist of command-line switches.
  63. Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
  64. HANDLER-FUNCTION receives switch name as sole arg;
  65. remaining command-line args are in the variable `command-line-args-left'.")
  66.  
  67. (defvar term-setup-hook nil
  68.   "Function to be called after loading terminal-specific lisp code.
  69. It is called with no arguments.  You can use this to override the
  70. definitions made by the terminal-specific file.")
  71.  
  72. (defvar window-setup-hook nil)
  73.  
  74. (defconst initial-major-mode 'lisp-interaction-mode
  75.   "Major mode command symbol to use for the initial *scratch* buffer.")
  76.  
  77. (defun normal-top-level ()
  78.   (if command-line-processed
  79.       (message "Back to top level.")
  80.     (setq command-line-processed t)
  81.     ;; In presence of symlinks, switch to cleaner form of default directory.
  82.     (if (and (not (eq system-type 'vax-vms))
  83.          (getenv "PWD")
  84.          (equal (nthcdr 10 (file-attributes default-directory))
  85.             (nthcdr 10 (file-attributes (getenv "PWD")))))
  86.     (setq default-directory (file-name-as-directory (getenv "PWD"))))
  87.     (unwind-protect
  88.     (command-line)
  89.       (and term-setup-hook
  90.        (funcall term-setup-hook))
  91.       (and window-setup-hook
  92.        (funcall window-setup-hook)))))
  93.  
  94. (defun command-line ()
  95.   (let ((args (cdr command-line-args))
  96.     (init (if noninteractive nil (user-login-name)))
  97.     (done nil))
  98.     ;; If user has not done su, use current $HOME to find .emacs.
  99.     (and init (string= init (user-real-login-name))
  100.      (setq init ""))
  101.     (while (and (not done) args)
  102.       (let ((argi (car args)))
  103.     (if (or (string-equal argi "-q")
  104.         (string-equal argi "-no-init-file"))
  105.         (setq init nil
  106.           args (cdr args))
  107.       (if (or (string-equal argi "-u")
  108.           (string-equal argi "-user"))
  109.           (setq args (cdr args)
  110.             init (car args)
  111.             args (cdr args))
  112.         (setq done t)))))
  113.     ;; Load user's init file, or load default one.
  114.     (condition-case error
  115.     (if init
  116.         (progn (load (cond ((eq system-type 'vax-vms) "sys$login:.emacs")
  117.                    ((eq system-type 'amigaos) "s:.emacs")
  118.                    (t (concat "~" init "/.emacs")))
  119.              t t t)
  120.            (or inhibit-default-init
  121.                (let ((inhibit-startup-message nil))
  122.              ;; Users are supposed to be told their rights.
  123.              ;; (Plus how to get help and how to undo.)
  124.              ;; Don't you dare turn this off for anyone
  125.              ;; except yourself.
  126.              (load "default" t t)))))
  127.       (error (message "Error in init file")))
  128.     (if (get-buffer "*scratch*")
  129.     (save-excursion
  130.       (set-buffer "*scratch*")
  131.       (funcall initial-major-mode)))
  132.     ;; On Amiga, initialise clipboard
  133.     (if (eq system-type 'amigaos)
  134.     (let ((clip (safe-amiga-paste)))
  135.       (if clip (kill-add clip))))
  136.     ;; Load library for our terminal type.
  137.     ;; User init file can set term-file-prefix to nil to prevent this.
  138.     (and term-file-prefix (not noninteractive)
  139.      (if window-system
  140.          (load (concat term-file-prefix
  141.                (symbol-name window-system)
  142.                "-win")
  143.            t t)
  144.        (let ((term (getenv "TERM"))
  145.          hyphend)
  146.          (while (and term
  147.              (not (load (concat term-file-prefix term) t t)))
  148.            ;; Strip off last hyphen and what follows, then try again
  149.            (if (setq hyphend (string-match "[-_][^-_]+$" term))
  150.            (setq term (substring term 0 hyphend))
  151.          (setq term nil))))))
  152.     (command-line-1 args)
  153.     (if noninteractive (kill-emacs t))))
  154.  
  155. (defun command-line-1 (command-line-args-left)
  156.   (if (null command-line-args-left)
  157.       (cond ((and (not inhibit-startup-message) (not noninteractive)
  158.           ;; Don't clobber a non-scratch buffer if init file
  159.           ;; has selected it.
  160.           (string= (buffer-name) "*scratch*")
  161.           (not (input-pending-p)))
  162.          ;; If there are no switches to procss, we might as well
  163.          ;; run this hook now, and there may be some need to do it
  164.          ;; before doing any output.
  165.          (and term-setup-hook
  166.           (funcall term-setup-hook))
  167.          ;; Don't let the hook be run twice.
  168.          (setq term-setup-hook nil)
  169.          (and window-setup-hook
  170.           (funcall window-setup-hook))
  171.          (setq window-setup-hook nil)
  172.          (unwind-protect
  173.          (progn
  174.            (insert (emacs-version)
  175.                "
  176. Copyright (C) 1990 Free Software Foundation, Inc.\n")
  177.            ;; If keys have their default meanings,
  178.            ;; use precomputed string to save lots of time.
  179.            (if (and (eq (key-binding "\C-h") 'help-command)
  180.                 (eq (key-binding "\C-xu") 'advertised-undo)
  181.                 (eq (key-binding "\C-h\C-c") 'describe-copying)
  182.                 (eq (key-binding "\C-h\C-d") 'describe-distribution)
  183.                 (eq (key-binding "\C-h\C-w") 'describe-no-warranty)
  184.                 (eq (key-binding "\C-ht") 'help-with-tutorial))
  185.                (insert 
  186.        "Type C-h for help; C-x u to undo changes.  (`C-' means use CTRL key.)
  187.  
  188. GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
  189. You may give out copies of Emacs; type C-h C-c to see the conditions.
  190. Type C-h C-d for information on getting the latest version.
  191. Type C-h t for a tutorial on using Emacs.")
  192.              (insert (substitute-command-keys
  193.        "Type \\[help-command] for help; \\[advertised-undo] to undo changes.  (`C-' means use CTRL key.)
  194.  
  195. GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
  196. You may give out copies of Emacs; type \\[describe-copying] to see the conditions.
  197. Type \\[describe-distribution] for information on getting the latest version.
  198. Type \\[help-with-tutorial] for a tutorial on using Emacs.")))
  199.            (set-buffer-modified-p nil)
  200.            (sit-for 120))
  201.            (save-excursion
  202.          ;; In case the Emacs server has already selected
  203.          ;; another buffer, erase the one our message is in.
  204.          (set-buffer (get-buffer "*scratch*"))
  205.          (erase-buffer)
  206.          (set-buffer-modified-p nil)))))
  207.     (let ((dir default-directory)
  208.       (line 0))
  209.       (while command-line-args-left
  210.     (let ((argi (car command-line-args-left))
  211.           tem)
  212.       (setq command-line-args-left (cdr command-line-args-left))
  213.       (cond ((setq tem (assoc argi command-switch-alist))
  214.          (funcall (cdr tem) argi))
  215.         ((or (string-equal argi "-f")  ;what the manual claims
  216.              (string-equal argi "-funcall")
  217.              (string-equal argi "-e")) ; what the source used to say
  218.          (setq tem (intern (car command-line-args-left)))
  219.          (setq command-line-args-left (cdr command-line-args-left))
  220.          (funcall tem))
  221.         ((or (string-equal argi "-l")
  222.              (string-equal argi "-load"))
  223.          (let ((file (car command-line-args-left)))
  224.            ;; Take file from default dir if it exists there;
  225.            ;; otherwise let `load' search for it.
  226.            (if (file-exists-p (expand-file-name file))
  227.                (setq file (expand-file-name file)))
  228.            (load file nil t))
  229.          (setq command-line-args-left (cdr command-line-args-left)))
  230.         ((or (string-equal argi "-i")
  231.              (string-equal argi "-insert"))
  232.          (insert-file-contents (car command-line-args-left))
  233.          (setq command-line-args-left (cdr command-line-args-left)))
  234.         ((string-equal argi "-kill")
  235.          (kill-emacs t))
  236.         ((string-match "^\\+[0-9]+\\'" argi)
  237.          (setq line (string-to-int argi)))
  238.         (t
  239.          (find-file (expand-file-name argi dir))
  240.          (or (zerop line)
  241.              (goto-line line))
  242.          (setq line 0))))))))
  243.