trogdoro / xiki

A shell console with GUI features
http://xiki.org
Other
3.76k stars 208 forks source link

Confusing example on code page: undefined local variable or method `a' for Object:Class #153

Open thams opened 8 years ago

thams commented 8 years ago

This page starts like this:

| # Put some code here and expand to run it
| a = 1
| a + a

But if you expand both examples, the second one blows up.

| # Put some code here and expand to run it
| a = 1
  : 2
| a + a
  - tried to run: a + a
  - error:
    | undefined local variable or method `a' for Object:Class
    |   NameError
  - backtrace:
    =/Users/t/xiki-master/lib/xiki/core/code.rb:2:in `eval_inner'
    =/Users/t/xiki-master/lib/xiki/core/code.rb:299:in `module_eval'
    =/Users/t/xiki-master/lib/xiki/core/code.rb:299:in `eval_inner'
    ...
trogdoro commented 8 years ago

What you're seeing is the expected behavior.

It's because consecutive |... lines are treated as a paragraph, when you expand any one of them:

- When you expand the 3rd line:
code/
  | # Put some code here and expand to run it
  | a = 1
  | a + a
    : 2

- When you expand the 2nd line:
code/
  | # Put some code here and expand to run it
  | a = 1
    : 2
  | a + a

- When you expand the 2nd line then the 3rd line:
code/
  | # Put some code here and expand to run it
  | a = 1
    : 2
  | a + a
    - error:
      | undefined local variable or method `a' for Object:Class
      ...

The ": 2" output breaks up the "a = 1\na + a" into two separate chunks. When you ran it the first time, it evals "a = 1\na + a". When you run it the 2nd time, it evals only "a + a" and showing the appropriate error, that "a" wasn't defined.

You can always Ctrl+X on "| a = 1" to collapse the output under it, and then the output will no longer break up the paragraph.

It might have seemed more natural to you if the first output would have appeared below the "| a + a" line instead. But the reason I don't do it that way is because if there were 30 lines instead of just 2, the output would likely be off-screen.

thams commented 8 years ago

That makes complete sense. I'd only suggest then that the example helps the user understand

| # Put some code here and expand the last line to run it all | a = 1 | a + a

thams commented 8 years ago

(that's the kind of change I'd put in a pull request for you if you like)

trogdoro commented 8 years ago

expand the last line to run it all

That would be misleading though, since you can expand any line to run it. If there were 30 or 100 lines (which isn't uncommon) the user would think they had to go all the way to the bottom to run them. It's pretty common to edit, run, edit, run etc.. So that would be a lot of unnecessary cursor movement.

It does seem like there could be something done here to help the user understand what's going on, I just don't know what it is yet. Maybe in cases where the expanded line is close to the last line, the output could be inserted after the last line. Or, maybe the first time the user expands |... lines, I could have something pop up and explain how it works.

--Craig

On Fri, Oct 30, 2015 at 11:30 AM, Kurt Thams notifications@github.com wrote:

(that's the kind of change I'd put in a pull request for you if you like)

— Reply to this email directly or view it on GitHub https://github.com/trogdoro/xiki/issues/153#issuecomment-152610390.

thams commented 8 years ago

"Whatever line you expand, Xiki will run the code up to and including that line" ?

thams commented 8 years ago

If there were 30 or 100 lines (which isn't uncommon) the user would think they had to go all the way to the bottom to run them.

And maybe I still don't understand... if you want to run all 100 lines, you do have to move the cursor to end to run them, don't you?

trogdoro commented 8 years ago

Nope. Note that in this example the whole paragraph was run:

- When you expand the 2nd line:
code/
  | # Put some code here and expand to run it
  | a = 1
    : 2
  | a + a
thams commented 8 years ago

oh! Right!!!!!!!