Skip to content

Commit

Permalink
Now Only executes a working command before the cursor!
Browse files Browse the repository at this point in the history
Huge! This is a big win.
  • Loading branch information
kennethshawfriedman committed May 7, 2017
1 parent d3a5a70 commit 52bb1f1
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 5 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,70 @@
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Schemer/SchemeComm.swift"
timestampString = "515827211.919702"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "47"
endingLineNumber = "47"
landmarkName = "findExecutableCommandInText(incoming:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Schemer/SchemeComm.swift"
timestampString = "515827359.840521"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "48"
endingLineNumber = "48"
landmarkName = "findExecutableCommandInText(incoming:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Schemer/SchemeComm.swift"
timestampString = "515827359.840521"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "52"
endingLineNumber = "52"
landmarkName = "findExecutableCommandInText(incoming:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Schemer/SchemeComm.swift"
timestampString = "515827355.332696"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "53"
endingLineNumber = "53"
landmarkName = "findExecutableCommandInText(incoming:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
47 changes: 43 additions & 4 deletions Schemer-MacOS/Schemer/SchemeComm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ class SchemeComm {

static func parseExecutionCommand(codingField cf:CodeField) -> Data {

let nothingHereMessage = "(pp \"nothing here\")"
//string to append code to
var result:String = ""
//error message: used if it can't find text in the codeField
let nothingHereMessage = "(pp \"Something Has Gone Wrong, the text can't be found.\")"
//get string from codeField
let currentText:String = cf.textStorage?.string ?? nothingHereMessage
//get curosor location:
let cursorLoc = SchemeComm.locationOfCursor(codingField: cf)
//grab all text before cursor location:
let codeBeforeCursor = currentText.substring(to: currentText.index(currentText.startIndex, offsetBy: cursorLoc))
//find an executable command within the possible code before the cursor
let executableCommand = SchemeComm.findExecutableCommandInText(incoming: codeBeforeCursor)

var result = ""
//Figure stuff out here
result.append(currentText)
result.append(executableCommand)
//return as Data object to send to Scheme Process
return result.data(using: .utf8)!
}

Expand All @@ -32,6 +41,36 @@ class SchemeComm {
return insertSpot
}

static func findExecutableCommandInText(incoming:String) -> String {
var chars = Array(incoming.characters)
chars.reverse()
var parenCount = 0 //keep track of parenthesis!
var indextoRevertBackTo = 0
print(chars)
for i in 0..<chars.count {
print("CURRENTLY CHECKING:\(chars[i])")
if (chars[i] == Character(")")) {
parenCount += 1
} else if (chars[i] == Character("(")) {
parenCount -= 1
}
if (parenCount == 0) {
indextoRevertBackTo = i+1
let beginSpot = incoming.index(incoming.endIndex, offsetBy: -indextoRevertBackTo)
let substringToReturn = incoming.substring(from: beginSpot)
print("THIS IS THE RESULT: \(substringToReturn) END")
return substringToReturn
} else if (parenCount < 0) {
print("Major Error: there is no command that will work!")
return ""
}
}
print("ERROR WITH: \(incoming)")
print("something happened in findexecutablecommandintext function!")
return ""
}


}

//This is class is just extra, rarely-called functions to help SchemeComm (SchemeComm should be handling most of the logic)
Expand Down
1 change: 0 additions & 1 deletion Schemer-MacOS/Schemer/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ViewController: NSViewController {

override func viewDidLoad() {
super.viewDidLoad()


cf.font = CodeField.standardFont()
cf.isContinuousSpellCheckingEnabled = false
Expand Down

0 comments on commit 52bb1f1

Please sign in to comment.