Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pharo: how to make Cmd+d ("do it") execute the whole multi-line statement by default instead of just the current line

Suppose I have a multi-line statement like this:

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

Currently, when I put a text cursor on some 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 would execute the current statement (i.e. all this three-line statement), not just the current line. Because this is a much more frequent case ("I want to execute the whole statement") than "I want to execute this particular line inside a statement" (which in most cases just doesn't make sense syntactically, as 1st and 3rd lines here). And in these rear occasions (when I need to execute a line inside a statement) I would pre-select this line manually.

How can I achieve this?

like image 318
Grigory Hatsevich Avatar asked Nov 08 '22 07:11

Grigory Hatsevich


1 Answers

To answer your question: Take a look at the text component. It has some method for evaluate-selection-and-do. And if nothing is selected, it tries to select the current line. You may change this implementation to find the top most statement "scope". It could be possible if you work with the code AST instead of the text. I worked once with this, to make it smarter for code expressions inside of comments.(that didn't work for all situations because the context for getting the method AST isn't always the same for this text component,in different tools (browser/workspace/and other))

like image 189
Nicolai Hess Avatar answered Jan 04 '23 01:01

Nicolai Hess