]> code.delx.au - gnu-emacs/blob - lisp/eshell/em-script.el
(normal-splash-screen, fancy-splash-screens-1): Add a reference to the Lisp
[gnu-emacs] / lisp / eshell / em-script.el
1 ;;; em-script.el --- Eshell script files
2
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
5
6 ;; Author: John Wiegley <johnw@gnu.org>
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 (provide 'em-script)
26
27 (eval-when-compile (require 'esh-maint))
28
29 (require 'eshell)
30
31 (defgroup eshell-script nil
32 "This module allows for the execution of files containing Eshell
33 commands, as a script file."
34 :tag "Running script files."
35 :group 'eshell-module)
36
37 ;;; Commentary:
38
39 ;;; User Variables:
40
41 (defcustom eshell-script-load-hook '(eshell-script-initialize)
42 "*A list of functions to call when loading `eshell-script'."
43 :type 'hook
44 :group 'eshell-script)
45
46 (defcustom eshell-login-script (concat eshell-directory-name "login")
47 "*If non-nil, a file to invoke when starting up Eshell interactively.
48 This file should be a file containing Eshell commands, where comment
49 lines begin with '#'."
50 :type 'file
51 :group 'eshell-script)
52
53 (defcustom eshell-rc-script (concat eshell-directory-name "profile")
54 "*If non-nil, a file to invoke whenever Eshell is started.
55 This includes when running `eshell-command'."
56 :type 'file
57 :group 'eshell-script)
58
59 ;;; Functions:
60
61 (defun eshell-script-initialize ()
62 "Initialize the script parsing code."
63 (make-local-variable 'eshell-interpreter-alist)
64 (setq eshell-interpreter-alist
65 (cons '((lambda (file)
66 (string= (file-name-nondirectory file)
67 "eshell")) . eshell/source)
68 eshell-interpreter-alist))
69 (make-local-variable 'eshell-complex-commands)
70 (setq eshell-complex-commands
71 (append '("source" ".") eshell-complex-commands))
72 ;; these two variables are changed through usage, but we don't want
73 ;; to ruin it for other modules
74 (let (eshell-inside-quote-regexp
75 eshell-outside-quote-regexp)
76 (and (not eshell-non-interactive-p)
77 eshell-login-script
78 (file-readable-p eshell-login-script)
79 (eshell-do-eval
80 (list 'eshell-commands
81 (catch 'eshell-replace-command
82 (eshell-source-file eshell-login-script))) t))
83 (and eshell-rc-script
84 (file-readable-p eshell-rc-script)
85 (eshell-do-eval
86 (list 'eshell-commands
87 (catch 'eshell-replace-command
88 (eshell-source-file eshell-rc-script))) t))))
89
90 (defun eshell-source-file (file &optional args subcommand-p)
91 "Execute a series of Eshell commands in FILE, passing ARGS.
92 Comments begin with '#'."
93 (interactive "f")
94 (let ((orig (point))
95 (here (point-max))
96 (inhibit-point-motion-hooks t)
97 after-change-functions)
98 (goto-char (point-max))
99 (insert-file-contents file)
100 (goto-char (point-max))
101 (throw 'eshell-replace-command
102 (prog1
103 (list 'let
104 (list (list 'eshell-command-name (list 'quote file))
105 (list 'eshell-command-arguments
106 (list 'quote args)))
107 (let ((cmd (eshell-parse-command (cons here (point)))))
108 (if subcommand-p
109 (setq cmd (list 'eshell-as-subcommand cmd)))
110 cmd))
111 (delete-region here (point))
112 (goto-char orig)))))
113
114 (defun eshell/source (&rest args)
115 "Source a file in a subshell environment."
116 (eshell-eval-using-options
117 "source" args
118 '((?h "help" nil nil "show this usage screen")
119 :show-usage
120 :usage "FILE [ARGS]
121 Invoke the Eshell commands in FILE in a subshell, binding ARGS to $1,
122 $2, etc.")
123 (eshell-source-file (car args) (cdr args) t)))
124
125 (put 'eshell/source 'eshell-no-numeric-conversions t)
126
127 (defun eshell/. (&rest args)
128 "Source a file in the current environment."
129 (eshell-eval-using-options
130 "." args
131 '((?h "help" nil nil "show this usage screen")
132 :show-usage
133 :usage "FILE [ARGS]
134 Invoke the Eshell commands in FILE within the current shell
135 environment, binding ARGS to $1, $2, etc.")
136 (eshell-source-file (car args) (cdr args))))
137
138 (put 'eshell/. 'eshell-no-numeric-conversions t)
139
140 ;;; Code:
141
142 ;;; arch-tag: a346439d-5ba8-4faf-ac2b-3aacfeaa4647
143 ;;; em-script.el ends here