-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
le-julia.el
73 lines (59 loc) · 2.18 KB
/
le-julia.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
;;; le-julia.el --- lispy support for Julia. -*- lexical-binding: t -*-
;; Copyright (C) 2016-2019 Oleh Krehel
;; This file is not part of GNU Emacs
;; This file 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, 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.
;; For a full copy of the GNU General Public License
;; see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'julia-mode nil t)
(require 'julia-shell nil t)
(declare-function julia-shell-collect-command-output "ext:julia-shell")
(defun lispy--eval-julia (str)
"Eval STR as Julia code."
(string-trim-right (julia-shell-collect-command-output str)))
;; TODO: simplify
(defun lispy-eval-julia-str (&optional bnd)
(save-excursion
(cond ((region-active-p)
;; get rid of "unexpected indent"
(replace-regexp-in-string
(concat
"^"
(save-excursion
(goto-char (region-beginning))
(buffer-substring-no-properties
(line-beginning-position)
(point))))
"" (lispy--string-dwim)))
((looking-at lispy-outline)
(string-trim-right
(lispy--string-dwim
(lispy--bounds-dwim))))
((lispy-bolp)
(lispy--string-dwim
(lispy--bounds-c-toplevel)))
(t
(cond ((lispy-left-p))
((lispy-right-p)
(backward-list))
(t
(error "Unexpected")))
(setq bnd (lispy--bounds-dwim))
(ignore-errors (backward-sexp))
(while (eq (char-before) ?.)
(backward-sexp))
(setcar bnd (point))
(lispy--string-dwim bnd)))))
(defun lispy-eval-julia ()
(lispy--eval-julia (lispy-eval-julia-str)))
(provide 'le-julia)
;;; le-julia.el ends here