Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autocomplete and camelcase

If I use Meta-/ to autocomplete words like ThisClass, emacs gets confused and gives me either THISCLASS or thisclass. Worse yet, if I have typed ThisC and then autocomplete it gives Thisclass which is very frustrating.

Is there a way to modify this behavior ?

like image 293
Rohan Monga Avatar asked Dec 08 '10 04:12

Rohan Monga


3 Answers

In addition to hippie-expand, you can also achieve your desired behavior with just dabbrev by customizing the following variable:

dabbrev-case-fold-search is a variable defined in `dabbrev.el'.
Its value is nil

  This variable is potentially risky when used as a file local variable.

Documentation:
Control whether dabbrev searches should ignore case.
A value of nil means case is significant.
A value of `case-fold-search' means case is significant
 if `case-fold-search' is nil.
Any other non-nil version means case is not significant.

You can customize this variable.
like image 146
Derek Slager Avatar answered Nov 06 '22 01:11

Derek Slager


Yup, use hippie-expand:

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

Check out the wiki page on it, and the terse manual page for it.

hippie-expand is like dabbrev (the default binding for M-/), but adds more capability, and in the process has fixed the camelcase issue you point out.

like image 23
Trey Jackson Avatar answered Nov 06 '22 00:11

Trey Jackson


While modifying the search behavior is one way to fix the issue, another way that's perhaps better is to keep the search behavior as-is but instead to modify the replacement behavior.

To accomplish this, set the variable dabbrev-case-replace to nil.

This way is perhaps better because, even if what you typed is incorrect case, it will still be correctly matched, and then completed to the correct case.

Example: Let's say you have the variable "aVariable". If you change the search behavior (setting dabbrev-case-fold-search to nil), then typing "av" will not match your variable. However, if you instead change the replacement behavior (setting dabbrev-case-replace to nil), then typing "av" will expand to "aVariable".

Reference: http://www.gnu.org/software/emacs/manual/html_node/emacs/Dabbrev-Customization.html

like image 2
walrus Avatar answered Nov 05 '22 23:11

walrus