-
Notifications
You must be signed in to change notification settings - Fork 2
/
gofer.el
134 lines (122 loc) · 4.07 KB
/
gofer.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
;;; Gofer mode for GNU Emacs
;;;
;;; Last update: 6/12/91
;;;
;;; Author: Stuart Clayman,
;;; Dept. Computer Science,
;;; University College London
;;;
;;; Email: [email protected]
;;;
;;; Use:
;;; In .emacs put
;;;
;;; (autoload 'gofer-mode "gofer" "Go into gofer mode" t)
;;; (autoload 'run-gofer "gofer" "Run gofer as inferior process" t)
;;; (autoload 'gofer-project "gofer" "Go into a gofer project" t)
;;;
;;; (set-variable 'auto-mode-alist
;;; (append '(
;;; ("\\.gs$" . gofer-mode) ;; gofer source
;;; ("\\.gp$" . gofer-project) ;; gofer project files
;;; ) auto-mode-alist))
;;;
;;; All gofer source files should end in .gs
;;; All gofer project files should end in .gp
;;;
;;; In gofer source files
;;; ESC \C-x
;;; \C-c \C-c
;;; \C-c l loads the current file
;;;
;;; \C-u ESC \C-x
;;; \C-u \C-c \C-c
;;; \C-u \C-c l loads the current file and does a cd first
;;;
;;; \C-c a adds the current file
;;; \C-u \C-c a adds the current file and does a cd first
;;; \C-c r reloads the current file
;;;
;;;
;;; In gofer project files
;;; ESC \C-x
;;; \C-c \C-c
;;; \C-c p loads the project file
;;; \C-u ESC \C-x
;;; \C-u \C-c \C-c
;;; \C-u \C-c p loads the project file and does a cd first
;;;
;;; The duplication of ESC \C-x, \C-c \C-c, and \C-c l is for
;;; historical reasons.
(require 'shell)
(defvar gofer-mode-hook nil "Gofer mode hook")
(defun run-gofer()
"Run an inferior Gofer process."
(interactive)
(switch-to-buffer (make-shell "gofer" "gofer"))
(make-variable-buffer-local 'shell-cd-pattern)
(make-variable-buffer-local 'shell-prompt-pattern)
(setq shell-cd-pattern ":cd")
(setq shell-prompt-pattern "^[? ]*? \\|^"))
(defun save-buffer-and-go-outline(which arg)
"Save current Gofer file buffer.
Goto inferior Gofer buffer and load file.
WHICH operation is required.
With ARG for additional operation"
(save-buffer)
(if (or (null (get-buffer "*gofer*")) (null (process-status "gofer"))) ; if gofer not running
(save-excursion (run-gofer))) ; run gofer
(if (equal which "r") ; reload a file
(progn
(send-string "gofer" (concat ":reload" "\n")))
(if (equal which "l") ; load a file
(progn
(if arg
(send-string "gofer" (concat ":cd " default-directory "\n")))
(send-string "gofer" (concat ":l " (buffer-name) "\n")))
(if (equal which "a") ; add a file
(progn
(if arg
(send-string "gofer" (concat ":cd " default-directory "\n")))
(send-string "gofer" (concat ":a " (buffer-name) "\n")))
(if (equal which "p") ; a project file
(progn
(if arg
(send-string "gofer" (concat ":cd " default-directory "\n")))
(send-string "gofer" (concat ":p " (buffer-name) "\n")))
(message "Bad programming in gofer.el")))))
(switch-to-buffer-other-window "*gofer*"))
(defun save-gofer-buffer-and-load(arg)
"Save a gofer source file and load it"
(interactive "P")
(save-buffer-and-go-outline "l" arg))
(defun save-gofer-buffer-and-add(arg)
"Save a gofer source file and add it to the file list"
(interactive "P")
(save-buffer-and-go-outline "a" arg))
(defun save-gofer-buffer-and-reload(arg)
"Save a gofer source file and reload it"
(interactive "P")
(save-buffer-and-go-outline "r" arg))
(defun save-gofer-project-buffer-and-go(arg)
"Save a gofer project file and run"
(interactive "P")
(save-buffer-and-go-outline "p" arg))
(defun gofer-mode()
"Gofer mode."
(interactive)
(setq mode-name "Gofer")
(make-variable-buffer-local 'indent-line-function)
(setq indent-line-function 'indent-relative)
(run-hooks 'gofer-mode-hook)
(local-set-key "\e\C-x" 'save-gofer-buffer-and-load)
(local-set-key "\C-c\C-c" 'save-gofer-buffer-and-load)
(local-set-key "\C-cl" 'save-gofer-buffer-and-load)
(local-set-key "\C-cr" 'save-gofer-buffer-and-reload)
(local-set-key "\C-ca" 'save-gofer-buffer-and-add)
(local-set-key "\eg" 'goto-line))
(defun gofer-project()
"For Gofer project files"
(local-set-key "\e\C-x" 'save-gofer-project-buffer-and-go)
(local-set-key "\C-c\C-c" 'save-gofer-project-buffer-and-go)
(local-set-key "\C-cp" 'save-gofer-project-buffer-and-go))