forked from kmroz/rmoo
-
Notifications
You must be signed in to change notification settings - Fork 5
/
rmoo-local-edit.el
60 lines (54 loc) · 1.85 KB
/
rmoo-local-edit.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
;; rmoo-local-edit.el
;;
;; Some code to interact with Lambdastyle local editing.
;;
;; Original Author: Ron Tapia <[email protected]>
;; Revised by: mattcamp
(require 'rmoo)
(require 'rmoo-mcp)
(provide 'rmoo-local-edit)
(defvar rmoo-local-edit-regexp (concat "^#\\$# "
"edit"
" name: "
"\\(.*\\)"
" upload: "
"\\(.*\\)$"))
(add-hook 'rmoo-handle-text-redirect-functions 'rmoo-local-edit-redirect-function)
(defun rmoo-local-edit-redirect-function (line)
(cond ((eq (string-match rmoo-local-edit-regexp line) 0)
(let ((buf (get-buffer-create (generate-new-buffer-name
(substring line
(match-beginning 1)
(match-end 1)))))
(world rmoo-world-here))
(set-buffer buf)
(setq rmoo-world-here world)
(put world 'last-output-function (get world 'output-function))
(put world 'output-function 'rmoo-local-edit-output-function)
(put world 'last-output-buffer (get world 'output-buffer))
(put world 'output-buffer (current-buffer))
(insert (substring line (match-beginning 2) (match-end 2)))
(insert "\n"))
'rmoo-mcp-nil-function)
(t
nil)))
(defun rmoo-local-edit-output-function (line)
(cond ((eq (string-match "^\\.$" line) 0)
(set-buffer (get rmoo-world-here 'output-buffer))
(insert ".\n")
(funcall 'rmoo-local-edit-cleanup-function)
(rmoo-output-function-return-control-to-last)
(rmoo-set-output-buffer-to-last)
'rmoo-mcp-nil-function)
(t
(set-buffer (get rmoo-world-here 'output-buffer))
(insert (concat line "\n")))))
(defun rmoo-local-edit-cleanup-function ()
(let ((world rmoo-world-here))
(if (get world 'coldc)
(coldc-mode)
(moocode-mode))
(setq rmoo-world-here world)
(goto-char (point-min))
(put rmoo-world-here 'goto-function 'switch-to-buffer-other-window)
(put rmoo-world-here 'goto-buffer (current-buffer))))