<commit_before>/*  $Id$

    Part of XPCE
    Designed and implemented by <NAME> and <NAME>
    E-mail: <EMAIL>

    Copyright (C) 1994 University of Amsterdam. All rights reserved.
*/

:- module(pce_help, []).
:- use_module(library(pce)).
:- use_module(library(pce_prompter)).
:- require([ auto_call/1
	   , ignore/1
	   , forall/2
	   , member/2
	   , pce_help_file/2
	   , term_to_atom/2
	   , absolute_file_name/3
	   , atom_to_term/3
	   , concat/3
	   , default/3
	   , send_list/3
	   , sformat/3
	   ]).


:- pce_global(@helper, new(helper)).
:- pce_global(@finder, new(finder)).
:- pce_autoload(finder, library(find_file)).


		 /*******************************
		 *	      HELPER		*
		 *******************************/

:- pce_begin_class(helper, sheet, "Helper toplevel").

variable(buffers, sheet, get, "Sheet of open buffers").

:- send(@class, save_style, external).

initialise(Helper) :->
	send(Helper, send_super, initialise),
	send(Helper, slot, buffers, new(sheet)),
	send(@pce, exit_message, message(Helper, save_if_modified)).


save_if_modified(Helper) :->
	"Save unsaved buffers"::
	get(Helper, buffers, Sheet),
	send(Sheet, for_all,
	     message(@arg1?value?editors, for_all,
		     message(@arg1, save_if_modified))).


help_file(Helper, Name:name, File:file) :->
	"Attach a help-file"::
	send(File, absolute_path),
	(   get(Helper, value, Name, OldFile)
	->  (	send(File, same, OldFile)
	    ->	true
	    ;	send(Helper, report, warning,
		     'Redefined help file for database %s', Name),
		send(Helper, value, Name, File),
		ignore(send(Helper?buffers, delete, Name))
	    )
	;   send(Helper, value, Name, File)
	).


give_help(Helper, Database:name, Label:[name]) :->
	"View given database at label"::
	(   get(Helper?buffers, value, Database, Buffer)
	->  (	get(Buffer?editors, head, Editor)
	    ->	true
	    ;	get(Buffer, open, Editor)
	    ),
	    (	Label == @default
	    ->	send(Editor, caret, 0)
	    ;   send(Editor, goto, Label)
	    ),
	    send(Editor?frame, expose)
	;   (	get(Helper, value, Database, RC)
	    ;	new(RC, pce_help_file:resource(Database, help))
	    )
	->  (   pce_help_file:resource(Database, help, FileSpec),
	        absolute_file_name(FileSpec, Path)
	    ->  new(File, file(Path))
	    ;	File = @nil
	    ),
	    (	send(RC, exists)
	    ->	(   send(RC, check_object),
		    get(RC, object, Buffer),
		    send(Buffer, instance_of, hlp_buffer)
		->  send(Helper?buffers, value, Database, Buffer),
		    send(Buffer, file, File),
		    get(Buffer, open, Editor),
		    (	Label == @default
		    ->	send(Editor, caret, 0)
		    ;   send(Editor, goto, Label)
		    )
		;   send(Helper, report, error,
			 'Illegal data-format in "%N"', RC),
		    fail
		)
	    ;	(   get(@pce, is_runtime_system, @on)
		->  send(@display, inform,
			 'No help available for "%s"', Database),
		    fail
		;   send(@display, confirm,
			 'No help-database "%s"\n\nCreate it?', Database),
		    new(Buffer, hlp_buffer),
		    send(Buffer, file, File),
		    get(Buffer, open, Editor),
		    send(Editor, editable, @on)
		)
	    )
	;   term_to_atom(DBTerm, Database),
	    functor(DBTerm, _, 1),
	    arg(1, DBTerm, DBname)
	->  assert(pce_help_file:resource(DBname, help, DBTerm)),
	    send(Helper, give_help, DBname, Label)
	;   send(Helper, report, error,
		 'No help-database called %s', Database),
	    fail
	).

:- pce_end_class.


		 /*******************************
		 *	       FRAGMENT		*
		 *******************************/

:- pce_begin_class(hlp_fragment, fragment, "Help fragment").

variable(label, 'name|int*', both, "Reference label of this text").

number_section(_Frag, _I:vector) :->
	"Dummy"::
	true.

emptied(F) :->
	"Destroy empty fragments"::
	send(F, free).

:- pce_end_class.

		 /*******************************<commit_msg>* Better modularisation<commit_after>/*  $Id$

    Part of XPCE
    Designed and implemented by <NAME> and <NAME>
    E-mail: <EMAIL>

    Copyright (C) 1994 University of Amsterdam. All rights reserved.
*/

:- module(pce_help, []).
:- use_module(library(pce)).
:- use_module(library(pce_prompter)).
:- require([ auto_call/1
	   , ignore/1
	   , forall/2
	   , member/2
	   , pce_help_file/2
	   , term_to_atom/2
	   , absolute_file_name/3
	   , atom_to_term/3
	   , concat/3
	   , default/3
	   , send_list/3
	   , sformat/3
	   ]).


:- pce_global(@helper, new(helper)).
:- pce_global(@finder, new(finder)).
:- pce_autoload(finder, library(find_file)).


		 /*******************************
		 *	      HELPER		*
		 *******************************/

:- pce_begin_class(helper, sheet, "Helper toplevel").

variable(buffers, sheet, get, "Sheet of open buffers").

:- send(@class, save_style, external).

initialise(Helper) :->
	send(Helper, send_super, initialise),
	send(Helper, slot, buffers, new(sheet)),
	send(@pce, exit_message, message(Helper, save_if_modified)).


save_if_modified(Helper) :->
	"Save unsaved buffers"::
	get(Helper, buffers, Sheet),
	send(Sheet, for_all,
	     message(@arg1?value?editors, for_all,
		     message(@arg1, save_if_modified))).


help_file(Helper, Name:name, File:file) :->
	"Attach a help-file"::
	send(File, absolute_path),
	(   get(Helper, value, Name, OldFile)
	->  (	send(File, same, OldFile)
	    ->	true
	    ;	send(Helper, report, warning,
		     'Redefined help file for database %s', Name),
		send(Helper, value, Name, File),
		ignore(send(Helper?buffers, delete, Name))
	    )
	;   send(Helper, value, Name, File)
	).


give_help(Helper, Database:name, Label:[name]) :->
	"View given database at label"::
	get(Helper, buffer, Database, @on, Buffer),
	(   get(Buffer?editors, head, Editor)
	->  true
	;   get(Buffer, open, Editor)
	),
	(   get(Buffer, size, 0)
	->  send(Editor, editable, @on)
	;   Label == @default
	->  send(Editor, caret, 0)
	;   send(Editor, goto, Label)
	).


buffer(Helper, Database:name, Interactive:[bool], Buffer:hlp_buffer) :<-
	"Return hlp-buffer holding help-text"::
	(   get(Helper?buffers, value, Database, Buffer)
	->  true
	;   (	get(Helper, value, Database, RC)
	    ;	new(RC, pce_help_file:resource(Database, help))
	    )
	->  (   pce_help_file:resource(Database, help, FileSpec),
	        absolute_file_name(FileSpec, Path)
	    ->  new(File, file(Path))
	    ;	File = @nil
	    ),
	    (	send(RC, exists)
	    ->	(   send(RC, check_object),
		    get(RC, object, Buffer),
		    send(Buffer, instance_of, hlp_buffer)
		->  send(Helper?buffers, value, Database, Buffer),
		    send(Buffer, file, File)
		;   send(Helper, report, error,
			 'Illegal data-format in "%N"', RC),
		    fail
		)
	    ;	Interactive == @on,
	        (   get(@pce, is_runtime_system, @on)
		->  send(@display, inform,
			 'No help available for "%s"', Database),
		    fail
		;   send(@display, confirm,
			 'No help-database "%s"\n\nCreate it?', Database),
		    new(Buffer, hlp_buffer),
		    send(Buffer, file, File)
		)
	    )
	;   term_to_atom(DBTerm, Database),
	    functor(DBTerm, _, 1),
	    arg(1, DBTerm, DBname)
	->  assert(pce_help_file:resource(DBname, help, DBTerm)),
	    get(Helper, buffer, DBname, Buffer)
	;   Interactive == @on,
	    send(Helper, report, error,
		 'No help-database called %s', Database),
	    fail
	).

:- pce_end_class.


		 /*******************************
		 *	       FRAGMENT		*
		 *******************************/

:- pce_begin_class(hlp_fragment, fragment, "Help fragment").

variable(label, 'name|int*', both, "Reference label of this text").

number_section(_Frag, _I:vector) :->
	"Dummy"::
	true.

emptied(F) :->
	"Destroy empty fragments"::
	send(F, free).

:- pce_end_class.

		 /*******************************
{'fraction_non_alphanumeric': 0.19495201787827002, 'fraction_numerical': 0.005784146181148942, 'mean_word_length': 3.305602716468591, 'pattern_counts': {'":': 11, '<': 10, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2350635', 'n_tokens_mistral': 2926, 'n_tokens_neox': 2691, 'n_words': 571}