reddit / emacs

A package that abbreviates the word at point

VernonGrant 路 2022-09-08 17:11
I spent a few hours today creating this silly little package that basically does the exact opposite of `abbrev-mode`. The reason is that I always forget certain abbreviations and wanted to make sure I keep the abbreviations I use consistent across code bases. Maybe someone in the community will also find it useful and hopefully Emacs does not already have this feature and I missed it somehow! 馃槄 **Example:** https://i.redd.it/o811cqad2om91.gif **I also made it possible to add your own abbreviations**, please check the below repository for more information. And if anyone wants to help contribute some abbreviations or features, please do! Repository: [https://github.com/VernonGrant/abbreviate.el](https://github.com/VernonGrant/abbreviate.el)
eleven_cupfuls 路 2022-09-08 17:27
I don't want to detract from your work, nicely done! But you can actually use `abbrev-mode` for this already. 馃榿 Check this out: 1. `C-x b abbrev-test <RET>` 2. `M-x abbrev-mode <RET>` 3. Type "rect" into the buffer 4. `C-x a +` (`add-mode-abbrev`) 5. Type "rectangle" into the prompt, hit `<RET>` 6. Now in the buffer type the word "rectangle" then a space! In other words, you can add an "abbrev" definition from a _longer_ to a _shorter_ string.
VernonGrant 路 2022-09-08 18:17
No, thanks for letting me know! But, I think this might cause issues as abbrev-mode automatically expands abbreviations as you press space. So if you start defining longer to shorter abbreviations, normal words will collapse as you type. With abbrev-mode, your abbreviations triggers, can't be actual words, they kinda need to be an uncommon sequence of characters. Does that make sense or am I missing something?
eleven_cupfuls 路 2022-09-08 18:42
I don't think so, because that would also be a problem for shorter-to-longer. abbrev only does a replacement on full words. For example, if you define "bar" as an abbrev for "belayed and ready", "foobar" won't trigger expansion. But it's possible I am not aware of some edge case. I admit I don't actually use abbrev-mode regularly myself. I've experimented with it but use yasnippet instead for my workflows.
VernonGrant 路 2022-09-09 01:29
I guess I need to look into it in more detail, thanks again! 馃檹馃徎
SequentialDesign 路 2022-09-09 05:05
this approach would cause problems in regular writing. you would trigger abbreviations you wouldn't want to. for example, you would trigger `h` by writing `height` and `w` by writing `width`. in your own example, you do it: you trigger rect by writing rectangle. if you're writing a comment explaining what your functions are doing or your line of thinking, you would trigger unwanted strings.
VernonGrant 路 2022-09-09 05:44
Yes, that's exactly what I was trying to say. But seeing all the up-votes made me think I was missing something 馃槄. But yes, `abbrev-mode` will not work for this type of functionality.
vifon 路 2022-09-09 08:54
> for example, you would trigger h by writing height and w by writing width. Doesn't `abbrev` trigger only after inserting a whitespace or a similar separator (comma etc.)?
_viz_ 路 2022-09-09 16:40
You don't write heightanotherword but height SPC another SPC word so height will be shortened to h.
eleven_cupfuls 路 2022-09-09 17:00
Yes, but abbrevs can be per-mode. And the same problem (comments vs. code) also applies to a shorter-to-longer translation, as I noted yesterday.
_viz_ 路 2022-09-09 17:37
One can make use of the :enable-function abbrev table property to take care of code vs. comments. I have one for org mode to prevent expansion of abbrevs in TeX blocks.