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 ?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With