-
Notifications
You must be signed in to change notification settings - Fork 19
Add blog post: Setting up JabRef's LSP Server with Emacs #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dea277c
2b1ebfd
b455c2d
46307f7
5f7c199
3d68577
12a80a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| --- | ||
| title: Setting up JabRef's LSP Server with Emacs | ||
| tags: [jabref, emacs, lsp, macos, tutorial] | ||
| author: Ayush Kumar Singh | ||
|
Techvian marked this conversation as resolved.
|
||
| --- | ||
|
|
||
| Hello! I'm Ayush, a student pursuing B.Tech in AI & Data Science Engineering at Guru Gobind Singh Indraprastha University, Delhi, India. In this blog, I share my experience documenting the setup of Emacs with JabRef’s LSP server during an open-source contribution. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to the end No --- in human written md files |
||
|
|
||
| --- | ||
|
|
||
| ## What's happening here | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a good heading. "Overview" or "Two methods to use the LSP feature" |
||
|
|
||
| JabRef has a built-in LSP server called [**JabLS**](https://github.com/JabRef/jabref/tree/main/.jbang). You run it in the background, connect Emacs to it via `eglot`, and you get autocomplete, diagnostics, and more when editing `.bib` files. | ||
|
|
||
| There are two ways to get the LSP server running - using `jbang`, or using the development build of JabRef which lets you enable LSP directly from Preference. I tested the `jbang` approach personally, so that's what this guide covers in detail. The macOS steps here should also be relatively easy to adapt for Linux and Windows. | ||
|
|
||
| --- | ||
|
|
||
| ## What you need | ||
|
|
||
| - macOS (tested on Apple M2) | ||
| - Homebrew (package manager for macOS) | ||
| - Emacs 29 or later | ||
| - Jbang | ||
| - Basic comfort with Terminal | ||
|
|
||
| --- | ||
|
|
||
| ## Method 1 - Using jbang | ||
|
|
||
| ### Step 1 - Install Emacs | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Either refocus the the blog entry for any (!) editor able to talk LSP or focus on emacs. And then users have emacs installed!!!! |
||
|
|
||
| ```bash | ||
| brew install --cask emacs | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
| Verify it's working: | ||
|
|
||
| ```bash | ||
| emacs --version | ||
| ``` | ||
|
|
||
| It will show that `GNU Emacs 30.2`. | ||
|
|
||
| ### Step 2 - Install jbang | ||
|
|
||
| [jbang](https://www.jbang.dev) is a tool for running Java apps without a full build setup. JabLS uses it. | ||
|
|
||
| ```bash | ||
| brew install jbangdev/tap/jbang | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
| Then trust the JabRef source: | ||
|
|
||
| ```bash | ||
| jbang trust add https://github.com/JabRef/jabref/ | ||
| ``` | ||
|
|
||
| When prompted, type `2` to trust the JabRef repository permanently. | ||
|
|
||
| ### Step 3 - Start the JabLS server | ||
|
|
||
| Open a Terminal window and run: | ||
|
|
||
| ```bash | ||
| jbang jabls@jabref | ||
| ``` | ||
|
|
||
| The first time, it downloads some dependencies. wait for it - when you see this line, the server is ready: | ||
|
|
||
| ``` | ||
| INFO: LSP Server listening on port 2087... | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
| > **Important** Keep this Terminal window open. The LSP server needs to stay running while you edit `.bib` files in Emacs. | ||
|
|
||
| ### Step 4 - Configure Emacs | ||
|
|
||
| Open your Emacs config file with `Ctrl + X` then `Ctrl + F`, type `~/.emacs.d/init.el` and press Enter. | ||
|
|
||
| Add this Config: | ||
|
|
||
| ```elisp | ||
| (require 'package) | ||
| (add-to-list 'package-archives | ||
| '("melpa" . "https://melpa.org/packages/") t) | ||
| (package-initialize) | ||
|
|
||
| (require 'eglot) | ||
|
|
||
| (add-to-list 'eglot-server-programs | ||
| `(bibtex-mode . ("localhost" 2087))) | ||
|
|
||
| (add-hook 'bibtex-mode-hook 'eglot-ensure) | ||
| ``` | ||
|
|
||
| Use `Ctrl + X` then `Ctrl + S` for save the file. | ||
|
|
||
| > **Note:** We use `eglot` here because it ships built-in with Emacs 29+ and connects to JabLS cleanly over TCP. No extra packages needed. | ||
|
|
||
| ### Step 5 - Test it | ||
|
|
||
| Open it in Emacs: | ||
|
|
||
| ```bash | ||
| emacs ~/Desktop/Chocolate.bib | ||
| ``` | ||
|
|
||
| You should see `[eglot:~]` appear in the mode line at the bottom - that means Emacs is connected to JabLS. | ||
|
|
||
|  | ||
|
|
||
| --- | ||
|
|
||
| ## Method 2 - Using JabRef's development build (alternative) | ||
|
|
||
| If you'd rather not use `Jbang`, the development build of JabRef includes an option to enable the LSP server directly from JabRef's **Preferences** - no extra tools needed. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. If one uses rhe JabRef graphical application. Also outline the choices in the intro |
||
|
|
||
| Download the latest development build for your platform from: | ||
|
|
||
| **https://builds.jabref.org/main/** | ||
|
|
||
| Pick the right folder for your system: | ||
| - `macOS-silicon` — Apple M2/M3 | ||
| - `macOS-intel` — older Intel Macs | ||
| - `linux-amd64` — Linux | ||
| - `windows-amd64` — Windows | ||
|
|
||
| Once installed, open JabRef --> go to **Preferences** --> look for the **LSP server** option and enable it. The server will start automatically when JabRef is open, and you can connect Emacs to it using the same `eglot` config from step 4 above. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Detail step. Screenshot. |
||
|
|
||
| --- | ||
|
|
||
| ## Every time you use it (Jbang method) | ||
|
|
||
| JabLS doesn't start automatically - start it before opening Emacs: | ||
|
|
||
| ```bash | ||
| # Termainal 1 - Keep open | ||
| jbang jabls@jabref | ||
|
|
||
| # Terminal 2 - open your file | ||
| emacs yourfile.bib | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| **Eglot not connecting** | ||
| Make sure the JabLS server is running and showing `listening on port 2087` before opening Emacs. | ||
|
|
||
| **No completions appearing** | ||
| Make sure your cursor is inside a BibTex field value, not on the citation key. Press `Ctrl + Alt + i` to trigger completions manually. | ||
|
|
||
| --- | ||
|
|
||
| ## Wrapping up | ||
|
|
||
| The trickiest part was figuring out that [JabLS](https://github.com/JabRef/jabref/tree/main/.jbang) is the correct server to use, and that `eglot` connects to it more cleanly than `lsp-mode` for this use case. Once those two things clicked, the rest was straightforward. | ||
|
|
||
| If you run into anything unexpected, the [JabRef issue tracker](https://github.com/JabRef/jabref/issues) is active and the maintainers respond quickly. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.