-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathldesigner.el
108 lines (92 loc) · 3.13 KB
/
ldesigner.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
;; This mode is implemented as a derivation of `haskell' mode,
;; indentation and font locking is courtesy that mode. The
;; inter-process communication is courtesy `comint'. The symbol at
;; point acquisition is courtesy `thingatpt'. The directory search
;; facilities are courtesy `find-lisp'.
(require 'comint)
(require 'inf-haskell)
(defvar oscillare-buffer
"*oscillare*"
)
(defun oscillare-start-haskell ()
"Start oscillare"
(interactive)
(call-interactively 'inferior-haskell-start-process)
(oscillare-send-string ":module Oscillare")
(oscillare-send-string "(p, t, base, thread) <- run")
(split-window-below-and-focus)
(switch-to-buffer inferior-haskell-buffer)
)
(defun oscillare-quit-haskell ()
"Quit osicllare."
(interactive)
(switch-to-buffer inferior-haskell-buffer)
(kill-buffer-and-window))
(defun oscillare-restart-haskell()
"Restart oscillare"
(interactive)
(oscillare-quit-haskell)
(oscillare-start-haskell)
)
(defun oscillare-send-string (s)
(if (comint-check-proc inferior-haskell-buffer)
(let ((cs (chunk-string 64 (concat s "\n"))))
(mapcar
(lambda (c) (comint-send-string inferior-haskell-buffer c))
cs))
(error "no oscillare buffer running")))
(defun oscillare-run-line ()
"Send the current line to the haskell buffer"
(interactive)
(let* ((s (buffer-substring (line-beginning-position)
(line-end-position))))
(oscillare-send-string s)))
(defun oscillare-run-multiple-lines ()
"Send the current region to the interpreter as a single line."
(interactive)
(save-excursion
(mark-paragraph)
(let* ((s (buffer-substring-no-properties (region-beginning)
(region-end))))
(oscillare-send-string ":{")
(oscillare-send-string s)
(oscillare-send-string ":}")
(mark-paragraph)
(pulse-momentary-highlight-region (mark) (point))
)))
(defun chunk-string (n s)
"Split a string into chunks of n characters"
(let* ((l (length s))
(m (min l n))
(c (substring s 0 m)))
(if (<= l n)
(list c)
(cons c (chunk-string n (substring s n))))))
(defun oscillare-see-output ()
"Show output buffer"
(interactive)
(when (comint-check-proc inferior-haskell-buffer)
(with-current-buffer inferior-haskell-buffer
(let ((window (display-buffer (current-buffer))))
(goto-char (point-max))
(save-selected-window
(set-window-point window (point-max)))))))
(defun oscillare-mode-keybindings (map)
"Oscillare keybindings"
(define-key map [?\C-c ?\C-s] 'oscillare-see-output)
(define-key map [?\C-c ?\C-c] 'oscillare-run-line)
(define-key map (kbd "<C-return>") 'oscillare-run-multiple-lines))
(defvar oscillare-mode-map nil
"Keymap for oscillare")
(if oscillare-mode-map
()
(let ((map (make-sparse-keymap "Oscillare")))
(oscillare-mode-keybindings map)
(setq oscillare-mode-map map)))
(define-derived-mode
oscillare-mode
haskell-mode
"Oscillare"
"Major mode for interacting with oscillare.")
(add-to-list 'auto-mode-alist '("\\.osc$" . oscillare-mode))
(provide 'oscillare)