Skip to content

Redo #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 30, 2020
Merged

Redo #812

merged 6 commits into from
Jun 30, 2020

Conversation

allgo27
Copy link
Contributor

@allgo27 allgo27 commented Jun 24, 2020

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

@thomasballinger thomasballinger 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.

@@ -775,6 +775,13 @@ def process_key_event(self, e):
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
Copy link
Member

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 like https://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.

Copy link
Member

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

@@ -775,6 +775,13 @@ def process_key_event(self, e):
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
if (self.could_be_redone):
Copy link
Member

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?

@@ -775,6 +775,13 @@ def process_key_event(self, e):
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
Copy link
Member

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.

bpython/repl.py Outdated
@@ -439,7 +439,8 @@ def __init__(self, interp, config):
duplicates=config.hist_duplicates, hist_size=config.hist_length
)
self.s_hist = []
self.history = []
self.history = [] # History of commands
Copy link
Member

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.

bpython/repl.py Outdated
@@ -1009,6 +1010,10 @@ def undo(self, n=1):

entries = list(self.rl_history.entries)

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

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

@@ -860,6 +867,9 @@ def readline_kill(self, e):

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:
Copy link
Member

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 the insert_into_history parameter in Repl.reevaluate() to new_code; this is what it means, it's about whether the lines might be new, so they should be added to readline history.
  • rename the insert_into_history parameter in Repl.on_enter() to new_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 that new_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 the self.reevaluate(insert_into_history=True) in clear_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 below prompt_undo(), line ~1820

@@ -1811,7 +1816,15 @@ def prompt_for_undo():

greenlet.greenlet(prompt_for_undo).switch()

def reevaluate(self, insert_into_history=False):
def prompt_redo(self):
Copy link
Member

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.

bpython/cli.py Outdated
@@ -905,7 +905,7 @@ def p_key(self, key):
if n > 0:
self.undo(n=n)
return ""

Copy link
Member

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?

@thomasballinger thomasballinger marked this pull request as ready for review June 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

@thomasballinger thomasballinger merged commit be1160a into bpython:master Jun 30, 2020
allgo27 added a commit to allgo27/bpython that referenced this pull request Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants