Pharo: how to make Cmd + d ("do it") execute the entire multiline default statement instead of the current line

Suppose I have a multiline statement like this:

1 to: 5 do: [:i|
  Transcript show: i.
  Transcript cr].

Currently, when I put a text cursor on a line (without selecting anything) and press Cmd + d, Pharo tries to execute the current line. But it would be more convenient for me if, by default (when nothing is selected), Pharo will execute the current statement (i.e., all this three-line operator), and not just the current line. Because this is a much more frequent case ("I want to execute the entire statement") than "I want to execute this particular line inside the statement" (which in most cases just doesn't make sense syntactically, like the 1st and 3rd lines Here) . And in these back cases (when I need to execute a line inside a statement), I would first select that line manually.

How can i achieve this?

+4
source share
2

: . ---do. , . , " ". , AST . , . ( , AST , (/workspace/ ))

+1

. .

ExpressionFinder .

ivars

  • string: ( //)
  • compiler: ,
  • lines: pos->line, pos - line string
  • index: lines,
  • interval: , , nil

, string, compiler position string. :

string: aString position: anInteger compiler: aCompiler
  string := aString.
  compiler := aCompiler.
  self computeLines.
  index := lines findLast: [:assoc | assoc key <= anInteger]

:

computeLines
  | reader |
  lines := OrderedCollection new.
  reader := string readStream.
  [reader atEnd]
    whileFalse: [lines add: reader position + 1 -> reader nextLine]

, . ( ):

, . , . , .

find
  | i |
  i := index.
  [
    i <= 0 ifTrue: [^self].
    assoc := lines at: i.
    self findFrom: assoc key]
    whileFalse: [i := i - 1]

findFrom: start
  | i end success |
  i := index.
  [| assoc fragment |
    assoc := lines at: i + 1 ifAbsent: [string size + 1 -> nil]. 
    end := assoc key - 1.
    fragment := string copyFrom: start to: end.
    success := self canCompile: fragment.
    success not and: [end < string size]]
    whileTrue: [i := i + 1].
  success ifTrue: [interval := start to: end].
  ^success

canCompile: fragment ,

canCompile: fragment
  ^(compiler compileExpression: fragment) notNil

CompilationErrors, canCompile:, . . , , , , findFrom:, ..

0

Source: https://habr.com/ru/post/1657904/