Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
emacs slime livescript
(defun livescript-compile-region-emacs ()
(interactive)
(save-excursion
(setq livescript-args-compile '("-c" "--no-header" "--bare"))
(if (equal mark-active nil) (mark-whole-buffer))
(livescript-compile-region (point) (mark))
(deactivate-mark)
(setq livescript-args-compile '("-c" "--no-header" "-m" "embedded")))
)
; slime
(defun slime-send-livescript (arg)
(interactive "P")
(save-current-buffer
(save-excursion
(save-current-buffer
(let ((inhibit-read-only t))
(set-buffer "*slime-repl JS*")
(erase-buffer))
)
(let ((dir (file-name-directory buffer-file-name)))
(livescript-compile-region-emacs)
(set-buffer livescript-compiled-buffer-name)
; (goto-char (point-min))
; (while (re-search-forward "./" nil t)
; (replace-match (format "%s" dir)))
(goto-char (point-min))
(while (re-search-forward " require(" nil t)
(replace-match " importCwd("))
(goto-char (point-min))
(insert (format "process.chdir('%s')\nrequire('livescript')\nvar importCwd = require('import-cwd')\nvar clearRequire = require('clear-require')\n" dir))
)
(slime-send-js)
(kill-buffer livescript-compiled-buffer-name)
(set-buffer "*slime-repl JS*")
)
)
)
(add-hook 'livescript-mode-hook
(lambda () (progn
(local-set-key (kbd "C-q C-e") 'slime-send-livescript))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment