Debian Codegraph @

init/lisp.in

raw
1 ;;
2 ;; emacs-lisp init code for Modules
3 ;;
4
5 (setenv "MODULESHOME" "@prefix@")
6
7 (defvar Modules-history '() "module cmd history list")
8
9 (defun Modules-module (command)
10 "Run the string COMMAND as a Modules cmd using the tcl version of modules.
11 Any resulting output is placed in buffer \" *modules-cmd*\".
12 This should consist of a single line, a filename, which is
13 expected to contain Emacs lisp code to implement the indicated
14 module commands. The lisp code in this file is eval'd by Emacs
15 on successful completion of modulecmd.tcl.
16
17 Standard error output is placed in buffer \" *module-log*\" which will
18 be displayed if not empty.
19
20 Return value is t on success, nil otherwise."
21 (interactive (list (read-string "Module cmd: " nil 'Modules-history)))
22 (let
23 ((cmd-buffer (get-buffer-create " *modules-cmd*"))
24 (log-buffer (get-buffer-create " *modules-log*"))
25 (log-scratch-file (make-temp-name
26 (expand-file-name "modules-log"
27 (if (fboundp 'temp-directory)
28 (temp-directory) ;; XEmacs
29 temporary-file-directory))))
30 (status nil))
31
32 ;; clear cmd buffer, log buffer is replaced below
33 (set-buffer cmd-buffer)
34 (delete-region (point-min) (point-max))
35
36 (if (condition-case nil
37 ;; call-process on Emacs cannot write stderr to a separate buffer
38 ;; so it must go to a file and then get pulled into the log buffer
39 ;; (XEmacs *can* direct stderr to buffer, but not worth special case)
40 (progn
41 (apply 'call-process "@TCLSH@" nil
42 (list cmd-buffer log-scratch-file)
43 nil ;; don't display stdout
44 "@libexecdir@/modulecmd.tcl"
45 "lisp" (split-string command))
46 t)
47 (error nil))
48 (progn
49 ;; pull any log info from log-scratch-file into log-buffer
50 (set-buffer log-buffer)
51 (insert-file-contents log-scratch-file nil nil nil t)
52
53 ;; display any output written to stderr ( eg: module help|list )
54 (if (> (buffer-size) 0)
55 (switch-to-buffer-other-window log-buffer))
56
57 ;; Run any setenv, etc commands produced by modulecmd.tcl
58 ;; cmd-buffer should currently contain the pathname of file to run
59 ;; Note: use eval-buffer instead of load-file to avoid stomping
60 ;; any (message) output from the script itself.
61 (set-buffer cmd-buffer)
62 (if (> (buffer-size) 0)
63 (progn
64 ;; run it carefully. If an error is thrown, catch it and
65 ;; propagate the fact upwards as a nil, but be sure to still
66 ;; execute cleanup below
67 (setq status
68 (condition-case nil
69 (progn
70 (eval-buffer)
71 t)
72 (error nil)))))))
73
74 ;; all done, clean up
75 (delete-file log-scratch-file)
76
77 status))