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.
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
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:
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).
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.
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
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
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
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] ].
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:
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?