Questions about IDE themes

I’ve included a theme for the SWI-Prolog IDE to my project. The new theme is based on library(theme/dark) and it can be found here:

I’m trying to understand how I can change the background colour of highlighted variables in the SWI-Prolog IDE. To clarify, I mean the highlighting that appears when I place the cursor on a variable: all variables unifying with it in the same clause are highlighted with a new background colour. See the image below for an example.

swi_highlight

As can be seen in the image above, the cyan background of the highlighting makes the variables’ text hard to read in combination with the orange colour of variables in my theme.

How can I change the colour of that highlight?

A separate question. To create my theme I simply copied library(theme/dark) into a new file and changed the new file, but this way I also copied the header with the original author’s name. What’s the right way to preserve the name of the original author of library(theme/dark), while not making it look like my own theme was written by the same person? That’s to avoid embarrasment to the original author, obviously.

Btw, thanks for naming the theme after one of my favourite TV series, that can’t be a coincidence :stuck_out_tongue:

A little search in prolog_mode.pl shows it uses a class variable varmark_style defined on class emacs_prolog_mode. In the dark mode file, this is handled using pce_style/2. So, I
think you need something like this:

pce_style(emacs_prolog_mode, 
          [ varmark_style(style(background := purple,
                                    underline := true))
          ]).

I think the usual practice is to copy the file, add yourself as second author and state in the comment that this is a modified version of < point at original > If the modifications are not substantial you typically do not add yourself as author and just add a comment that you modified the file in such and such way.

Thanks Jan. I don’t know what prolog_mode.pl is and I don’t know anything about XPCE. Would it be useful to have the option controlling this background colour accessible through library(theme) files, instead?

The changes I made are not substantial and the file I copied is essentially a configuration file so I don’t think I need to add myself as an author. I already have comments documenting the changes I made in themes/dork, but I’ll add a note saying where the file was copied from originally.

Sorry, I see you meant pce_style, not pce_type, so I can add that directly in the theme file. Thanks! I thought I had to edit prolog_mode.pl (since pce_type is not in the theme file- but then noticed it’s not in prolog_mode either).

1 Like

As a side node, I wrote the dark theme long ago as a quick hack. Most likely the theme is pretty bad from a color palette point of view. My eyes can’t handle dark themes …

So, if your theme makes more sense than the original, I’m happy to replace the original or add this theme to the core distribution and make it the default dark theme.

That’s perfectly fine by me, as long as nobody else thinks my theme is an eyesore.

Btw, the correct syntax seems to be like this:

pce_style(emacs_prolog_mode,
          [ varmark_style(style(background := grey30,
                     underline := true))
          ]).

Note the boolean.

I can’t find how to change the foreground colour, though. This kind of thing is simply ignored:

pce_style(emacs_prolog_mode,
          [ varmark_style(style(background := grey30,
                                colour = yellow,
                                underline := true))
          ]).

Thanks. Modifying the xpce styles through Prolog is somewhat hacky :frowning:

Should be colour := yellow. Might still have no effect as there is also the highlighting from the variable. I don’t recall the disambiguation rules.

Thanks - I can’t get that to work either.

Never mind, it’s not important. I can live with a grey background with underlining. That should be fine.

What would you like me to do? Make a pull request with the new dark theme?

I guess we have two options. Ask people whether they think this theme is better first or simply add it to the distribution and see how people react.

Who is using the dark theme and are there people willing to evaluate @stassa.p’s version?

1 Like

Nobody I guess :slight_smile:

I’m the opposite from you: I have to use a dark theme in everything because bright light hurts my eyes :confused:

1 Like

I prefer dark themes as well. At the moment I usually use Visual Studio Code and not the built-in editor, but I did in the past, and maybe I could reuse it in the future, so I think it would be nice if your dark theme option could be available to users. It didn’t look bad from the preview-screenshot that you posted here

1 Like

I’m tempted to simply add @stassa.p’s theme to the theme directory and leave it to the user to decide :slight_smile:

Great! But I was trying to find how to change the style of arithmetic functions because they’re blue-on-black and that’s not very readable:

functions

Any idea? I think everything else is probably OK to read (disregarding the awful taste).

EDIT: I’m looking in prolog_mode, but not finding anything. I’m kind of lost in there to be honest :confused:

You need to look into library(prolog_colour). There you find colourise_expression/3, which calls colour_item(function, TB, FF-FT) or colour_item(no_function, TB, FF-FT) for known/unknown functions. And at the end of the file we find

def_style(function,                [colour(blue)]).
def_style(no_function,             [colour(red)]).

Redefining works like all the other things. They are not defined in the dark theme either. I should fix that (done; i’ll commit in a sec).

1 Like

You probably just need to define a style rule for function fragments, does that work?

Yup, it’s best to try maintaining a contrast ratio of at least 4.5 between the foreground and background colors (Web Content Accessibility Guidelines (WCAG) 2.1), although that’s sometimes easier said than done :slight_smile:

2 Likes

Aha, that’s where they all are :0

OK, here’s a screenshot with a good spread of different types of syntax in case anyone wants to chip in some ideas:

I’ll update my repository in a sec, then feel free to add the dork theme to the official SWI themes. I chose the name very carefully :stuck_out_tongue:

EDIT: Done. Now we can all go back to taking over the world with logic-based AI <3

Nice! There are a whole lot more colors though. I tried to write some code that illustrates most of them. This only covers the core though and is probably incomplete. Libraries may define additional style. Some with extensive style support are library(http/html_write) and library(chr).

Code
:- module(colour_demo,                  % module name
          [ colour_demo/2,              % defined export
            no_colour_demo/2,           % undefined export
            op(500, fx, &&)             % exported operator
          ]).
:- use_module(library(record)).         % existing library, used
:- use_module(library(utf8)).           % existing library, not used
:- use_module(no_such_file).            % non-existing library

/** <module> Show PceEmacs colors for all syntactic elements

This code does not run. It is just to show syntax highlighting elements.
*/

%!  colour_demo(+In, -Out) is det.
%
%   Very simple demo clause trying to show as many as possible colors.

colour_demo(In, Out) :-                 % exported predicate
    must_be(atom, In),                  % autoloaded
    some_module:some_pred(SingleTon),   % qualified call, singleton
    var(Out),                           % built-in
    not_defined,                        % call to undefined predicate
    format('From ~w~n', [In]),          % Quoted atom
    current_prolog_flag(bounded, _),    % existing flag
    current_prolog_flag(no_flag, _),    % non-existing flag
    Out is sin(1r3) +                   % function, rational
           nofunc(42) *                 % undefined function, integer
           exp(2.7),                    % function, float
    p,                                  % call to local predicate
    open(In, read, Stream,
         [ type(binary),                % ok option
           type(error),                 % illegal value
           nooption(value)              % no such option
         ]).

p :-                                    % local predicate
    q,
    p.                                  % recursive call

ssu(Head),
  var(Head) =>                          % SSU guard, SSH neck
    Head = 42.

dcg(Head), [A] --> [A], more(Head).     % DCG push back, DCG neck

not_called.                             % not called predicate

:- record
    point(x:integer,
          y:integer).

:- multifile
    prolog:message//1.                  % known hook

prolog:message(something(X)) -->
    [ 'Just some message: ~p'-[X] ].

1 Like

Oh, that’s nice! That could hopefully help others create their own themes also.

Another option is to look at popular themes for other editors and convert them to SWI themes. For example, I’ve seen a theme called “solarized” in pretty much every IDE I’ve worked with. I bet there must be some sort of archetypal theme that everybody is copying. I’ll see if I can find something about it (after work).

It might even be possible to automatically translate some popular themes into SWI’s format.

EDIT Oh, right. “Solarized” has its own wikipedia page:

Ok. Added the colour demo file into the repo, so we can extend it. You find it at https://github.com/SWI-Prolog/swipl-devel/blob/cb1353db5087a860b2a07cc71b0db51c83278644/demo/colours.pl.

If I read it correctly, Solarized is primarily a color palette, no? We have quite a few styles. Whether or not that is good or bad, I don’t know. Personally, I like all these styles. Even if you do not know the exact meaning, it tells you Prolog thinks these are different things and clicking on them should give you a basic idea what Prolog thinks about the role of a particular term. But, there seem to be people that like a lot less different styles. Possibly we need some (multiple) hierarchy?

I think you’re right. I really don’t know anything about that sort of thing. But a colour palette might also be useful. When I was putting together that dork theme I struggled to find colours that went together well and made the text easy to read.

Are there any UX designers in the SWI community, people with experience of designing fetching but accessible interfaces and so on?

How do you mean?