syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.67k stars 4.89k forks source link

Ruby layer and pry-byebug on the emacs console #6462

Closed casertap closed 8 years ago

casertap commented 8 years ago

I am trying to debug my ruby code using byebug when running my test. I am using SPC m t t to run the current test, byebug kicks in but I can not enter anything on the rspec-compilation buffer/console.

I can not enter c for instance to continue. It says Buffer is read-only. I tried C-x Cq but it did not help I tried adding (add-hook 'after-init-hook 'inf-ruby-switch-setup) but it did not work

This is my shell config

     (shell :variables
             shell-default-height 30
             shell-default-position 'bottom
             shell-default-shell 'term)

How can I use byebug inside spacemacs please?

d12frosted commented 8 years ago

It might be useful to have output of SPC h d s.

Since I am not using ruby layer, calling upon the knowledge and experience of @robbyoconnor (you do use ruby layer, right?) 💃

casertap commented 8 years ago

Hi, this is the output of _Message_ Yes, I am able to use the ruby layer like doing SPC m g g to go to method, etc. Rspec is starting but I can not input some new caracter in the emacs teminal to be able to debug step by step.

#### System Info
- OS: darwin
- Emacs: 24.5.1
- Spacemacs: 0.105.21
- Spacemacs branch: master (rev. 0283f64)
- Graphic display: nil
- Distribution: spacemacs
- Editing style: vim
- Completion: helm
- Layers:
```elisp
(auto-completion better-defaults themes-megapack emacs-lisp ruby ruby-on-rails git github osx dockerfile java emacs-lisp react
                 (shell :variables shell-default-height 30 shell-default-position 'bottom shell-default-shell 'term)
                 (javascript :variables javascript-disable-tern-port-files nil)
                 html)

Information has been copied to clipboard. You can paste it in the gitter chat. Check the Messages buffer if you need to review it Quit Saving file /Users/pierrecaserta/workspace/dotfiles/.spacemacs... Wrote /Users/pierrecaserta/workspace/dotfiles/.spacemacs RSpec Compilation exited abnormally with code 1

casertap commented 8 years ago

this is where I am stuck:

 1 -*- mode: rspec-compilation; default-directory: "~/workspace/jora_ads/" -*-
 2 RSpec Compilation started at Thu Jun 30 16:06:18
 3
 4 bundle exec rspec --options /Users/pc/workspace/jora_ads/.rspec /Users/pc/workspace/jora_ads/spec/lib/services/image_ad_response_caching_service_spec.rb:68
 5 Run options: include {:locations=>{"./spec/lib/services/image_ad_response_caching_service_spec.rb"=>[68]}}
 6
 7 Services::ImageAdResponseCachingService
 8   #process_request
 9     without existing cache entry
10       with multiple contenders
11
12 [15, 24] in /Users/pc/workspace/jora_ads/lib/services/image_ad_response_caching_service.rb
13    15:     private
14    16:
15    17:     def lock_and_process_request(ads_request)
16    18:       cache_key = "ads-request-#{ads_request.tk}"
17    19:       require 'pry-byebug'; byebug;
18 => 20:       process_request_on_engine = -> { Engine.new.process(ads_request) }
19    21:       ads_response = Caching::Redis.instance.read(cache_key)
20    22:       unless ads_response
21    23:         ads_response = lock_semaphore(cache_key, process_request_on_engine) do
22    24:           Caching::Redis.instance.fetch(cache_key, expires_in: 30.seconds) do
23 (byebug)

I can not enter any caracter to be able to edbug step by step

robbyoconnor commented 8 years ago

I've never used that

robbyoconnor commented 8 years ago

I don't do much Ruby lately -- I love it but I don't use it :(

casertap commented 8 years ago

Ho ok, basically this is an invaluable tool for ruby developer because it allows you to run your code step by step and check values, etc... There is no problem with the tool in itself. the problem comes from the fact that I can not edit the buffer to make byebug understand that I want to go to the next line for instance. So I am basically stuck because byebug is waiting for an input.

robbyoconnor commented 8 years ago

That's a lie -- I did use a few times...just not in spacemacs

casertap commented 8 years ago

I have no idea how to solve this. If you find a solution in the future, I will be very interested to here about it

robbyoconnor commented 8 years ago

I'm not sure -- I do a heap of devops lately -- I'd love to get back into Ruby

phstc commented 8 years ago

I tried C-x Cq but it did not help I tried adding (add-hook 'after-init-hook 'inf-ruby-switch-setup) but it did not work

C-x C-q worked for me, after appending inf-ruby-switch-setup into my dotspacemacs/user-config (SPC f e d).

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
  ;; ...
  (inf-ruby-switch-setup))
phstc commented 8 years ago

Actually adding:

(add-hook 'after-init-hook 'inf-ruby-switch-setup)

at end of my .spacemacs also worked.

screen shot 2016-07-03 at 12 12 58

casertap commented 8 years ago

@phstc Thank you very much, it works for me as well my mistake was that I was adding the (add-hook 'after-init-hook 'inf-ruby-switch-setup) on the user-config which make no sense at all. I understand a little better how the .spacemacs config work now. Thanks a lot.

wcalderipe commented 4 years ago

I stumbled on the same issue while configuring my Emacs for a better Ruby developer experience. Based on your conversation I adjusted my setup to make Pry and byebug work - thanks for sharing, folks!

If you're using use-package, here's a snippet that might work (it's vanilla Emacs):

(use-package inf-ruby
  :straight t
  :defer t
  :hook ((after-init . inf-ruby-switch-setup))
  :config
  (general-define-key
   :prefix my/leader
   :states 'normal
   :keymaps 'rspec-compilation-mode-map
   ;; Switches from rspec-mode to inf-ruby-mode so I can interact with Pry or
   ;; byebug.
   "c" 'inf-ruby-switch-from-compilation))

Note: the snippet contains other dependencies such as straight, general, and my/leader which you might want to get rid of.