Neovim + Lua + SLIMV: How to Start Swank Server in the Current Folder/Project?
Image by Fosca - hkhazo.biz.id

Neovim + Lua + SLIMV: How to Start Swank Server in the Current Folder/Project?

Posted on

Are you tired of using ancient Emacs with SLIME for your Lisp coding needs? Do you want to level up your development game with the power of Neovim, Lua, and SLIMV? Look no further! In this article, we’ll take you on a journey to start the Swank server in the current folder/project using Neovim, Lua, and SLIMV.

What is SLIMV?

SLIMV ( Superior Lisp Interaction Mode for Vim) is a Vim plugin that allows you to interact with Common Lisp (CL) and other Lisp dialects in a more efficient way. It provides features like code completion, debugging, and documentation lookup, making it an essential tool for any Lisp developer.

What is Swank?

Swank is a server that provides a communication channel between your Lisp environment and your editor (in this case, Neovim). It allows SLIMV to communicate with your Lisp process, enabling features like code completion, debugging, and more.

Setting up Neovim with Lua and SLIMV

Before we dive into starting the Swank server, make sure you have the following installed:

  • Neovim (version 0.5 or higher)
  • Lua (version 5.1 or higher)
  • SLIMV plugin for Neovim
  • A Common Lisp implementation (e.g., SBCL, CCL, or CLISP)

If you haven’t installed SLIMV yet, you can do so using your preferred package manager:

vim PlugInstall slimv

Alternatively, you can use vim’s built-in package manager:

vim -c 'packadd slimv' -c 'quit'

Starting the Swank Server

Now that we have our tools in place, let’s start the Swank server. There are two ways to do this:

Method 1: Using the SLIMV Command

Open your Neovim session and navigate to the directory where your Lisp project resides. Then, simply run the following command:

:SLIMV

This will start the Swank server and connect to it. You should see a message indicating that the server is running:

SLIMV: Connected to Swank server.

Method 2: Using a Lua Script

Create a new file in your project directory (e.g., `swank_init.lua`) with the following contents:

vim.cmd('SLIMV')
vim.cmd('LispStart')

Save the file and then run the following command in your Neovim session:

:luafile %:p:h/swank_init.lua

This will execute the Lua script, which in turn starts the Swank server and connects to it.

Verifying the Swank Server

After starting the Swank server, you can verify that it’s running by checking the Neovim status line or the SLIMV log:

:echo b:slimv_server

If everything is set up correctly, you should see a message indicating that the server is running:

b:slimv_server = {'host': 'localhost', 'port': 4005}

Troubleshooting Common Issues

If you encounter any issues while starting the Swank server, here are some common solutions:

Error Message Solution
SLIMV: Can’t connect to Swank server. Make sure you’re in the correct directory and the Swank server is running. Try restarting the server or checking the server logs for errors.
Lisp process not found. Ensure that you have a Lisp process running in the background. You can do this by running sbcl (or your preferred Lisp implementation) in a separate terminal.
Swank server not responding. Check the Swank server logs for errors. You can do this by running swank -l (or your preferred Swank server command) and checking the output.

Conclusion

Starting the Swank server in the current folder/project using Neovim, Lua, and SLIMV is a straightforward process. By following the steps outlined in this article, you’ll be well on your way to enjoying the power of SLIMV and taking your Lisp development to the next level. Happy coding!

Remember, if you encounter any issues or have further questions, feel free to ask in the comments below.

Happy coding, and don’t forget to :wq!

Frequently Asked Question

Get started with Neovim, Lua, and Slimv by learning how to start a Swank server in the current folder or project.

What is Swank, and why do I need it for Neovim and Slimv?

Swank is a server that allows your Neovim or Vim editor to communicate with external tools and plugins, such as Slimv, which provides Common Lisp development capabilities. You need Swank to enable features like code completion, debugging, and project navigation.

How do I start a Swank server in the current folder or project using Neovim and Lua?

You can start a Swank server using the following command in your Neovim Lua configuration file (~/.config/nvim/init.lua): require('slimv').start_swank({ startup_dir = vim.fn.getcwd() }). This will start the Swank server in the current working directory.

What if I want to start the Swank server in a specific project folder?

To start the Swank server in a specific project folder, simply specify the folder path as an argument to the start_swank function. For example: require('slimv').start_swank({ startup_dir = '/path/to/my/project' }). Replace /path/to/my/project with the desired folder path.

How do I know if the Swank server is running successfully?

Once you’ve started the Swank server, you should see a message indicating that the server is running and listening on a specific port (e.g., Swank server started on port 4567). You can also verify the server status by running the command :SlimvServerStatus in Neovim.

What if I encounter issues or errors when starting the Swank server?

If you encounter issues or errors when starting the Swank server, check the Neovim logs for errors or warnings. You can also try restarting the server or reinstalling the Slimv plugin. Additionally, consult the Slimv documentation and online forums for troubleshooting guidance and community support.

Leave a Reply

Your email address will not be published. Required fields are marked *