mixer.vim - (Classic) Vim plugin providing text objects and niceties for working with Mix projects

I’ve heard that if you’re not embarrassed by v1 of your product Vim plugin then you’ve released too late.

I’ve been sitting on this the past couple of months and while there is plenty I still have planned (a good amount of stuff is in the works just not in this version), I decided I should cut a release so the few people who will be interested can start using what’s available.

So, I’m happy to announce mixer.vim. Mixer is somewhat similar to elixir-tools.nvim only it’s written in vim9script so that Vim users can have nice Elixir things too. It assumes you have elixir.vim installed.

Here is the features section of the README for posterity:

Features

  • Text objects

    • ad/id - Any macro with a do block. Works on user-defined macros as well as keyword syntax (though the latter needs a little improvement).
    • aD - Like ad but include any assignment and/or attached comments (iD exists for convenience but is identical to id).
    • af/if - A function/macro definition
    • aF - Like af but include all heads, docs, annotations, attr and slot declarations, and even do_ prefixed versions (iF exists for convenience but is identical to if).
    • iS/aS- A sigil
    • im/am- A map or struct
    • iM/aM- A module
    • ic/ac- A comment or documentation
  • Conveniences

    • 'commentstring' is dynamically set in embedded HEEx/Surface.
    • matchit works in embedded HEEx/Surface templates.
    • Automatically sets :compiler if the appropriate plugin is found.
    • [experimental] Remaps ctrl-] in templates that will jump to a phx-hook definition (it’s pretty smart about it) or event handlers on other phx- attributes. Unfortunately this has a dependency on git-grep atm.
  • Commands

    • :Mix runs a mix command with autocomplete. Uses dispatch, neomake, asyncrun, or asyncdo if available.
    • :Deps doesn’t just wrap Mix deps but adds functionality like dynamically adding packages under your cursor (:Deps add floki, for example) or jumping to your deps
      function no matter what you’ve called it (:Deps with no args).
    • :Gen is a unified command for running gen tasks (with autocomplete!), eg:
      • :Gen migration add_name_to_users
      • :Gen live Accounts User users name:string age:integer
    • :IEx starts a :term window running iex. Within a mix project it will assume -S mix. Use :IEx! to get a plain session within a mix project.

:help mixer has more!

10 Likes

(replying here not to avoid fully necroing the old thread)

Lol, ya I hear ya. I’m annoyed at how long I put this off for myself. For me the text objects are the star of the show here even though they need some tweaking for keyword syntax. I find :Gen very useful as well since I seem to always type mix phx.gen.migration. Mix can be a bit finicky depending on if you use an async runner or not. I’m happy to discuss defaults and adding options and for any feedback/contributions in general of course!

There is quite a bit more coming than I’ve documented. I always get nervous before I make a repo public so I scrambled to ready it and missed some things. A lot of it is near ready just not quite polished enough for release.

Thank you for the effort! It’s very appreciated

1 Like

Just a lil’ update…

Once this plugin reaches beta I don’t plan on updating here anymore but for now you’re likely gonna be getting some semi-regular updates (whatever that means).

Here’s what’s different:

  • :Gen now does what you probably expected it should do from the start which is load all generated files into the quickfix list and auto-jump to the first entry. And of course :Gen! is available just in case you want don’t want to do any jumping and stay right where you are.

That’s it, really… unless, of course, you tried this plugin as soon as I posted it and learned that my cherry-picking fu was way off and I had neglected to include several features I claimed were there… anyway, that all that works now (probably).

The :IEx command now includes a hacky “connected REPL” or “Discount Connected REPL” as I like to call it. You could also say it’s a “We have connected REPLs at home” if you’re into that meme. I wouldn’t go so far as to say it’s the GoBots of connected REPLs because GoBots were cooler than this.

In short, you can start an iex session in a Vim :term and every time you save the buffer it will load the changes into the terminal. It even works with parts of a buffer via ranges/counts/visual selection.

In any event, it’s hard to describe so I made a short-ish screencast. It’s my first one ever so be nice if you choose to watch it… or don’t be nice, either is cool.

1 Like

I haven’t given an update on this project in a while so figured I’d share a newer thing. I’ve only been using it a week so it’s not super polished yet.

I’ve been playing around with htmx lately which means I’ve been using classic controllers for the first time in a while which finally gave me the push to implement the :R command. If you are unfamiliar, this is similar to rails.vim’s :R here for hopping to “related” files (and almost entirely different than projectionist’s idea of “related”).

In a nutshell:

  • Jump from controller to heex/template (context aware based cursor position) - this works whether you use dedicated heex files or components in the HTML module. Outside of a controller action it will jump to the HTML/view module
  • Jump to and from HEEx in a LiveView/Component/Hologram/Surface (this is implemented with the jumplist)
  • Jump from schema to context.
  • Jump from context to schema (context aware based on function name)—YMMV on this one as it uses some pretty hilarious brute forcing to find a file. Still tweaking it.
  • Jump between Router and Endpoint.
  • Go back one migration.
  • There are a few more places it works and more coming.

This is currently non-configurable since for all I know I’m the only one who uses this plugin.

I’ve also added some experimental (and so far undocumented) general Projectionist support (to try it out add let g:mixer_enable_projections = v:true to your vimrc). I’m still tweaking it but the big idea here is that it uses its own heuristics (not to be confused with projectionist’s codified heuristics) to determine your project’s layout and defines projections based on this. There is a lot of detail here so I won’t go into it but briefly:

  • Edomain - Edit a file in lib/my_app or lib/core.
  • Eweb - Edit a file in lib/my_app_web or lib/web.
  • Emigration - With no arguments will jump to the latest migration.
  • a whole host of others

I’m still working on this and I may end up implementing my own version as Projectionist isn’t too well suited for typical Phoenix project layouts (if there is indeed such a thing).

2 Likes