Skip to content

gav451/oglot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Org source blocks with Eglot

Goal with brief technical overview

Oglot (Org source blocks with Eglot) builds on the idea of the post Using Rustic, Eglot, and Org-Babel for literate programming with LSP support in Emacs to facititate the analyis of Org source code blocks with LSP servers. This requires installing suitable LSP servers and tangling of the Org source blocks. Note: Rustic supports Rust Org source blocks by means of rustic-babel.

Oglot tries to locate an Org source block in a tangled file when calling org-edit-src-code. In case of success, it visits the tangled file in the org-src-mode buffer and narrows the buffer to the block before launching Eglot on the tangled file. Oglot ensures also to delete the invisible regions outside the narrowed block before calling org-edit-src-exit or org-edit-src-save.

Oglot works well with python-lsp-ruff and Python, but it should also work with other languages and servers: add your language to oglot-maybe-ensure-modes and define an org-babel-edit-prep:<LANGUAGE> function similar to org-babel-edit-prep:python using oglot-org-babel-edit-prep.

Oglot works with eglot-jl and LanguageServer.jl. In my opinion, the server startup time is too long for small snippets.

Oglot also allows to control tangling: synchronizing an Org file with a tangled file works best after tangling the Org file with the header arguments property “:comments link”. Toggling this property allows to use those comments for internal use and to hide those comments for external use (by means of e.g. oglot-python-comments-link-toggle).

To use Org source blocks with Eglot for julia-mode, lua-mode, python-mode, and ruby-mode source blocks, execute the following source block:

(when (and (package-installed-p 'oglot)
           (require 'oglot nil 'noerror))
  ;; Ensure to understand all caveats.
  (setopt oglot-maybe-ensure-modes
          '(julia-mode lua-mode python-mode ruby-mode)))

Note that only python-mode works for sure, and that julia-mode works but has rough edges and that the status of lua-mode and ruby-mode is unsure.

The file pyproject.toml is an example how to configure the hints that ruff will emit. The file rpasycnio.org is a practical example that should also work with python-lsp without the python-lsp-ruff plugin. The file julia-mandelbrot.org is an eglot-jl example.

Note: The org-src-context library facilitates the analysis of Org source blocks with eglot as well as lsp-mode.

Installation

To install the whole git repository in src_emacs-lisp{(file-name-concat package-user-dir “oglot”)} {{{results(~/.emacs.d/elpa/oglot)}}} execute the source block below:

(package-vc-install '(oglot :url "https://github.com/gav451/oglot.git"))

This requires at least Emacs-29.1. Another method is to clone this repository locally to visit the file oglot.el and invoke package-install-from-buffer.

About

Org source blocks with Eglot

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published