IDE/Editor for SWI-Prolog?

This is a really interesting thought.

XPCE allows for that. It is mostly PceEmacs that rebinds keys to follow the Emacs standard.

Thanks Jan and big thanks for SWI-Prolog. It is invaluable.

2 Likes

I am now using that editor and it’s very handy. Two questions:

  • Is there a dark mode for it (and for the SWI-Prolog REPL).
  • Is there a way to sort the predicate names in the navigator alphabetically? They appear to be in the order that they are found in the code, not alphabetically.

Thanks. I am finding it most convenient to use both Notepad++ and the SWI-Prolog editor in tandem. Notepad++ has my code templates and bookmarks. But I use the SWI-Prolog editor to set spy/break points (much more convenient than doing that from the REPL shell), and during tracing.

Great idea on using prolog_edit_command!.

What is CUA?

About CUA: an 80’s thing: Common User Access. See Wikipedia
Was a good Microsoft choice, to make Windows UX adhere to IBM proposal…
I’m grown with it, like some other billions, so cut/paste, file ops, etc are very mechanical duties for what I (or my fingers) cannot afford to remember another sequence. Then look to menus, take a mouse, click, search… very distracting, but in the end I’m using PceEMACS enough for my purpose.
I’m also a bit unlucky, since I know VI, I used it on Windows in first 80’s. EMACS was more used by Prolog community at the time, guess…

1 Like

The SWI-Prolog REPL comes in at least three flavours: just use a console, the Qt thing as (Mac) app and swipl-win.exe. For the first the theme is up to the console. I think in the others you can set the colors using the preferences. The biggest problem is that the colour scheme for both the console messages and syntax highlighting are designed for a light screen. Most of that is hookable, so a dark theme support can surely be implemented but it is a bit of work to make it all fit together. If someone wants to do the color design I could write up some docs to bring it all together.

The navigator cannot be sorted. The idea is to show the structure of the file, assuming the file is properly organized :slight_smile: To find a predicate, typically you use the right menu on a call. Or ?- edit(pred). from the console. There is also Emacs M-. (meta-dot) to find a predicate, but I see it no longer completes on TAB. Might be some bit-rot :frowning:

1 Like

I know it doesn’t rasterize primitives. But it - somewhat low level - solve presentation layer rather cleanly. When I google for electron node-x11, the first listed entry seems relevant to our use case.

About rendering, as I understand it, NodeJS Electron builds on Chromium, and there we have all the latest bells and whistles, also as portability, that is what we are most interested, since the graphic ‘finesse’ is admittedly a bit outdated :slight_smile: . In the end, I like that WASM is growing strong. Also studying a bit of Rust meanwhile. I must at least try to keep up-to-date with Mozilla contribute to programming languages architecture.

electron seems to make sense to reach at something similar to your Qt based console. Not sure where XPCE fits in in that case though. Are you mostly seeking a way to integrate the PceEmacs editor and the tracer seamlessly?

That would be great, but I was only trying to simplify the console+IDE architecture.
I should try to implement, but cannot right now…
Thanks

Just an update - thanks to @jamesnvc’s amazing work, basic features of LSP for Prolog now work with [Neo]Vim too: https://github.com/jamesnvc/lsp_server/issues/2#issuecomment-520075558

Some more work is required though:

It might be beneficial to make this LSP implementation officially supported by SWIPL: https://github.com/SWI-Prolog/swipl-devel/issues/389

2 Likes

Does anyone else use gedit?

I personally prefer text editors which are not too integrated with a particular language since I’m constantly hopping between SWI-Prolog, Javascript and Postgres’s server side scripting language PL/pgSQL (among others).

gedit actually has a nice Prolog highlighter (though it’s a bit hidden in that *.pl files default to Perl, so you have to go View->Highlight Mode…->Prolog, after which it remembers that file should be highlighted for Prolog syntax).

I used Atom a while back, which has quite nice Prolog support with both syntax highlighting and a lint. A reason I quit using Atom (besides that Gentoo Linux which I use refuses to install it) is that incorporating a lint into a text editor is awful design because you constantly get warning boxes popping-up telling you the half finished line you are busy typing unsurprisingly has syntax problems. (Presumably one could switch that off, but I think life too short to bother wading through documentation for bloatware like Atom).

A standalone lint for SWI-Prolog would be nice though, to check files for style issues after you have finished getting the code to run without syntax errors and basic bugs. Does anyone know of a good one?

I am going to take it that the question is asking for lint for Prolog.

In my initial response to this topic I noted Visual Studio Code as running on Windows. Visual Studio Code also runs on Linux.

There are also some add-on/plug-in/extension and a paticular one (VSC-Prolog) has a linter

The VSC-Prolog extension also gets in the way sometimes when I am writing a new module and can be frustrating, but with VSC it is possible to disable an extension with just a click. This does not uninstall the extension, but just disables it. It can also be enabled just as easily.

With VSC I also have multiple extensions for Prolog installed and can enable and disable them in combinations as needed. Some times I even use the disabling and enabling as part of a compile and test cycle because it is so easy and so fast.

1 Like

Load it into the built-in editor? Lots of external code that I load into PceEmacs show lots of issues colored orange or red. The only disadvantage is that you have to scroll through the whole file. Possibly it should print a summary of warnings and errors encountered in the status window and allow jumping through them.

If you don’t like PceEmacs, you can quite easily get the same by using the underlying library(prolog_colour) directly. You pass it an open stream to the data to analyze and it does callbacks with triples <start, end, class> where start and end indicate the character ranges and class is a Prolog term describing what it found there. Just pick the classes you want to know about and visualize the result as you wish.

If I understand Paulo correctly Logtalk has more high level warnings.

2 Likes

A good linter requires access to compilation context, which is not always readily available for standalone tools (without duplicating some of the compiler work). Thus, a linter tightly integrated with the compiler can more easily report potential issues. The downside is longer compilation times.

P.S. I assume that you’re aware of SWI-Prolog check/0 predicate? See also Edison’s xtools pack. A few other packs may also be useful.

2 Likes

A summary of those warnings (in the current stable version) can be found at:

The Logtalk linter is a top development priority. The git version already provides the additional check for lambda expressions that we briefly discussed recently (and that I expect to bring to library(yall) soon) and I’m working in some more lint checks.

In a good number of cases, it’s possible to compile a Prolog module as an object (by typing {file} instead of [file] at the top-level) to potentially benefit for the Logtalk linter. For plain Prolog code (i.e. not encapsulated in a module), wrapping it with object opening and closing directives (:- object(foo). and :- end_object.) may also do the trick.

In the long run, depending on securing the necessary resources, there’s a potential of convergence of some of the different resources discussed in this thread.

1 Like

I guess loading the file I want to lint into PceEmacs to check is as easy as some standalone command line tool.

I used to use Emacs decades ago, but have forgotten most of the shortcut keys. As I mentioned, gedit has become my favoured text editor, but my ideal would be something entirely browser based. I’ve played with nodemirror, which uses the codemirror library, but am not sure if it supports Prolog syntax highlighting.

Thanks Paulo for the tip about the check/0, I’d never heard of it before. (I’m very much in the “When in doubt, print it out” level of debugging, using format(…) a lot as I develop since I find’s trace, spy etc extremely confusing).

The Logtalk distribution includes support for CodeMirror in the directory:
https://github.com/LogtalkDotOrg/logtalk3/tree/master/coding/codemirror

It highlights standard Prolog constructs, including module constructs (besides Logtalk features).

1 Like