Skip to content
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

Weird behavior with Pry #136

Open
Flink opened this issue Aug 23, 2020 · 15 comments
Open

Weird behavior with Pry #136

Flink opened this issue Aug 23, 2020 · 15 comments

Comments

@Flink
Copy link

Flink commented Aug 23, 2020

Hi!

I’m trying Spacemacs a second time, trying to use it instead of my neovim config and I have a hard time making things work as I want them regarding specs and binding.pry.

First I found that I had to do C-x C-q in the compilation buffer to make it work with ruby-inf but then I have another problem:

2.6.6 (#<RSpec::ExampleGroups::Device::Locale::WhenDevicesHaveTheSameLocale:0x000055873d281580>):0 > 1
1
2.6.6 (#<RSpec::ExampleGroups::Device::Locale::WhenDevicesHaveTheSameLocale:0x000055873d281580>):0 > 11
2.6.6 (#<RSpec::ExampleGroups::Device::Locale::WhenDevicesHaveTheSameLocale:0x000055873d281580>):0 > 3
3
2.6.6 (#<RSpec::ExampleGroups::Device::Locale::WhenDevicesHaveTheSameLocale:0x000055873d281580>):0 > 33
2.6.6 (#<RSpec::ExampleGroups::Device::Locale::WhenDevicesHaveTheSameLocale:0x000055873d281580>):0 > 

It seems characters are echoed back by the buffer/ruby-inf/whatever instead of being displayed normally. I have a custom Pry prompt but even when reverting it it still behaves in the same way.

By the way I tried to add a customization for my prompt but to no avail (documentation is a bit hard to follow on this 😅). I’ve put this in my .spacemacs config file but it doesn’t work (regex should be valid so it’s weird):

    (add-hook 'inf-ruby-mode-hook
              (lambda() (let ((p "[:digit:]\\.[:digit:]\\.[:digit:] ?\\([^(]+\\):[:digit:]+ ?(*|>)"))
                          (setq inf-ruby-first-prompt-pattern (concat inf-ruby-first-prompt-pattern p))
                          (setq inf-ruby-prompt-pattern (concat inf-ruby-prompt-pattern p)))))

Anyone able to help me with these please? 🙂

@dgutov
Copy link
Collaborator

dgutov commented Aug 23, 2020

It doesn't look like your regexp matches the actual prompt examples.

Try it in M-x re-builder to see.

Try this one: "[[:digit:]]\\.[[:digit:]]\\.[[:digit:]] ?([^(]+):[[:digit:]]+ ?\\(*\\|>\\)".

Or the shorter version: "[0-9]\\.[0-9]\\.[0-9] ?([^(]+):[0-9]+ ?\\(*\\|>\\)".

@Flink
Copy link
Author

Flink commented Aug 24, 2020

Ah yes indeed 🤦‍♂️ Thanks, I’m currently trying different things with M-x re-builder, I have one that seems to match now but still it doesn’t seem to work as expected in the compilation buffer. I guess it’s just a matter of tweaking it (double-escaping proper things I hope…).

Any idea about the echo back thingy?

@Flink
Copy link
Author

Flink commented Aug 24, 2020

And still not working for the regex. I think I don’t get what characters and how it should be double escaped, it doesn’t make sense compared to what I’m used to (not lisp 😅). Sometimes it’s \\( where it should just be ( as it’s to group something and sometimes it seems there is nothing but it should be escaped normally… (checking the source code of the package trying to make sense of how are made the regexps for other prompts). Any advice on this please? 🙂

(by the way this one is working in re-builder: "[0-9]\.[0-9]\.[0-9] ?\([^(]+\):[0-9]+ ?>|*" but not once I put it in my config. Don’t understand what to escape and how)

@dgutov
Copy link
Collaborator

dgutov commented Aug 24, 2020

As far as I can tell, either of the regexps I showed should match the prompt. If that still doesn't help, of course, we'll have to investigate further.

About what to escape or not, Emacs regexps are based on the "basic" syntax. Here you can see some documentation: https://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Backslash.html#Regexp-Backslash

@Flink
Copy link
Author

Flink commented Aug 24, 2020

Copied/pasted your last regexp, tried others but the compilation buffer doesn’t switch automatically to ruby inf 😕

This is what I’m using now, tried to make it similar to the one in the wiki:

  (add-hook 'inf-ruby-mode-hook
            (lambda() (let ((p "\\|\\(^[0-9]\\.[0-9]\\.[0-9] ?([^(]+):[0-9]+ ?> *\\)"))
                        (setq inf-ruby-first-prompt-pattern (concat inf-ruby-first-prompt-pattern p))
                        (setq inf-ruby-prompt-pattern (concat inf-ruby-prompt-pattern p)))))

When I try with the standard pry prompt, it’s automatically detected though. And this isn’t resolving the problem of having the output a bit garbled.

@dgutov
Copy link
Collaborator

dgutov commented Aug 24, 2020

This is what I’m using now, tried to make it similar to the one in the wiki:

Which wiki? The extra grouping and alternation and the beginning don't seem to be useful, going by your examples.

And this isn’t resolving the problem of having the output a bit garbled.

That's too bad. But I can't reproduce the problem.

Any chance you can post a sample project, with Gemfile.lock and a spec file which triggers this problem for you?

@Flink
Copy link
Author

Flink commented Aug 24, 2020

For the wiki I was trying to follow this one: https://github.com/nonsequitur/inf-ruby/wiki/Adding-new-prompt-patterns

Otherwise I did some tests and the problem with the commands being echoed (and having no completion) seems to be related to docker. Completely forgot to say that I’m working with containers, I just didn’t think it could mess up the completion buffer/inf-ruby as it doesn’t make a difference in neovim (using a terminal though that’s surely why).

So I used an existing rails project and make the config similar to the one I’m working on. I managed to reduce the biggest annoyances by setting TERM to dumb and PAGER to cat but still that command that is echoed back each time and no completion (it seems to put some ruby code when pressing on TAB and some garbage). Also I’m using Spacemacs as stated in my initial post, my config file is available here: https://gist.github.com/Flink/dcb5783b177a826ab901a29a2cd151cf (I’m using the develop branch otherwise LSP is not available)

The project is available here: https://github.com/Flink/sample_rails_app
To set it up, just run docker-compose build app (you might have to have direnv installed and do a direnv allow before that to export UID/GID to the build process) and then docker-compose run --rm app bash, bundle and everything should be ready to be used.

I’ve included a .dir-locals.el file which configures rspec-mode to run the proper commands when using SPC m t t. I’ve left a binding.pry statement in the user model spec too.

I think that’s all 😅 And thanks again for your time! 😊

@dgutov
Copy link
Collaborator

dgutov commented Aug 24, 2020

Do you think I will be able to repro without Spacemacs? 😰

@Flink
Copy link
Author

Flink commented Aug 24, 2020

I’m not sure since I haven’t a big experience with emacs but I’d say it should be possible 😅 The main thing I think is rspec-mode and inf-ruby since SPC m t t is bound to rspec mode verify (something like that) and this one invokes the commands customized in .dir-locals.el through the compilation buffer. I don’t think spacemacs does anything regarding the problem at hand (I mean in the compilation buffer specifically).

@dgutov
Copy link
Collaborator

dgutov commented Sep 18, 2020

OK, I found the time to repro.

Indeed, this happens. There are too many layers involved for me to quickly understand where this is coming from, but you can observe the difference in behavior by evaluating `stty -echo` in the Pry REPL.

To counteract it on the side of Emacs instead, set comint-process-echoes to t.

@dgutov
Copy link
Collaborator

dgutov commented Sep 18, 2020

@micdahl Have you seen this before, maybe?

@dgutov
Copy link
Collaborator

dgutov commented Oct 1, 2023

Hi again! 😬

Some very late investigation results:

  1. As was helpfully suggested in fix ruby-print-result for pry #174 (comment) by @snowman, AwesomePrint removes the => marker (which we rely on). Commenting AwesomePrint.pry! out in .pryrc makes it appear again.
  2. (setq comint-process-echoes t) seems to be necessary as well. As pointed out by @bo-tato Multiple irb prompt strings in send-region output #49 (comment), the REPL echoes when it thinks it's not being run interactively. The set up docker-compose incantation (docker-compose run --rm -e TERM=dumb -e PAGER=cat app) seems to have that result. I see your docker-compose.yml already includes tty: true and stdin_open: true suggested for similar cases on SO, and apparently they do not help. Further investigation needed. But setting comint-process-echoes in the same hook (inf-ruby-mode-hook) drops the echoes. A call to `stty -echo` does that too.
  3. These prompt settings work with that project's Pry prompt:
(let ((p "[0-9]\\.[0-9]\\.[0-9] ?([^(]+):[0-9]+ ?"))
 (setq inf-ruby-first-prompt-pattern (concat p ">"))
 (setq inf-ruby-prompt-pattern (concat p "\\(*\\|>\\)")))

But it's not really a healthy solution, to ask everyone to fiddle with their regexps. First I would try to make them more "regular" in that project (does including the Ruby version help much?), but if this format is popular enough, we should look into updating our regexps here.

@dgutov
Copy link
Collaborator

dgutov commented Oct 1, 2023

With the above tweaks, both input history navigation and completion seem to work. The latter is pretty sluggish, though (EDIT: with the updated prompt regexps above -- not sluggish anymore).

@dgutov
Copy link
Collaborator

dgutov commented Oct 1, 2023

One more thing. Starting with Emacs 29, Tramp supports docker as one of the connection methods (and for earlier versions, there is a 3rd party package).

Logging into an existing container and running the tests in there through Tramp takes care of the echoing as well (alternative solution for item number 2).

@dgutov
Copy link
Collaborator

dgutov commented Oct 1, 2023

First I would try to make them more "regular" in that project

This is done by commenting out the Pry.config.prompt = assignment in the same .pryrc. But of course if an existing team has settled on a particular prompt, a more complex solution can be required.

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

No branches or pull requests

2 participants