Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs ruby symbol word completion

Quite often I define a ruby symbol (eg. :some_value), then I want to create a method with the same name def some_value.

Unfortunately, the autocompletion(M + /) for the second occurrence of some_value string does not work, being slightly different (:some_value vs some_value).

How can I setup emacs to handle such events?

like image 799
vise Avatar asked Aug 04 '10 07:08

vise


3 Answers

Assuming that M-/ is bound to dabbrev-expand, you can configure dabbrev-mode to ignore certain prefixes when expanding strings. To make a single colon a prefix to be ignored, type

M-x customize-group

and then

dabbrev

This will take you to the customization page for dabbrev-mode. Go to the point Dabbrev Abbrev Skip Leading Regexp and click on Value menu. From the menu, pick "Regexp".

Now you see a textfield labeled "Regexp: " next to the value menu in which you enter a single colon.

:

Then click on the button State in the next line and choose the value "Save for Future Sessions".

like image 199
Thomas Avatar answered Oct 10 '22 04:10

Thomas


First, my results! I typed :some_crazy_symbol in my model. On a newline, I typed def so, hit M-/ twice, and ended up with

def some_crazy_symbol
end

(Rinari supplied the end.)

I got this to work quite well by using hippie-expand. If you want to test it out, bind hippie-expand to M-/ like so:

(global-set-key (kbd "M-/") 'hippie-expand)

Heres' the documentation. Hippie expand works by trying out a number of different expansions on the current point. These expansions are stored in the hippie-expand-try-functions-list variable. On my system (and be default), this variable is set to:

(try-complete-file-name-partially try-complete-file-name try-expand-all-abbrevs try-expand-list try-expand-line try-expand-dabbrev try-expand-dabbrev-all-buffers try-expand-dabbrev-from-kill try-complete-lisp-symbol-partially try-complete-lisp-symbol)

The minibuffer readout showed that this particular expansion was accomplished using the try-expand-dabbrev function.

like image 20
Sam Ritchie Avatar answered Oct 10 '22 03:10

Sam Ritchie


Not a direct answer to your question, but you should get more intelligent Ruby autocompletion by using auto complete mode paired with rsense.

like image 36
darioo Avatar answered Oct 10 '22 04:10

darioo