Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Redo#812

Merged
thomasballinger merged 6 commits intobpython:masterfrom
allgo27:redo
Jun 30, 2020
Merged

Redo#812
thomasballinger merged 6 commits intobpython:masterfrom
allgo27:redo

Conversation

@allgo27
Copy link
Contributor

I think I fixed it! But it does feel a little "hack-y." You previously suggested we make history a class, do you still think that's a good idea? You also suggested we move redo somewhere else, though I don't know if you had ideas of where-- do you still have thoughts on that? Thanks!

Copy link
Member

@thomasballingerthomasballinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This approach seems solid, so I went ahead with comments about the nitty-gritty.

Trying it out, I like it. I often undo several lines, then hit up arrow multiple times to get back the old value to redo that line, so this is an improvement.

self.on_tab(back=True)
elif e in key_dispatch[self.config.undo_key]: # ctrl-r for undo
self.prompt_undo()
elif e in ["<Ctrl-g>"]: # for redo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍 this seems like a safe choice, bpython doesn't seem to use Ctrl-g for anything and don't know if you checked something likehttps://en.wikipedia.org/wiki/GNU_Readline but it doesn't sound like something people are clamoring for. It would be nice to make it configurable like self.config.undo_key.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Also it'd be nice to

  • follow the pattern of other keys of calling a method to keep this switch-like if/elif/elif/... structure shorter
  • also for symmetry, use a tuple here instead of a list

elif e in key_dispatch[self.config.undo_key]: # ctrl-r for undo
self.prompt_undo()
elif e in ["<Ctrl-g>"]: # for redo
if (self.could_be_redone):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I know we chose this together but I don't like it anymore, it sounds to me like a boolean. How about redo_stack?

self.on_tab(back=True)
elif e in key_dispatch[self.config.undo_key]: # ctrl-r for undo
self.prompt_undo()
elif e in ["<Ctrl-g>"]: # for redo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It'd be nice to follow the pattern of the other keys here, calling a method in the body of the if.

)
self.s_hist = []
self.history = []
self.history = [] # History of commands

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

how about "commands executed since beginning of session," this comment isn't helping me much now.

entries = list(self.rl_history.entries)

#Most recently undone command
lastEntry = self.history[-n:]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Could you change lastEntry -> last_entries; plural because it's a list, and snake_case


def on_enter(self, insert_into_history=True, reset_rl_history=True):
# so the cursor isn't touching a paren TODO: necessary?
if insert_into_history:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This if statement reads confusingly to me, I think we should:

  • rename theinsert_into_history parameter inRepl.reevaluate() tonew_code; this is what it means, it's about whether the lines might be new, so they should be added to readline history.
  • rename theinsert_into_history parameter inRepl.on_enter() tonew_code as well. Then this if becomes "if the line being executed is new, then we can no longer use our redo stack."
  • not rename insert_into_history anywhere else

My rationale for the name is thatnew_code describes the situation/circumstance instead of the behavior we want, which is important since we're now using this flag to determine a new, different behavior.

And in reviewing this I found that theself.reevaluate(insert_into_history=True) inclear_modules_and_reevaluate() should probably be False instead, we can fix in another PR.

@thomasballinger
Copy link
Member

You previously suggested we make history a class, do you still think that's a good idea?

Could do, I don't think it's a big improvement.

You also suggested we move redo somewhere else, though I don't know if you had ideas of where-- do you still have thoughts on that?

I'd move it to a method on this Repl class, maybe right belowprompt_undo(), line ~1820

greenlet.greenlet(prompt_for_undo).switch()

def reevaluate(self, insert_into_history=False):
def prompt_redo(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think just redo, "prompt_undo" is because it may prompt you for how many lines you want to undo.

self.undo(n=n)
return ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Could you remove this extraneous change?

@thomasballingerthomasballinger marked this pull request as ready for reviewJune 25, 2020 15:51
@thomasballinger
Copy link
Member

Ok one more thing! (I'd say on last thing but that's hard to promise)

Could you add this to the example config file, as a commented out key like undo:

# undo = C-r

@thomasballingerthomasballinger merged commitbe1160a intobpython:masterJun 30, 2020
allgo27 added a commit to allgo27/bpython that referenced this pull requestJul 1, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@thomasballingerthomasballingerthomasballinger approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@allgo27@thomasballinger

[8]ページ先頭

©2009-2026 Movatter.jp