Re:Sorting in Emacs
by tom_ on Saturday August 12, 2023 @08:57AM
(#37099700)
Copy to clipboard, paste into your interactive Python window, and use as the argument to sorted. Copy and paste the interpreter's output back into your code.
[ Parent
| on HN ]
You technically described how to make a word sorting macro execute arbitrary code.
Fascinating to think how that doesn't mean it's bad advice. That is, unless your threat model includes targeted attacks by three-letter-scale adversaries — and then you maybe just don't open untrusted files in Emacs or use advice from strangers on HN.
That's a good point. My assumption, not that I ever stated it, was that the list would be one you'd typed out yourself, or was one that was just there in code already, and you could verify by eye that it's just string literals.
Using Python's eval with empty globals and locals dicts (consult the docs) could make this safer, though I've only ever had to use that for defending against accidents rather than malice. And now this quick thing is becoming increasingly complicated, and maybe you'd be better off engineering it properly.
This is actually a rather common thing to do.. I have functions that run shell commands in my spacemacs config to do things like this. For example I've got one that runs `date` to insert today's date in a particular format.
>Copy to clipboard, paste into your interactive Python window
python-shell-send-statement, it's built into Emacs's python mode.