View source with raw comments or as raw
    1/*  Part of XPCE --- The SWI-Prolog GUI toolkit
    2
    3    Author:        Jan Wielemaker and Anjo Anjewierden
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org/packages/xpce/
    6    Copyright (c)  2003-2023, University of Amsterdam
    7                              VU University Amsterdam
    8                              SWI-Prolog Solutions b.v.
    9    All rights reserved.
   10
   11    Redistribution and use in source and binary forms, with or without
   12    modification, are permitted provided that the following conditions
   13    are met:
   14
   15    1. Redistributions of source code must retain the above copyright
   16       notice, this list of conditions and the following disclaimer.
   17
   18    2. Redistributions in binary form must reproduce the above copyright
   19       notice, this list of conditions and the following disclaimer in
   20       the documentation and/or other materials provided with the
   21       distribution.
   22
   23    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   24    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   25    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   26    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   27    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   28    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   29    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   30    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   31    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   32    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   33    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   34    POSSIBILITY OF SUCH DAMAGE.
   35*/
   36
   37:- module(pce_prolog_xref, []).   38:- use_module(library(pce)).

XPCE plugin for library(prolog_xref)

This library facilitates using PceEmacs editors as sources for the Prolog cross referencer. */

   46:- multifile
   47    prolog:xref_source_identifier/2,        % +Source, -Id
   48    prolog:xref_source_directory/2,         % +Source, -Dir
   49    prolog:xref_open_source/2.              % +SourceId, -Stream
 prolog:xref_source_identifier(+Object, -Ref)
The cross-referencer runs faster if the reference is an indexable term. Therefore we strip the XPCE @ from the object.
   56prolog:xref_source_identifier(Object, Ref) :-
   57    object(Object),
   58    !,
   59    Object = @Ref.
   60prolog:xref_source_identifier(Ref, Ref) :-
   61    integer(Ref),
   62    !.
 prolog:xref_source_directory(+Source, -Dir)
Find the directory of a PceEmacs buffer to resolve relative paths.
   68prolog:xref_source_directory(SourceId, Dir) :-
   69    integer(SourceId),
   70    Obj = @SourceId,
   71    object(Obj),
   72    catch(get(Obj?file, absolute_path, Path), _, fail),
   73    file_directory_name(Path, Dir).
 prolog:xref_open_source(+Source, -Stream)
Open the PceEmacs as a Prolog stream.
   79prolog:xref_open_source(SourceId, Stream) :-
   80    integer(SourceId),
   81    Obj = @SourceId,
   82    object(Obj),
   83    pce_open(Obj, read, Stream),
   84    (   catch(get(Obj?file, absolute_path, Path), _, fail)
   85    ->  set_stream(Stream, file_name(Path))
   86    ;   true
   87    )