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