Skip to content

Commit

Permalink
added timelines.el
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisKyriakoudis committed Mar 16, 2018
1 parent 77ff271 commit 82ebba4
Showing 1 changed file with 154 additions and 0 deletions.
154 changes: 154 additions & 0 deletions timelines.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
(require 'scheme)
(require 'comint)
(require 'thingatpt)
(require 'find-lisp)
(require 'pulse)
(require 'haskell-mode)

(defvar timelines-buffer
"*timelines*"
"*The name of the TimeLines process buffer (default=*timelines*).")

(defvar timelines-interpreter
"ghci"
"*The haskell interpeter to use (default=ghci).")


(defun timelines-start ()
"Start TimeLines."
(interactive)
(if (comint-check-proc timelines-buffer)
(error "A TimeLines process is already running")
(apply 'make-comint "timelines" timelines-interpreter nil)
(tidal-see-output))
(timelines-send-string "1 + 1"))


(defun timelines-show-output
"Show haskell output."
(interactive)
(when (comint-check-proc timelines-buffer)
(delete-other-windows)
(split-window-vertically 10)
(with-current-buffer timelines-buffer
(let ((window (display-buffer (current-buffer))))
(goto-char (point-max))
(save-selected-window
(set-window-point window (point-max)))))))


(defun tidal-see-output ()
"Show haskell output."
(interactive)
(when (comint-check-proc timelines-buffer)
(delete-other-windows)
(split-window-vertically)
(with-current-buffer timelines-buffer
(let ((window (display-buffer (current-buffer))))
(goto-char (point-max))
(save-selected-window
(set-window-point window (point-max)))))))

(defun timelines-chunk-string (n s)
"Split a string S 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 (timelines-chunk-string n (substring s n))))))

(defun timelines-send-string (s)
(if (comint-check-proc timelines-buffer)
(let ((cs (timelines-chunk-string 64 (concat s "\n"))))
(mapcar (lambda (c) (comint-send-string timelines-buffer c)) cs))
(error "no TimeLines process ")))


(defun timelines-run-line ()
"Send the current line to the interpreter."
(interactive)
(let* ((s (buffer-substring-no-properties
(line-beginning-position)
(line-end-position))))
(timelines-send-string s))
(pulse-momentary-highlight-one-line (point))
;;(forward-line)
)

(defun timelines-send-region ()
"Eval the current region as a single line"
(mark-paragraph)
(let* ((s (buffer-substring-no-properties (region-beginning)
(region-end))))
(timelines-send-string ":{")
(timelines-send-string s)
(timelines-send-string ":}")
(mark-paragraph)
(pulse-momentary-highlight-region (mark) (point)))
)

(defun timelines-eval-region ()
"Send the current region to the interpreter as a single line."
(interactive)
(if (>= emacs-major-version 25)
(save-mark-and-excursion
(timelines-send-region))
(save-excursion
(timelines-send-region))
)
)


(defun timelines-interrupt-haskell ()
(interactive)
(if (comint-check-proc timelines-buffer)
(with-current-buffer timelines-buffer
(interrupt-process (get-buffer-process (current-buffer))))
(error "no process running?")))

(defun timelines-quit-haskell ()
"Quit haskell."
(interactive)
(kill-buffer timelines-buffer)
(delete-other-windows))

(defvar timelines-mode-map nil
"Timelines keymap.")

;;(global-set-key (kbd "C-t") nil)

(defun timelines-mode-keybindings (map)
"Haskell Timelines keybindings."
(define-key map (kbd "C-c C-s") 'timelines-start)
(define-key map (kbd "C-t C-t") 'timelines-show-output)
(define-key map (kbd "C-t C-q") 'timelines-quit-haskell)
(define-key map (kbd "<C-return>") 'timelines-eval-region)
)

(defun timelines-turn-on-keybindings ()
"Haskell Timelines keybindings in the local map."
(local-set-key (kbd "C-t C-s") 'timelines-start)
(local-set-key (kbd "C-t C-t") 'timelines-show-output)
(local-set-key (kbd "C-t C-q") 'timelines-quit-haskell)
(local-set-key (kbd "<C-return>") 'timelines-eval-region)
)

(unless timelines-mode-map
(let ((map (make-sparse-keymap "Haskell-Timelines")))
(timelines-mode-keybindings map)
(setq timelines-mode-map map)))


(define-derived-mode
timelines-mode
haskell-mode
"Haskell Timelines"
"Major mode for interacting with an inferior haskell process."
(set (make-local-variable 'paragraph-start) "\f\\|[ \t]*$")
(set (make-local-variable 'paragraph-separate) "[ \t\f]*$")
(turn-on-font-lock))

(add-to-list 'auto-mode-alist '("\\.tl" . timelines-mode))

(provide 'timelines)

0 comments on commit 82ebba4

Please sign in to comment.