aboutsummaryrefslogtreecommitdiff
path: root/Emacs/.config/emacs/elisp/haskell-multiedit.el
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2021-07-26 01:48:56 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2021-07-26 01:49:38 +0100
commitad5cb2b50985da466ea30ae5a5b2eea07ba212b9 (patch)
treedd8651aa8de0342fe56ca13487799dfef26086df /Emacs/.config/emacs/elisp/haskell-multiedit.el
parenta6f1a172de8dcc73944671aa13aaff4c31afd7fe (diff)
downloaddotfiles-ad5cb2b50985da466ea30ae5a5b2eea07ba212b9.tar.gz
dotfiles-ad5cb2b50985da466ea30ae5a5b2eea07ba212b9.tar.bz2
dotfiles-ad5cb2b50985da466ea30ae5a5b2eea07ba212b9.zip
(Emacs)~move elips files into elisp/ folder
These files were cluttering the main directory, I'd rather just have my config files here.
Diffstat (limited to 'Emacs/.config/emacs/elisp/haskell-multiedit.el')
-rw-r--r--Emacs/.config/emacs/elisp/haskell-multiedit.el66
1 files changed, 66 insertions, 0 deletions
diff --git a/Emacs/.config/emacs/elisp/haskell-multiedit.el b/Emacs/.config/emacs/elisp/haskell-multiedit.el
new file mode 100644
index 0000000..700e7de
--- /dev/null
+++ b/Emacs/.config/emacs/elisp/haskell-multiedit.el
@@ -0,0 +1,66 @@
+;;; haskell-multiedit.el --- Minor mode to edit and evaluate multi-line scripts of Haskell without making a file -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Aryadev Chavali
+
+;; Author: Aryadev Chavali <aryadev@aryadevchavali.com>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; To be used in a haskell-interactive-mode buffer. It'll generate a
+;; new buffer with haskell-mode and this minor mode activated. Once
+;; finished with the code, using another keybind it'll close this
+;; buffer and paste the code into haskell-interactive-mode, evaluating
+;; it all line by line with indenting and multi-line guards.
+
+;;; Code:
+
+(defvar haskell-multiedit-mode-map
+ (make-sparse-keymap))
+
+(define-minor-mode haskell-multiedit-mode
+ "Minor mode for haskell buffers generated by haskell-interactive-mode.
+Provides bindings to retrieve content back into the REPL with
+full multi-edit commands"
+ nil
+ ""
+ haskell-multiedit-mode-map)
+
+(with-eval-after-load "haskell"
+ (defun haskell-multiedit ()
+ (interactive)
+ (haskell-interactive-mode-return)
+ (switch-to-buffer "*haskell-temp*")
+ (haskell-mode)
+ (haskell-multiedit-mode))
+
+ (defun haskell-multiedit-evaluate-at-repl ()
+ (interactive)
+ (let* ((contents (buffer-string))
+ (lines (split-string contents "\n")))
+ (switch-to-buffer (haskell-session-interactive-buffer (haskell-session)))
+ (insert ":{")
+ (haskell-interactive-mode-return)
+ (mapc #'(lambda (line) (insert line) (haskell-interactive-mode-return)) lines)
+ (insert ":}")
+ (haskell-interactive-mode-return)))
+
+ (define-key haskell-interactive-mode-map (kbd "C-c '") #'haskell-multiedit)
+ (define-key haskell-multiedit-mode-map (kbd "C-c '") #'haskell-multiedit-evaluate-at-repl)
+ )
+
+(provide 'haskell-multiedit)
+;;; haskell-interactive-multiedit.el ends here