Subject: Re: bug#21526: 24.5; prolog-mode: broken indentation for if-then-else construct

From: Markus Triska <[email-masked]>
Date: Wed, 30 Sep 2015 22:40:31 +0200

Stefan Monnier <[email-masked]> writes:

> Is there a precedence table somewhere that includes "multifile"
> and friends?  The one I have doesn't include it.

You can generate such a table directly from Prolog, using for example:

   ?- current_op(P, T, N), portray_clause(P-T-N), false.

This yields the precedence (smaller = tighter), types and names of all
operators that are available by default. Users may change these
precedences, but it is unusual and bad practice to change the precedence
of default operators. So I would use this as a good approximation.

Using SWI-Prolog, you obtain for example:

   250-yfx- (?).
   1-fx- ($).
   990-xfx- (:=).
   200-fy- (@).
   1150-fx- (volatile).
   700-xfx- (=@=).
   200-xfy- (^).
   700-xfx- (@>).
   100-yfx- ('.').
   1150-fx- (meta_predicate).
   400-yfx- (rdiv).
   500-yfx- (\/).
   1150-fx- (initialization).
   600-xfy- (:).
   1200-xfx- (-->).
   700-xfx- (=..).
   400-yfx- (*).
   700-xfx- (@>=).
   1100-xfy- (;).
   700-xfx- (\=@=).
   700-xfx- (>:<).
   1150-fx- (dynamic).
   700-xfx- (@<).
   700-xfx- (:<).
   700-xfx- (@=<).
   400-yfx- (xor).
   1150-fx- (discontiguous).
   700-xfx- (>=).
   400-yfx- (//).
   700-xfx- (>).
   400-yfx- (div).
   1150-fx- (module_transparent).
   1200-fx- (?-).
   500-yfx- (/\).
   400-yfx- (/).
   200-fy- (+).
   500-yfx- (+).
   1150-fx- (multifile).
   400-yfx- (<<).
   1150-fx- (public).
   1200-fx- (:-).
   1200-xfx- (:-).
   400-yfx- (rem).
   1000-xfy- (',').
   1150-fx- (thread_initialization).
   700-xfx- (\=).
   700-xfx- (=).
   1050-xfy- (*->).
   700-xfx- (=<).
   700-xfx- (<).
   1050-xfy- (->).
   700-xfx- (as).
   1150-fx- (thread_local).
   400-yfx- (>>).
   200-fy- (-).
   500-yfx- (-).
   700-xfx- (is).
   900-fy- (\+).
   200-fy- (\).
   700-xfx- (=:=).
   400-yfx- (mod).
   200-xfx- (**).
   700-xfx- (\==).
   700-xfx- (==).
   1105-xfy- ('|').
   700-xfx- (=\=).

In SWI-Prolog, try the query:

   ?- help(op/3).

to see what these type indicators (xfx, fx etc.) mean.

I hope this helps you to indent according to operator precedence.

All the best,
Markus