Skip to content

Commit

Permalink
Init Cell Eval
Browse files Browse the repository at this point in the history
  • Loading branch information
JobJob committed Nov 26, 2016
1 parent 71c73a4 commit f2bff9b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/misc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports =
paths: require './misc/paths'
history: require './misc/history'
blocks: require './misc/blocks'
cells: require './misc/cells'
words: require './misc/words'

bufferLines: (t, f) ->
Expand Down
39 changes: 39 additions & 0 deletions lib/misc/cells.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
scopes = require './scopes'
{values} = require 'underscore-plus'

module.exports =

getCurrentCell: (ed) ->
buffer = ed.getBuffer()
start = buffer.getFirstPosition()
end = buffer.getEndPosition()
regexString = "#---"

unless regexString?
return [start, end]

regex = new RegExp regexString
cursor = ed.getCursorBufferPosition()

# while cursor.row < end.row #and @isComment cursor
# cursor.row += 1
# cursor.column = 0

if cursor.row > 0
buffer.backwardsScanInRange regex, [start, cursor], ({range}) ->
start = range.start

buffer.scanInRange regex, [cursor, end], ({range}) ->
end = range.start

console.log 'CellManager: Cell [start, end]:', [start, end],
'cursor:', cursor

celltext = ed.getTextInBufferRange([start, end])
res =
range: [values(start), values(end)]
selection: [values(start), values(end)]
line: end.row + 1
text: celltext
console.log 'res', res
[res]
4 changes: 4 additions & 0 deletions lib/package/commands.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ module.exports =
@withInk ->
boot()
juno.runtime.evaluation.eval(move: true)
'julia-client:run-cell': =>
@withInk ->
boot()
juno.runtime.evaluation.eval(cell: true)
'julia-client:run-file': (event) =>
cancelComplete event
@withInk ->
Expand Down
7 changes: 4 additions & 3 deletions lib/runtime/evaluation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ path = require 'path'

{client} = require '../connection'
{notifications, views, selector} = require '../ui'
{paths, blocks, words} = require '../misc'
{paths, blocks, cells, words} = require '../misc'
modules = require './modules'

{eval: evaluate, evalall, cd, clearLazy} = client.import rpc: ['eval', 'evalall'], msg: ['cd', 'clearLazy']
Expand All @@ -16,9 +16,10 @@ module.exports =
edpath = editor.getPath() || 'untitled-' + editor.getBuffer().id
fn {editor, mod, edpath}

eval: ({move}={}) ->
eval: ({move, cell}={}) ->
@withCurrentContext ({editor, mod, edpath}) =>
Promise.all blocks.get(editor).map ({range, line, text, selection}) =>
code_sections = if cell? then cells.getCurrentCell(editor) else blocks.get(editor)
Promise.all code_sections.map ({range, line, text, selection}) =>
blocks.moveNext editor, selection, range if move
[[start], [end]] = range
@ink.highlight editor, start, end
Expand Down

0 comments on commit f2bff9b

Please sign in to comment.