Recent

Author Topic: Tree-sitter mode for Emacs  (Read 2362 times)

bolsen

  • New Member
  • *
  • Posts: 11
Tree-sitter mode for Emacs
« on: July 26, 2025, 01:23:40 pm »
Hi,

I have been learning Pascal for a little while as a hobby. Lazarus is OK, but I am used to Emacs. I gotten to a point where I feel comfortable using it (LSP, highlighting and other creature comforts), but I suppose there is some work to be done (or there is work that I need to do!)

However: The opascal-mode that comes with Emacs is OK for indenting (for now) but the syntax highlighting, at least out of the box, didn't look good for me. I thought I would try a tree-sitter mode, but couldn't find anything at all that uses the existing tree-sitter parser (https://github.com/Isopod/tree-sitter-pascal) (forgive me if I missed something.) So I started something: https://github.com/bolsen/pascal-ts-mode.git . After a few hours poking at it, code looks nicer in Emacs. :)

I hope this is useful for others.

Brian

d2010

  • Full Member
  • ***
  • Posts: 230
Re: Tree-sitter mode for Emacs
« Reply #1 on: July 27, 2025, 07:57:25 am »
Hi,
I have been learning Pascal for a little while as a hobby. Lazarus is OK, but I am used to Emacs. I gotten to a point where I feel comfortable using it (LSP, highlighting and other creature comforts), but I suppose there is some work to be done (or there is work that I need to do!)
Brian
Can You, anyone share to a public,  many many demos with EmacS'Pascal?
I have a few experienced with "clone-Pascal", I am happy to test and EmacsPascaL.
But I need a downloading one big .zip with full Emacs-with-Demos.zip"
(e.g Portable.zip from sourceforge.com)
 %)

bolsen

  • New Member
  • *
  • Posts: 11
Re: Tree-sitter mode for Emacs
« Reply #2 on: August 09, 2025, 03:34:05 pm »
Can You, anyone share to a public,  many many demos with EmacS'Pascal?
I have a few experienced with "clone-Pascal", I am happy to test and EmacsPascaL.
But I need a downloading one big .zip with full Emacs-with-Demos.zip"
(e.g Portable.zip from sourceforge.com)
 %)

Maybe some day.

I have setup now is using github.com/genericptr/pascal-language-server for LSP support. That is not complete, but it is the best one I found so far (also I see there are issues raised that prevent building on the master/main branch.) I use Lazarus right now for debugging and setting up projects, but use lazbuild via `M-x compile` in Emacs otherwise.Anything Pascal through Emacs was not a plug-and-play experience for me like other programming languages, but there is something decent now.

This is also critical to using lazbuild in Emacs compilation-mode:

Code: Pascal  [Select][+][-]
  1. (add-to-list 'compilation-error-regexp-alist 'fpc)
  2. (add-to-list 'compilation-error-regexp-alist-alist
  3.             '(fpc "^\\(.+\\)(\\([0-9]+\\),\\([0-9]+\\)) \\(.+\\):.+" 1 2 3 (4)))

Ideally, a lot of workflows can be done with smashing 3rd-party tools together, but Lazarus still has its place (and something to lean on to implement those cmd line tools, I guess :) )
« Last Edit: August 09, 2025, 03:37:19 pm by bolsen »

bolsen

  • New Member
  • *
  • Posts: 11
Re: Tree-sitter mode for Emacs
« Reply #3 on: August 27, 2025, 05:06:54 pm »
I added a bit more that I find useful :
1. Use M-x compile (like I said in my last post)
2. A flycheck checker for getting errors in source. With lsp-ui, it looks really nice :)  It uses `fpc` to get syntax. From my view, the time it takes to boot the compiler from a cold start takes the most time, so this is probably something to eventually tweak.

In some time, I will integrate a better lsp client, which supports https://github.com/genericptr/pascal-language-server better (this mostly completes the stack for me and have been using it for awhile. With flycheck showing syntax errors, it makes the experience with the lsp server better.)

AlexK

  • Full Member
  • ***
  • Posts: 101
Re: Tree-sitter mode for Emacs
« Reply #4 on: September 07, 2025, 11:56:08 pm »

I have setup now is using github.com/genericptr/pascal-language-server for LSP support. That is not complete, but it is the best one I found so far (also I see there are issues raised that prevent building on the master/main branch.)

Opascal has lsp now. Those build instructions, though.

I'm gonna explore modern ctags potential..

bolsen

  • New Member
  • *
  • Posts: 11
Re: Tree-sitter mode for Emacs
« Reply #5 on: September 09, 2025, 07:59:39 pm »
Opascal has lsp now. Those build instructions, though.

I'm gonna explore modern ctags potential..

Yeah, the lsp server is also slightly broken (edit: to be fair: not "broken", but as it is described in the repo, incomplete.) I had to fix things, but I have to revisit it if it is worth doing a pull request.
« Last Edit: September 14, 2025, 10:58:38 am by bolsen »

 

TinyPortal © 2005-2018