Debian Codegraph @

doc/emacs.txt

raw
1 Submitted by [email protected], Nov 18, 2004
2
3
4 How to init emacs lisp modules from .emacs:
5
6 ;; load and init emacs lisp modules if not already loaded...
7 (if (and (getenv "MODULESHOME")
8 (file-directory-p (getenv "MODULESHOME"))
9 (not (fboundp 'module)))
10 (progn
11 (if (load-file (concat (getenv "MODULESHOME") "/init/lisp"))
12 (define-key global-map "\C-cm" 'Modules-module))))
13
14 After this, from within your emacs process you can run any module
15 command, eg:
16
17 C-c m load modules
18 C-c m list
19 etc.
20
21
22 What follows describes an optional usage.
23
24 Since I use env variables frequently within emacs (mostly to
25 specify filename paths) and also use shell-mode, I want to have
26 all modules commands run within both emacs and in my *shell*
27 buffer. The following works for me, but may need tweaking in
28 other environments...
29
30 ;; send a cmd to my shell
31 ;; not very flexible, knows about my setup, shell, etc.
32 ;; cribbed from switch-to-shell.el
33
34 (defvar my-shell-command-shell-buffer-name "*shell*"
35 "The name of the shell buffer.")
36
37 (defun my-shell-command (command)
38 (interactive "sCommand: ")
39 ;; Find shell buffer
40 (and (get-buffer my-shell-command-shell-buffer-name)
41 (pop-to-buffer my-shell-command-shell-buffer-name)
42 (get-buffer-process (current-buffer))
43 (progn
44 (goto-char (point-max))
45 (comint-kill-input) ;; delete any junk on line
46 (insert-string command)
47 (comint-send-input))))
48
49 ;; send the same module cmd to both emacs and my shell buffer
50 (defun m-doit (cmd)
51 (and (Modules-module cmd)
52 (my-shell-command (concat "module " cmd))))
53
54 ;; a sample module command using above
55 (defun m-projects-A ()
56 (interactive)
57 (m-doit "unload projects")
58 (m-doit "load projects/A"))
59 (defun m-projects-B ()
60 (interactive)
61 (m-doit "unload projects")
62 (m-doit "load projects/B"))
63
64 Then use
65
66 M-x m-projects-A <RET>
67
68 to switch to project-A setup.