vikigenius · 2022-08-25 02:42
Consider I have the following lines
pub net_current_desktop => b"_NET_CURRENT_DESKTOP",
pub net_desktop_names => b"_NET_DESKTOP_NAMES",
pub net_active_window => b"_NET_ACTIVE_WINDOW",
Now I have many more lines that are like this that I want to type. Currently I just paste the previous line and do a Query Replace. But this is inefficient because the pattern is that only the part after the `net_` changes and it is common on both sides (except for capitalization).
Is there some workflow where I can define some temporary elisp code, then call it with just the suffix, and it automatically generates the next line (with the proper indent and everything).
For example:
Some Keybind + workarea
Should generate
pub net_workarea => b"_NET_WORKAREA",
I know that by the time somone points me in the right direction and I figure it out I could just manually write it :)
But I would like to take this opportunity to learn if there is an efficient way of doing this.
lynnuxcn · 2022-08-25 03:18
you can try [https://github.com/abo-abo/auto-yasnippet](https://github.com/abo-abo/auto-yasnippet)
NDcodes · 2022-08-25 03:34
I would look into using the insert function, which does exactly that: inserts its argument string into the buffer at point.
So you can write a function that takes in a string, turns it into all caps, then appends it to your “common” string, and then calls the insert function with the resulting string as the argument (edit: I didn’t realize your resulting string is slightly more complex than that, but you should still be able to construct it given the argument and the common parts).
I haven’t looked into each of these steps specifically so let me know if you encounter some issues or if my explanation isn’t clear
JohnathanDee · 2022-08-25 04:25
Hmmm... Maybe [yasnippet](https://github.com/joaotavora/yasnippet)?
It's pretty powerful, with tabbing between placeholders, mirroring and transforming.
You can then type the snippet key, like `pub-net` and then `C-<tab>` to expand the snippet, type and have it capitalized and mirrored ... ?
7890yuiop · 2022-08-25 07:06
Sure, it's easy to transform only the variable text into the desired end result.
current_desktop
desktop_names
active_window
Option 1: Keyboard macros.
* `workarea`
* `<f3> C-a C-k`
* `pub net_`
* `C-y`
* ` => b"_NET_`
* `C-y C-x C-u`
* `",`
* `RET <f4>`
then:
* `foo<f4>`
* `bar<f4>`
Or if you have the whole list entered in advance, then omit the final `RET` from the recording (you can use `C-x C-k e` to edit the macro and remove it), and then mark that region and use:
* `C-x C-k r`
Option 2: regexp search and replace:
`.*` => `pub net_\& => b"_NET_\,(upcase \&)",`
akirakom · 2022-08-26 06:10
This is the best for temporary micro snippeting.An alternative is minad's tempel