reddit / emacs

Text Expansion with Hippie Expand

mickeyp · 2022-05-17 13:37
mickeyp · 2022-05-17 13:38
I saw some chatter about hippie recently and figured I'd write about one of my favourite features in Emacs. If someone's using it for something cool, I'd love to hear about it.
bruchieOP · 2022-05-17 14:22
great article explaining how it works! I think other IDE has been trying to mimic hippie expand for example in intellij which bind alt+/ to a version of it.... hippie expand goes way beyond the basic buffer completion, and when properly configured it seems to get the string I look for, compared to lsp/company which sometime get really annoying.
_viz_ · 2022-05-17 14:33
I actually switched back to using dabbrev-expand last week. The main annoyance is that I can't complete filenames anymore but so far it's been fine. I think what annoyed me the most was the list expand. As for something cool, I saw this post long back: https://www.reddit.com/r/emacs/comments/hqxm5v/weekly_tipstricketc_thread/fy0xduj/ and I did this a while back: https://www.reddit.com/r/emacs/comments/qgrpte/weekly_tips_tricks_c_thread/himvw1j/
chandaliergalaxy · 2022-05-17 14:34
Wow I thought I was one of the few still using hippie expand as it seems other people have moved onto newer completion techniques. Sometimes I wondered what I'm missing out on, but hippie expand is so easy and convenient.
mickeyp · 2022-05-17 14:39
You can just amend the list of try completers and remove the ones you dislike. Might be one way to have your cake and eat it: just keep the dabbrev completer and the filename one. Those examples are both really cool. Thanks for linking!
mickeyp · 2022-05-17 14:40
I think it's a good wedge between intelligent completion systems that LSP may offer, and just simple word expansion. I can't live without hippie.
vifon · 2022-05-17 14:47
I actually prefer `dabbrev-expand` as it's possible to "chain" it to complete multiple consecutive tokens by inserting a space after `dabbrev-expand` and calling it again. Roughly `M-/ SPC M-/ SPC M-/ …`. I have `dabbrev-expand` bound at `M-/` (the default) and `hippie-expand` at `C-M-?` (aka `C-M-S-/`) so I have access to both, but I use `dabbrev-expand` far more often.
_viz_ · 2022-05-17 14:47
>You can just amend the list of try completers and remove the ones you dislike. Might be one way to have your cake and eat it: just keep the dabbrev completer and the filename one. Yep, I have to do this. Takes patience tho so I will leave it to future frustrated/annoyed me. ;-) Also I think the current dabbrev try functions don't take the new dabbrev defcustoms into account as well. :-(
sebhoagie · 2022-05-17 16:30
I tried hippie and ended up going back to dabbrev too, seemed to be less noisy. I do get filename completions though.
a-c-d-w · 2022-05-17 18:06
Oh great! I've honestly just sort of been "using" hippie for a while, not really knowing how it works. Thanks /u/mickeyp !
bugamn · 2022-05-17 18:11
I just saw this on the RSS feed and I have to try it! This is very timely as I've been wondering about better completion option for non-programming modes
b3n · 2022-05-17 18:49
As you briefly mention Yasnippet, it's worth pointing out that Yasnippet comes with `#'yas-hippie-try-expand` allowing it to be easily integrated with Hippie.
mickeyp · 2022-05-17 18:51
Neat. I didn't know that.
Foo-jin · 2022-05-17 19:37
I recently replaced my use of `company` with `complete-at-point` -- anyone using a similar setup managed to combine this with hippie? Otherwise it seems rather hard to integrate into my workflow if these two semi-overlap but not quite ...
sebhoagie · 2022-05-17 20:00
I tried Corfu and plain CAPF like you have now, and for some reason the lists of candidates I get doesn't match what company offers. Even in modes with no specific backend, like Elisp. Did you notice something similar? or with CAPF get the same candidates than in Company but cycling rather than with a pop-up?
Foo-jin · 2022-05-17 20:03
as far as I can tell I get the same candidates with CAPF as Company but then in the same fashion as `find-file` and similar minibuffer selections. However, I haven't switched for very long so I could just not have noticed anything wrong yet.
mmarshall540 · 2022-05-17 23:46
Is there a way to freely move back and forth in the expansion list? I tried using undo/redo, which is okay if you accidentally pass an item and know for sure you wanted to use it. But undoing ends the expansion sequence. Meaning that you can undo to go backwards in the list. And you can redo to go forward again, but when you get to the expansion where you first called undo, you can't go forward any further.
_viz_ · 2022-05-18 05:12
IIRC, someone posted a completing-read interface to hippie expansions in the weekly thread a while back. Perhaps that could serve as a good starting point for what you want; alternatively, you can also take dabbrev-completion (or dabbrev-capf in Emacs master) as an example.
mickeyp · 2022-05-18 06:08
Not really. You can give Hippie a negative argument `M-- M-/` to reset the expansion to the start.
JDRiverRun · 2022-05-18 18:03
Are you sure the candidates actually differ, vs. just the sorting of them? If so, it's likely due to the backends configured. Company sometimes has CAPF + other backends enabled (like company-dabbrev). You can replicate this "combined sources" style in CAPF-land [using cape](https://github.com/minad/corfu/wiki#using-cape-to-tweak-and-combine-capfs). I actually quite enjoy combining the results of `cape-dabbrev` and `elisp-completion-at-point` (the default completion provider in emacs-lisp mode). This helps because dabbrev works even before you have evaluated/loaded a buffer. [Here's how it looks](https://user-images.githubusercontent.com/93749/169111128-088ae219-a4e1-433d-8051-37b00d503917.png) for me (with corfu and kind-icons, and a complicated orderless search).
sebhoagie · 2022-05-18 20:53
That could be it too, Corfu tends to match what I get from C-M-i with plain CAPF. Great explanation. Thank you!
wargxs · 2022-05-18 22:05
Maybe this? https://github.com/duckwork/hippie-completing-read
wargxs · 2022-05-18 22:06
https://github.com/duckwork/hippie-completing-read maybe?
Knusper2000 · 2022-05-28 02:56
I've got it bound to M-SPC ...