Evaluate shebang on first saving (close #668)

This commit is contained in:
1024jp 2017-01-19 20:24:32 +09:00
parent 38676e7a8c
commit 21c8a19384
2 changed files with 17 additions and 13 deletions

View File

@ -14,6 +14,7 @@ develop
- Optimize script menu updating performance.
- Change behavior to avoid showing incompatible char list on undoing encoding change.
- Evaluate also the shebang to specify the syntax style on saving the document newly.
- Scale up character view in character inspector.
- Change drawing font for some invisible characters to draw them at a better position.
- Update “JavaScript” syntax style.

View File

@ -418,34 +418,37 @@ final class Document: NSDocument, AdditionalDocumentPreparing, EncodingHolder {
}
guard error == nil else { return }
guard let strongSelf = self else { return }
assert(Thread.isMainThread)
// apply syntax style that is inferred from the file name
// apply syntax style that is inferred from the file name or the shebang
if saveOperation == .saveAsOperation {
let fileName = url.lastPathComponent
if let styleName = SyntaxManager.shared.styleName(documentFileName: fileName) {
self?.setSyntaxStyle(name: styleName)
if let styleName = SyntaxManager.shared.styleName(documentFileName: fileName)
?? SyntaxManager.shared.styleName(documentContent: strongSelf.string)
// -> Due to the async-saving, self.string can be changed from the actual saved contents.
// But we don't care about that.
{
strongSelf.setSyntaxStyle(name: styleName)
}
}
if saveOperation != .autosaveElsewhereOperation {
// update file information
self?.analyzer.invalidateFileInfo()
strongSelf.analyzer.invalidateFileInfo()
// send file update notification for the external editor protocol (ODB Editor Suite)
let odbEventType: ODBEventSender.EventType = (saveOperation == .saveAsOperation) ? .newLocation : .modified
self?.odbEventSender?.sendEvent(type: odbEventType, fileURL: url)
strongSelf.odbEventSender?.sendEvent(type: odbEventType, fileURL: url)
}
if let strongSelf = self {
switch saveOperation {
case .saveOperation,
.saveAsOperation,
.saveToOperation:
ScriptManager.shared.dispatchEvent(documentSaved: strongSelf)
default: break
}
switch saveOperation {
case .saveOperation,
.saveAsOperation,
.saveToOperation:
ScriptManager.shared.dispatchEvent(documentSaved: strongSelf)
default: break
}
}
}