Skip to content

Commit

Permalink
Removed .juliarc.jl line, now automatically included.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapp committed Mar 2, 2015
1 parent 1690059 commit ea06e61
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
9 changes: 2 additions & 7 deletions README.org
Expand Up @@ -12,16 +12,11 @@ Evaluating code from the source buffer into the REPL will

* Usage

For now, you will need to include the following line in =.juliarc.jl=:

#+BEGIN_SRC julia
include("path-to/ESS-julia-extensions/ess-julia-extensions.jl")
#+END_SRC
and load the Emacs Lisp code, eg
Load the Emacs Lisp code, eg
#+BEGIN_SRC emacs-lisp
(load "path-to/ESS-julia-extensions/ess-julia-extensions.el")
#+END_SRC
with the paths, of course, depending on where you cloned this repo.
with the path, of course, depending on where you cloned this repo.

It will take over the =C-RET=, =C-c C-r=, and =C-c C-c= keybindings in Julia buffers.

Expand Down
21 changes: 21 additions & 0 deletions ess-julia-extensions.el
@@ -1,5 +1,14 @@
(require 'cl-lib)

(eval-and-compile
(defvar ess-julia-extensions-directory
(directory-file-name
(file-name-directory
(if (and (boundp 'load-file-name) load-file-name) ;; A nice default
(file-truename load-file-name)
(error "could not establish directory for ESS-julia-extensions"))))
"Directory of this file. Necessary for loading the ESSx module."))

(defun julia-active-module-path (position)
"Return a list of strings that designates the path of the active module at POSITION. For example, '(\"Foo\" \"Bar\") would be returned when Foo.Bar.
Expand All @@ -24,6 +33,13 @@ For example, '(\"Foo\" \"Bar\") => \"[:Foo :Bar]\""
:key (lambda (m)
(format ":%s" m)))))

(defun julia-ensure-module (process module file)
"Ensures that MODULE is defined in PROCESS, loading FILE if necessary.
NOTE: This is necessary until workspace() in Julia is fixed to
reload the REPL interaction interface."
(ess-send-string process (format "isdefined(:%s) || include(%S)" module file)))

(defun julia-send-region (process start end)
"Send the region between START and END to a Julia process. Evaluated in the current module when applicable, uses the correct line numbers."
(let* ((line (line-number-at-pos start))
Expand All @@ -36,6 +52,11 @@ For example, '(\"Foo\" \"Bar\") => \"[:Foo :Bar]\""
(string (format "ESSx.eval_string(%S, %d, %S%s)"
(buffer-substring-no-properties start end)
line file modpath-string)))
(julia-ensure-module process "ESS"
(format "%sess-julia.jl" ess-etc-directory))
(julia-ensure-module process "ESSx"
(format "%s/ess-julia-extensions.jl"
ess-julia-extensions-directory))
(ess-send-string process string)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
2 changes: 1 addition & 1 deletion ess-julia-extensions.jl
Expand Up @@ -7,7 +7,7 @@ VERSION < v"0.4-" && using Docile
export eval_string, ensure_module

@doc doc"""Evaluate `string` as if it was in `filename`, starting at line number `line`. When a `mod` is supplied, evaluation happens in that module.
""" ->
"""->
function eval_string(string::AbstractString, line::Int, filename::AbstractString,
mod::Module=current_module())
eval(mod, :(include_string("\n"^($line-1)*$string, $filename)))
Expand Down

0 comments on commit ea06e61

Please sign in to comment.