Commit 1579064da0
Verified · cmc
Layout: unified · split
Sources/OrgCore/Compute/Babel.swift +3 −3
| @@ -294,7 +294,7 @@ public enum Babel { | |||
| 294 | let needsFile = options.file == nil && params.lisp.contains { params.evaluated[$0] == nil } | 294 | let needsFile = options.file == nil && params.lisp.contains { params.evaluated[$0] == nil } |
| 295 | guard let language = block.language else { return .failure(.message("This block has no language")) } | 295 | guard let language = block.language else { return .failure(.message("This block has no language")) } |
| 296 | let eval = params.single[":eval"]?.lowercased() | 296 | let eval = params.single[":eval"]?.lowercased() |
| 297 | if eval == "never" || eval == "no" || eval == "never-export" || eval == "no-export" { | 297 | if eval == "never" || eval == "no" { |
| 298 | return .failure(.message("Evaluation of this \(language) code block\(block.name.map { " (\($0)) " } ?? " ")is disabled.")) | 298 | return .failure(.message("Evaluation of this \(language) code block\(block.name.map { " (\($0)) " } ?? " ")is disabled.")) |
| 299 | } | 299 | } |
| 300 | if params.single[":cmdline"] != nil, !["dot", "plantuml", "mermaid"].contains(language), !shells.contains(language) { | 300 | if params.single[":cmdline"] != nil, !["dot", "plantuml", "mermaid"].contains(language), !shells.contains(language) { |
| @@ -1903,14 +1903,14 @@ public struct ExecuteSrcBlock: OrgCommand { | |||
| 1903 | public var title: String { "Run Source Block" } | 1903 | public var title: String { "Run Source Block" } |
| 1904 | public func applies(in context: EditContext) -> Bool { KeyContext.holds("src", in: context) || Self.atCallOrInline(context) } | 1904 | public func applies(in context: EditContext) -> Bool { KeyContext.holds("src", in: context) || Self.atCallOrInline(context) } |
| 1905 | 1905 | ||
| 1906 | /// On a `#+CALL:` line or an inline `src_` block. | 1906 | /// On a `#+CALL:` line, an inline `call_` or an inline `src_` block. |
| 1907 | static func atCallOrInline(_ context: EditContext) -> Bool { | 1907 | static func atCallOrInline(_ context: EditContext) -> Bool { |
| 1908 | let ns = context.text as NSString | 1908 | let ns = context.text as NSString |
| 1909 | let line = ns.substring(with: ns.lineRange(for: NSRange(location: min(context.caret, ns.length), length: 0))) | 1909 | let line = ns.substring(with: ns.lineRange(for: NSRange(location: min(context.caret, ns.length), length: 0))) |
| 1910 | if line.range(of: "(?i)^[ \\t]*#\\+CALL:", options: .regularExpression) != nil { return true } | 1910 | if line.range(of: "(?i)^[ \\t]*#\\+CALL:", options: .regularExpression) != nil { return true } |
| 1911 | var node = context.tree.root | 1911 | var node = context.tree.root |
| 1912 | while let child = node.child(containing: context.caret) { | 1912 | while let child = node.child(containing: context.caret) { |
| 1913 | if child.kind == .inlineSourceBlock { return true } | 1913 | if child.kind == .inlineSourceBlock || child.kind == .inlineBabelCall { return true } |
| 1914 | node = child | 1914 | node = child |
| 1915 | } | 1915 | } |
| 1916 | return false | 1916 | return false |
Tests/OrgCoreTests/BabelTests.swift +25
| @@ -328,6 +328,17 @@ struct BabelTests { | |||
| 328 | #expect(got == message) | 328 | #expect(got == message) |
| 329 | } | 329 | } |
| 330 | } | 330 | } |
| 331 | |||
| 332 | @Test func noExportStillRunsInteractively() { | ||
| 333 | for eval in ["never-export", "no-export"] { | ||
| 334 | let text = "#+begin_src sh :eval \(eval)\necho 1\n#+end_src\n" | ||
| 335 | let context = EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [2..<2]) | ||
| 336 | guard case .success = Babel.plan(context) else { | ||
| 337 | Issue.record("refused :eval \(eval)") | ||
| 338 | continue | ||
| 339 | } | ||
| 340 | } | ||
| 341 | } | ||
| 331 | } | 342 | } |
| 332 | 343 | ||
| 333 | struct BabelCallTests { | 344 | struct BabelCallTests { |
| @@ -378,6 +389,20 @@ struct BabelCallTests { | |||
| 378 | } | 389 | } |
| 379 | } | 390 | } |
| 380 | 391 | ||
| 392 | extension BabelCallTests { | ||
| 393 | @Test func ctrlCCtrlCRunsInlineCalls() { | ||
| 394 | let text = Self.named + "Inline call_double(n=6) here.\n" | ||
| 395 | let caret = (text as NSString).range(of: "call_").location + 2 | ||
| 396 | let context = EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [caret..<caret]) | ||
| 397 | #expect(ExecuteSrcBlock().applies(in: context)) | ||
| 398 | guard case .external(.babel(let job)) = CtrlCCtrlC().run(in: context) else { | ||
| 399 | Issue.record("inline call not run") | ||
| 400 | return | ||
| 401 | } | ||
| 402 | #expect((job.script ?? job.input).contains("echo $((n*2))")) | ||
| 403 | } | ||
| 404 | } | ||
| 405 | |||
| 381 | struct BabelFileTests { | 406 | struct BabelFileTests { |
| 382 | static let cases = [ | 407 | static let cases = [ |
| 383 | "#+begin_src sh :results file :file out.txt\necho hello\necho there\n#+end_src\n", | 408 | "#+begin_src sh :results file :file out.txt\necho hello\necho there\n#+end_src\n", |