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