7 ms·
Ask HN: What code editors or IDEs are easily scriptable?
I want to build a deeper relationship with an editor or IDE that's designed to be extended or scripted.
I'd prefer to use an everyday-language I work in for scripting, which rules out Vimscript, Lua or Lisp. I'd be most happy with any of Ruby, Python, Go or Rust. Ideas?
- solardev 2y agoDo VScode and Jetbrains's plug-ins /extensions satisfy your scripting needs? They're in JS and Java, I think.
- compacct27 2y agoIn my experience, VS Code’s extension system really shines here. There are also boilerplate repos out there to get started.
- dualogy 2y ago> There are also boilerplate repos out there to get started. Should be unnecessary (and might be outdated unless meticulously maintained) IF one chooses to just follow the VSC API docs' `yo code` approach. Which generates the project structure with a simple hello `extension.ts` IIRC.
- aphantastic 2y agoThey are meticulously maintained, and far more comprehensive than yo code.
- chuckadams 2y agoFor Jetbrains IDEs, I recommend using LivePlugin rather than building a full-blown plugin for every script: https://github.com/dkandalov/live-plugin https://github.com/dkandalov/live-plugin
- brabel 2y agoThat's really awesome! As they support Groovy and Kotlin, they basically support most JVM languages too, so you can probably use this with Scala, Clojure etc. I may give it a spin myself as I am pretty heavy user of IntelliJ. By the way, I think Fleet, the new "Beta" editor by Jetbrains, is currently designing a custom plugin system to make it "nicer" to write plugins than for IntelliJ, but apparently it's not yet open for trials: https://www.jetbrains.com/help/fleet/managing-plugins.html https://www.jetbrains.com/help/fleet/managing-plugins.html
- add-sub-mul-div 2y ago"Scripts in languages such as Python, PHP and awk can now be used to edit documents": https://www.textpad.com/relnotes-textpad#v9050 https://www.textpad.com/relnotes-textpad#v9050
- Woshiwuja 2y agoSublime uses python if i remember correctly
- jvanderbot 2y agonvim has excellent lua scripting support.
- AJRF 2y agoOP said; "I'd prefer to use an everyday-language I work in for scripting, which rules out Vimscript, Lua or Lisp."
- jvanderbot 2y agoI'm a poor citizen of the internet today. Thanks for the callout, you're right.
- enricozb 2y agoKakoune _barely_ has a scripting language. It has essentially a set of commands and some basic string substitution, one of which will let you drop to a shell (something akin to substitute this string with the result of evaluating its contents through bash). With this you can write your scripts in whatever language you like. My plugins are almost all in Rust, some are in bash.
- Vegenoid 2y agoAnother vote for Kakoune. I think most people will find its approach a bit obtuse at first, but once it starts to click it’s pretty interesting. Maybe if you’re a seasoned terminal veteran it will make more sense to you right outta the gate. I started using Kakoune not long after I started using the terminal much more heavily, so it was a bit difficult at first, but it has been and continues to be rewarding. For example, select some text and press the pipe character, and then you can enter a script or shell command (sort, uniq, fmt, etc.). The selected text will be fed to stdin of the command, and then will be replaced with the output. Combine this power with multiselections, which can be operated on in separate contexts, and you’ve got a stew going.
- gaze 2y agoThe consequence of this is that kakoune forks for _everything_. In practice maybe this is fine but it seems wasteful
- deleted 2y ago[deleted]
- acedTrex 2y agoI mean as far as i know the only answer that fits your "no lua/lisp" requirement is intellij IDEs, they use java/kotlin.
- holowoodman 2y agoPlain old vim doesn't only do vimscript, you can also script it in Perl, Python, TCL, Lua and maybe one more I cannot remember. See e.g. this python howto: http://codeseekah.com/2012/03/04/vim-scripting-with-python-lookup-ip-country/ http://codeseekah.com/2012/03/04/vim-scripting-with-python-l...
- comex 2y agoAlso Ruby.
- mzs 2y agoalso the way you can use shell - hmmm I'd like all the build timestamps of my 6.4 bootroms... alright I'll put all the filenames in the buffer ls /tftp/bootroms/foobar/foobar_6.4_*.bin | gvim - I'll run an awk one-liner to print the filename and date seperated by a tab :%!awk '{ printf("\%s\t", $0); system("strings " $0 " | grep '\''20[0-2][0-9],'\''") }' I don't want that long path :1,$s:.*/:: I know, I'll sort them by build date :%!sort -r -k4 -k2M -k3n -k5 Oh yuck 4 space tabs don't do it :set ts=16 :set expandtab :retab
- ericb 2y agoThis is probably the most promising answer to me. > Plain old vim By this, do you mean this is only available in vim, not NeoVim?
- xk_id 2y agoNeoVim has additional scripting functionality over Vim actually, which is why some of their plugins aren’t compatible with Vim. So OP is referring to Vim over the likes of vscode, jetbrains etc
- 000ooo000 2y agoNeovim. You can use Lua, but you can also use your language of choice via msgpack. https://github.com/orgs/neovim/repositories?type=all&q=Client https://github.com/orgs/neovim/repositories?type=all&q=Clien...
- ashton314 2y agoOf the “preferred not” languages you listed, Lisp and Lisp-derivatives are easily the most pragmatic languages you will see doing “real” work outside of the scripting environment. So, given the dearth of good scriptable editors using other languages, why not give Emacs a try? I will grant that Elisp is a bit of an odd dialect, but a lot of what you learn from learning Elisp will transfer to understanding other languages better, modulo function names and whatnot. It’s also helpful that Elisp has comprehensive documentation available right from the editor itself. There are also hundreds of high-quality examples you can look at too, and Elisp lets to poke at basically every aspect of the editor.
- dwb 2y agoEmacs Lisp is my first Lisp, so I don't even really notice how supposedly weird it is. It's a fine language, don't let it get in your way, and it's just as important to be able to read other's code than it is to write your own. Unless you have all the time in the world, you want to use as much of other people's work as possible. Would I have preferred an editor written in Ruby? Sure. But I think I was right to not worry about that.
- ashton314 2y agoIndeed—most of the weirdness comes from things like dynamic scoping (deprecated, going away, good riddance—most of the packages I use have all switched to using lexical scoping anyway) and function names like `mapcar` instead of just `map`. But that's a trivial matter. Would I write a shell script in Emacs Lisp just for kicks? No. Is it more than good enough to script the crap out of my text editor? Oh yeah. > read other's code I'll second this: there are so many really good packages out there that it makes it easy to find something to get some pointers on how to proceed.
- pantsforbirds 2y agoZed is written in Rust: https://github.com/zed-industries/zed https://github.com/zed-industries/zed. It seems relatively straightforward to write an extension for it, but I've never personally tried (I suck at Rust). I will say that Lua is extremely easy to pick up, and as far as hacking on an IDE I think that simplicity might make it an ideal language.
- replete 2y agoI tried out Zed after reading this, super impressive and could overtake vscode in a year or two. Missing a few things like supporting editorconfig, but that's being worked on this week. Would switch immediately if it supported a few more things
- meiraleal 2y agonobody is going to take VSCode so soon. But I'm starting to feel the VSCode fatigue in the air. Kinda like with React. I was looking for another editor to use or maybe get back to emacs. Funny enough, as I have a lot of free time right now, I decided to code my own editor. It is very fun!
- weebull 2y agoWhat kind of things do you want to script? Personally I use macros in an editor for "text manipulation", and drop to Python/sed/awk for "text processing". I don't find I have a need for anything in-between.
- ericb 2y agoHere's an example of extending an IDE (IntelliJ/PyCharm/RubyMine/WebStorm) by driving it externally: I used just a little bit of code to make it so when I command-click a filepath anywhere, it opens in IntelliJ. This works in the browser, on chrome links, (github, gitlab, jenkins, error pages, etc) and also in iTerm on stack traces, spec/test paths. I made a chrome plugin, a shell script, and used the remote control plugin (not mine). The result was super-satisfying. I'll probably open source the bits soon. Now, I didn't script the IDE myself--the Remote Control Plugin did that work, but for an open source solution, I wouldn't mind building a remote control plugin myself. Making this work got me wondering about doing the same with an open-source editor. I also would like to drive things internally, but I want it to be easy so I get a good return on the effort.
- mzs 2y agoFor that you can just make the scripts 'gvim file' If on MacOS and you are using the apple native build, 'open -a gVim file' opens each file in the same editor. If you want to do that on X11 (even macos X11.app) or MS Windows: https://vimhelp.org/remote.txt.html#remote.txt https://vimhelp.org/remote.txt.html#remote.txt Basically (or gvim, yu might want --remote-silent too): vim --servername foo --remote-silent filename [ filename ... ] The end of that doc explain you can use either Windows messages or OLE. But the same doc explains how you can completely script vim from the command line: Tell the remote server "foo" to write all files and exit: vim --servername foo --remote-send '<C-\><C-N>:wqa<CR>' ^\^N is what you press on a keyboard to enter normal mode from every mode except ex mode without a beep. :wqa means do the command Write All and Quit. so with --remote-send you can send any sequence of key-strokes to act on buffers. You probably want to read from https://vimhelp.org/intro.txt.html#notation https://vimhelp.org/intro.txt.html#notation to learn the fundamentals. I'd avoid neovim initially until you learn enough to decided if you want it - pros and cons both ways.
- max_ 2y agoVSCode has a comprehensive API that you can create scripts for in Typescript
- dualogy 2y agoIt's pretty rad really: https://code.visualstudio.com/api/ https://code.visualstudio.com/api/ What I like about it is how it exposes pretty much all capabilities with no chance of breaking the editor host itself. Just the right balance of constrained-enough-but-seemingly-unconstrained. You can develop these extensions in JS/TS super-smoothly inside VSC and run-with-F5 to open a new window with your extension running. But frankly for small-script purposes, it's a bit overkill, unless/until you have enough of those that bundling them all up into one "my extension with all the Foos I demand" begins to make sense. Unfortunately local-only, private one-off extensions aren't installed as trivially as dumping just-a-script-file in some dot folder and calling it done. I mean it almost is with `~/.vscode/extensions/my-ext/` but not 100% reliable. I have 2 custom exts in there that are always available but 1 that inexplicably never is (but builds & runs error/warning-free with F5). The official installation story is a "vsx package" (probably just a ZIP but haven't looked into it yet).
- aphantastic 2y agoPerhaps try diffing the auto-generated output from installing the vsix via the official means vs your nonfunctional dev-repo?
- nosduco 2y agoThere are a variety of API clients written in various languages to configure and script Neovim including Ruby, Python, Go, and Rust. You can find an extensive list here: https://github.com/neovim/neovim/wiki/Related-projects#api-clients https://github.com/neovim/neovim/wiki/Related-projects#api-c...
- deleted 2y ago[deleted]
- emidln 2y agoIMO, the language is only a small part of a deeper relationship with your IDE. The IDE needs a good debugger, a good introspection system, and good hooks to modify things (ideally anything). Emacs meets this criteria, but few others do. This is why there is a living corpus of 40+ year old elisp that can be drawn upon for functionality and inspiration.
- jgoodhcg 2y agoAlso ChatGPT is pretty good at writing elisp.
- gnomewascool 2y agoSublime Text? (It's extendable in Python, but isn't FOSS, which might be a deal-breaker.)
- janoc 2y agoEmacs.
- janoc 2y agoEmacs
- WhereIsTheTruth 2y agoSublime Text could have been perfect, it uses python and it is hot-reloadable, but the API is limited, you can't extend the interface _at all_, want tabs in the build/task panel? nope, want to customize your status bar with clickeable elements? nope VSCode is a joke, you can't use javascript, worse, you need to compile your scripts, and you need to restart the editor whenever you change your "scripts"
- aphantastic 2y ago[flagged]
- aphantastic 2y ago> VSCode is a joke, you can't use javascript, worse, you need to compile your scripts, and you need to restart the editor whenever you change your "scripts" You can use Javascript, you don’t need to compile your scripts if you do you javascript, and you don’t need to restart the editor when you change your scripts. You do have to restart the extension host, but that’s not the same thing.
- dualogy 2y agoYou said no-Lua, but since for many interested in this thread Lua's a non-problem, I'll pitch a disconcertingly under-hyped / under-noticed native (aka non-Electron) editor with Lua extension story (and many of its parts built on that plus its small C core) called TextAdept. I'm still a happy camper on VSCode but if it ever begins to crumble/rot/overbloat (by subjective criteria), I'd hop onto that. Lua is (for my purposes here) no better/worse than JS/TS. Save for those darned 1-based array indexings! LSP-capable too, last I heard, else it'd be a non-option for me in 2024. https://orbitalquark.github.io/textadept/ https://orbitalquark.github.io/textadept/
- davidkunz 2y agoI wouldn't exclude Lua, it's a simple language whose basics you can learn pretty quickly if you know JavaScript or comparable languages. I therefore would recommend Neovim.
- rtcode_io 2y agohttps://RTCode.io https://RTCode.io is built on Monaco! It's incredibly easy to script! 0. Go to https://RTCode.io/x/ https://RTCode.io/x/ 1. Type a number 2. Select the number 3. Press ↑/↓ keys 3. Open the context menu (right click/long tap) 4. Mess with Selections: or Eval menu items Claude has helped with the selection actions! See https://diff.rt.ht https://diff.rt.ht which is also built on Monaco! For more advanced stuff visit: https://go.rt.ht https://go.rt.ht and select the Backend or PDF starters and hover over the attributes! Feel free to view the sources to see how I script it!
- lambdaba 2y agoYou shouldn't dismiss Lua outright, it's a language designed specifically for embedding, there's practically nothing to learn to begin using it productively. See this presentation by a core Neovim maintainer that explains why Lua was chosen https://www.youtube.com/watch?v=IP3J56sKtn0 https://www.youtube.com/watch?v=IP3J56sKtn0. See also http://lua-users.org/wiki/MechanismNotPolicy http://lua-users.org/wiki/MechanismNotPolicy to understand Lua's core design.
- somat 2y agoFor myself the attraction of the unix operating environment(aka the userland) is that now your operating system is your ide. Now admittedly this is never as sleek or uniform as an actual Integrated Development Environment, but the extensibility, well the extensibility is unmatched. you can even have an ide in your ide.
- _benj 2y agoTo add a few less popular options, I really liked working with TextAdept. Almost the whole API is accessible via Lua and you can script the heck out of that editor. The challenge with that is that you don't get a lot of items out of the box. The community is awesome though and the author of the project is very responsive in github. There's also Lite XL, which is also a very hackable editor. Also hackable in Lua. The documentation for it is a bit lacking but one can jump into the code and start tweaking things in it. There's also micro. This one also uses Lua for writing plugins and such. It's a terminal editor if that's something you are interested in.
- Teknomancer 2y agoEmacs ≥ VIM ≥ Neovim Started on Emacs because that was what Prof required, after leaving school with a BS in CS, switched to VIM, years afterwards found a comfy place in Neovim managed in NixOS via Flakes & Home-Manager. A purely scriptable and declarative setup that can be reproduced on nearly any machine one might wish to work on. Scriptable interaction with Language Servers, Linters, Formatters and Debuggers in any language that is needed for work or fun (C, C++, Go, JavaScript, Lua, Python, Ruby, Rust, etc.) Highly recommend.
- sunir 2y agoAre your signs backwards?
- _benj 2y agoadding a few fun ones that I've used in the past: TextAdept. The API is fully open to Lua and a bunch of stuff can be scripted in it. The author is super responsive on github and has a nice small welcoming community. Lite XL is mostly written in Lua, less documentation than TextAdept but is not terribly hard to jump into the code and figure out how the editor works and modify it. Micro uses Lua for plugins. It's a terminal only editor, which is a plus for some people, but still the mouse support is quite nice.
- cultofmetatron 2y agoemacs is basicly a lisp machine running a descent text editor on top of it. you can't get much more scriptable than that.
- hollerith 2y ago"Lisp machine" means a CPU or a computer specialized for running Lisp (which stopped being made in the 1980s or 1990s). You mean "a Lisp implementation" or "a Lisp language processor".
- david1542 2y agoDefinitely VS Code. I’ve created 3 extensions and I really like it.
- david1542 2y agoDefinitely VS Code is my favourite. I’ve created so far 3 extensions. I really like the SDK and the way you can control every aspect of the IDE.
- alrenai 2y agoThe 'custom css and js loader' extension for vscode is pretty good. since most of the editor is rendered with HTML you can pretty much do anything you want, pairs nicely with the built-in dev console and easier/quicker to iterate than doing things the 'proper way' via extensions/api.
- bloopernova 2y agoEmacs, as has been mentioned multiple times in this thread, but I wanted to share a bit more about why. Emacs is a text manipulation environment, and it's incredibly powerful to be able to run any elisp code. In org-mode, I use plain lists and checkboxes often, and after inserting the checkbox, I always need to move my cursor 2 spaces to the right. Well, with Emacs and elisp, I can do that: (defun my-org-toggle-checkbox-and-move-right () "Toggle checkbox and move cursor 2 spaces to the right." (interactive) (org-toggle-checkbox) (forward-char 2)) ;; Bind the function to a key if desired ;; (global-set-key (kbd "C-c t") 'my-org-toggle-checkbox-and-move-right) Other examples: https://www.reddit.com/r/emacs/comments/1bgyq3y/wrote_my_first_function/ https://www.reddit.com/r/emacs/comments/1bgyq3y/wrote_my_fir... or https://blog.thomasheartman.com/posts/my-first-emacs-lisp https://blog.thomasheartman.com/posts/my-first-emacs-lisp or https://emacs.stackexchange.com/questions/54602/how-do-i-define-a-function-to-execute-as-a-command-with-m-x https://emacs.stackexchange.com/questions/54602/how-do-i-def... And of course, because your config is text/code you can version control it, which allows rollbacks if you make a mistake ;)
- CarpeQueso 2y agoSome people live in their editor and occasionally drop into a shell. I've personally found a lot less friction in doing the opposite. Live in the shell, and occasionally drop into your editor. I used to think that it would be better to have a lot of scripting and automation built into my editor, but there are so many well-built, connect-able tools already available in a unix shell that it's usually easier to write scripts in that context, instead. There are often easy ways to pull the outputs of those scripts into your editor or use your editor as a thin, pass-thru layer to run shell scripts on certain selected bits of text in a file.
- PeterWhittaker 2y agoThis is mostly how I work as well, and has the advantage that when I need to poke around on servers and appliances on which I do not have my vim setup, I can still use a lot of my regular “tricks” because they are shell-based. Sure, sure, I do miss tpope’s surround and repeat plugins, but I have shell muscle memory and am happy(ish). IMHO, of course, YMMV. :-)
- eikenberry 2y ago+1 .. Came to say the same thing. My favorite IDE is the Unix shell. Multiple great editors to pick from, multiple and very flexible ways to hook all your tools together. Easy to use on remote systems. All of it free software.
- markhahn 2y agoI'm curious about the implications of "deeper relationship".
- rjzzleep 2y agoThe team that built Neovim was actually very focused on python extensibility before they went for Lua IIRC, so the neovim python library works very well I think. https://pynvim.readthedocs.io/en/latest/ https://pynvim.readthedocs.io/en/latest/
- Ancapistani 2y agoI'll echo others' comments that you should consider not completely ruling out Lua. I'm a Neovim user almost exclusively, and knew no Lua at all coming in to it. In less than a day I was up to speed enough to be able to write complex extensions in it, and honestly didn't struggle much with the language itself in getting to that point. Most of my time was spent learning the APIs, not the language. That said, while I've not done so, it _is_ possible to write Neovim extensions in Python. Check out this project for details: https://github.com/neovim/pynvim https://github.com/neovim/pynvim While there are obviously many editors out there these days, IMO the ubiquity of [n]vim and emacs make them strong leaders. Convincing me to use anything else would be difficult. I love Neovim, and it fits my needs well - but my choosing it over emacs was largely arbitrary. Now I'm in a position where I understand Neovim very well but lack that knowledge of emacs. As far as I know they're on par with each other.
- mike_hearn 2y agoWell, every IDE is designed to be extended. Unfortunately neither Go nor Rust are really intended for the extension use case. Sublime Text supports Python scripting but isn't an IDE. I think the best IDE scripting experience I know of right now is IntelliJ (or other Jetbrains IDEs) with the Live Plugin extension. You can write simple scripts in Kotlin or Groovy. They're similar langs but the latter is dynamically typed. And then you can just do things like register menu items, explore the language AST, edit buffers, trigger refactorings, access remote machines. Anything, really. As your script gets too big, you just convert it to a 'real' plugin project with multiple files, can use libraries, etc. Then you can upload it to the Marketplace so people can find it. And if your plugin ends up being really good, Jetbrains run a monetization system so you can sell it easily. They handle all the billing, tax, licensing etc for you, so you can focus on your plugin. It's pretty rad. That said, in years of working with IntelliJ I never felt a need to extend it for my own personal use. It's not like emacs where every user ends up with piles of elisp. The defaults are pretty good, and many features where in other IDEs you'd be forced to write a script can be done entirely via the GUI. For example if you want to define templates that auto-expand and where the cursor moves between 'slots', you can do that using a mini templating language without needing to do any coding. There's a thing called Structural Search & Replace which is similar - it lets you create templates that match against ASTs and do transforms on them.