Setting a default editor in Pry - ruby-on-rails

I'm asking about setting a default editor for Pry to use. I'm working on a Rails
app. I created a file named ".pryrc" immediately inside my working directory.
In this file, I wrote this line of code (based on what I read on Github :
Pry.config.editor = proc { |file, line| "sublime +#{line} #{file}" }
This doesn't seem to work. when I try the command ".sublime company.rb", I 'd get
this error:
Error: there was a problem executing system command: sublime company.rb
Can someone tell me what I'm doing wrong please?

Change the configuration to:
Pry.config.editor = proc { |file, line| "sublime #{file}:#{line}" }
You start the editor in Pry by using the edit command.
For example to open test.rb at line 30 use:
edit test.rb:30
See here for more details

For those who have the same problem as mine.Perhaps, you have trouble launching the editor even outside Pry. First thing, make sure to check if the sublime command exists in ur PATH. if not, you probably need to create a symlink between the command and the corresponding path to your app within /usr/local/bin. For more information, see here.

Related

Lua io.write() not working

I am using a luvit Lua environment to run my lua code through my control panel. I am looking to write to a .txt file, but with the simple code that i am running, its not working.
The reason I wish to write to a .txt file is to log notices from my Discord Bot I am working on in the Discordia library.
I have a folder called MezzaBOT. In this file i have a write.lua file and also a log.txt file. I have this simple code in my write.lua file:
io.output('log.txt')
io.write('hello\n')
io.close()
I then run in my command promt with Luvit environment:
>luvit Desktop\mezzabot\write.lua
I don't get any errors but the log.txt file continues to stay empty. Am I missing a line in my code, or do i need to access log.txt differently?
edit: my new code is the following
file = io.open('log.txt')
file:write('hello', '\n')
file:close()
and it is not making a new line for each time with \n
edit B:
Ok, i found my problem, its creating a log.txt in my C:\Users\PC.
One other problem is when writing, its not making a new line with the \n. Can someone please help me?
Lua, by default, opens files in read mode. You need to explicitly open a file in write mode if you want to write to it (see manual)
file = io.open('log.txt', 'w')
file:write('hello', '\n')
file:close()
Should work :)

Has anyone figured out setting up custom snippets on AWS Cloud9?

I've come across a few posts online but still befuddled and nothing concrete. Maybe someone can decode the below for me, seems like they figured it out but I've never made a plugin before so not sure where to start. Maybe can outline a file structure and I can take it from there? Thanks in advance
https://community.c9.io/t/snippets-not-working-in-c9/19215/3
I could not get plugins to load using the external url method, but loading plugins locally works.
You need to create a new plugin
mkdir -p ~/.c9/plugins/myPlugin/snippets;
cd ~/.c9/plugins/myPlugin/snippets;
printf '# scope: javascript\nsnippet test\n\tif (${1:true}) {\n\t\t${2}\n\t}\n\t$0' > javascript.snippets;
echo '{"name":"myPlugin", "plugins": {}}' > ../package.json
Then open your init script (click on AWS Cloud9 > Open Your Init Script in the menu bar) and add code for loading the plugin
services["language.complete"] = services["languageComplete"];
services.pluginManager.loadPackage([
"~/.c9/plugins/myPlugin/package.json",
])
To add more snippets edit ~/.c9/plugins/myPlugin/snippets/javascript.snippets
NOTE: snippet file needs to be indented with tabs not spaces
I pieced this together from the two links below.
How to load plugins locally: https://community.c9.io/t/snippets-not-working-in-c9/19215/3
Fix for AWS not loading snippets: https://forums.aws.amazon.com/thread.jspa?threadID=299949&tstart=0

Emacs haskell-mode: "Searching for program: no such file or directory, ghci"

For some reason emacs is not able to find my ghci. I am running Ubuntu 16.04, and followed the instructions in this tutorial to the book.
Using which ghci I get the path /opt/ghc/7.10.3/bin/ghci. And executing M-: exec-path and M-: (getenv "PATH") I can see that path correctly printed.
I have tried to explicitly set the PATH variable in emacs like this, which changes nothing since as far as I could tell it was already there. From this answer.
(setenv "PATH" "/usr/local/bin:/usr/bin:/bin:/opt/cabal/1.22/bin/cabal:/opt/ghc/7.10.3/bin/ghci")
(setq exec-path (split-string (getenv "PATH") path-separator)
The same thing happens when I use
(custom-set-variables '(haskell-process-type 'cabal-repl)) namely the error: "Searching for program: no such file or directory, cabal"
I would greatly appreciate help. :) I have no idea what to do, and I haven't found any answers on the internet.
The issue was that I was adding the path to the actual executable, rather than the folder in which the executable sits.
So:
/opt/cabal/1.22/bin/cabal
should be
/opt/cabal/1.22/bin/
and:
/opt/ghc/7.10.3/bin/ghci
should be
/opt/ghc/7.10.3/bin/

Issue in vim-rspec - not mapping the right path

The vim-rspec mapping is only getting the right path for one test. Somehow all the other tests are not loading with the right path.
When I do the command inside vim on the file that works, it gives the right command:
rspec spec/controllers/queue_items_controller_spec.rb
But for all the other specs, the path comes with the parent folders:
rspec /(...)/(...)/(...)/spec/controllers/reviews_controller_spec.rb
I have the following on my .vimrc
" vim-rspec mappings
let g:rspec_runner = "os_x_iterm"
map <Leader>t :call RunCurrentSpecFile()<CR>
map <Leader>s :call RunNearestSpec()<CR>
map <Leader>l :call RunLastSpec()<CR>
map <Leader>a :call RunAllSpecs()<CR>
I am using iTerm2 + Vim + Tmux.
Does any one knows how I fix this mapping issue?
I just found where the error is. It is actually an issue when you open the file through NERDTree. I did not find a solution for this specific issue, so for now I am just opening the spec files through CtrlP. – Gustavo Varallo

How to prevent vim from setting current directory

Recently my vim will change current directory no matter what I do. I'm using spf13 distribution and when I am in a rails app root directory and did vi, my pwd will be correctly in app root directory. But once I open some file, any file, it will change the pwd to abosolute/path/to/myrailsapp/app/assets/stylesheets,
When I don't have let g:spf13_no_autochdir = 1 in my .vimrc, vim will change the pwd to current file directory; When I do, it will change to the stylesheet directory whenever I open a file.
I'm also using rails.vim installed. Here is the related code inside my .vimrc
if !exists('g:spf13_no_autochdir')
autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" | lcd %:p:h | endif
" Always switch to the current file directory
endif
UPDATE:
What I want: the pwd always stay in absolute/path/to/myrailsapp/, no changing to the stylesheet directory automatically whenever I open a file.
Actually I just found and had a look at the plugin. I assume this is it:
https://github.com/spf13/spf13-vim/blob/3.0/.vimrc
Around line 75 you can see:
" Most prefer to automatically switch to the current file directory when
" a new buffer is opened; to prevent this behavior, add the following to
" your .vimrc.before.local file:
" let g:spf13_no_autochdir = 1
So just add that last line (without the comment-marker quote) to your .vimrc and you'll get rid of the automated directory change.
I note that neither method in my other answer would have worked, because the plugin author for whatever reason decided not to use the built-in option, and also not to put their autocmd in a group. Naughty, naughty!
I solved this according to Ben's second answer.
spf13 loads configuration files in order as follows.
.vimrc.before - spf13-vim before configuration
.vimrc.before.fork - fork before configuration
.vimrc.before.local - before user configuration
.vimrc.bundles - spf13-vim bundle configuration
.vimrc.bundles.fork - fork bundle configuration
.vimrc.bundles.local - local user bundle configuration
.vimrc - spf13-vim vim configuration
.vimrc.fork - fork vim configuration
.vimrc.local - local user configuration
if !exists('g:spf13_no_autochdir') check is done at (7), so let g:spf13_no_autochdir = 1 should be loaded before that.
I put it in .vimrc.before.local, and it works as expected.
There are two ways this could be happening.
The most likely, is that this "spf13" configuration includes set autochdir. To find out whether this is the case, start up Vim normally, and type :verbose set autochdir? and press Enter. This should tell you IF autochdir is set and WHICH FILE set it to that value.
If autochdir is set, then you only need to set up a VimEnter autocmd, or stick a file in ~/.vim/after/plugin, to turn it off again after spf13 loads.
If autochdir is NOT set, then probably an autocmd is setting your directory for you. If there is a plugin option in SPF13 to turn it off, then do that. If not, you'll need to find where in the plugin the directory is getting changed. If you're lucky, the autocmd will be in an augroup by itself, and you can then remove that autocmd with :au! GroupName. This command can be in the same places; a VimEnter autocmd, or a file in ~/.vim/after/plugin.

Resources