[Pkg-jed-devel] Re: jed-extra.deb

Guenter Milde g.milde@web.de
Wed, 6 Apr 2005 09:33:42 +0200


--IJpNTDwzlM2Ie8A6
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

On  1.04.05, Rafael Laboissiere wrote:
> Guenter, 
> 
> You are replying to a quite old message.  Have you seen the announcement of
> jed-extra I sent to both jed-users and pkg-jed-devel on March 19?

I am afraid I cannot find it on the jed-users
   http://ruptured-duck.com/archives.html
   
Results:
References: [ jed-extra: 0 ] 
No document matching your query. 

So, maybe I missed it.

> * Guenter Milde <g.milde@web.de> [2005-04-01 17:34]:
> 
> > On 10.03.05, Rafael Laboissiere wrote:
> > > I am already working on this.  In my current design, the package
> > > installs all the necessary autoloads and add_completions
> > 
> > Are you using make_ini.sl? 
> 
> I thought about using make_ini, but it would only work if
> <INITIALIZATION> blocks are present in all files.  

Well, it could still help (with autoloads and files that have the
INITIALIZATION block). The ini.sl file can contain "permanent" stuff at the
top. add_completion() commands and Initialization code could be placed
there...

> I could patch the files by putting in them what is now in the *.rc
> files.  What do you think?  You might add me as a developer to the SF
> jedmodes project, such that i can commit the changes myself.

The policy of Jedmodes CVS is that only the author(s) should make
changes to their submissions. You are invited to mail suggestions or
patches to the modes author, most modes contain a mail address.

 
> > There is a new bugfix version at Jedmodes.
> 
> The jed-extra_1.0-1 package uses the cvs-snapshot tarball released at SF
> on 2005-03-09 02:34.

So we should definitively put out a bugfix release... Unfortunately,
things are quite in flux at present, in (at last) a weeks time
or so I will pack a new Jedmodes "release" (i.e. cvs snapshot). (But I
still suggest packing jed-extra from a cvs working copy.)

> > Also, automatic documentation extraction is coming soon with the release
> > of tm.sl...
> 
> Very nice.

So jed-extra should use it to generate on-line help texts (in
Jed_Debian/libfuns.txt). 

 * Either as a configuration step (smaller package size),
 * or before packaging (more transparent, as the help is available
   also without installing the package)

I'll attach the current version for reference and testing.

> > However, currently make_ini() doesnot add add_completions (as there is
> > a limit to the number of completions which could be exceeded easily :-(
> 
> I was hit by that limit.  I got around it by rebuilding the jed package
> with the following patch:
> 
> --- jed-0.99.16.orig/src/keymap.c
> +++ jed-0.99.16/src/keymap.c
> @@ -974,7 +974,7 @@
>  static SLKeymap_Function_Type *Flist_Context;
>  static int Flist_Context_Len;
>    
> -#define MAX_USER_FLIST 100
> +#define MAX_USER_FLIST 512
>  static char *Slang_Functions[MAX_USER_FLIST];
>  static char **Slang_Flist_Context;
> 
> Paul Boekholt told me that this limitation does not exist in jed 0.9.17.

In this case, I should add the add_completions to make_ini again (with a
custom_variable for users who cannot (or don't want to) use this feature.

If jed-extra depends on a jed version with this patch, it could activate
the feature.


> > > The problem with this is that it is not orthogonal with the Debian
> > > packaging.  If the jed-extra is kept reasonably updated, then I think it
> > > will be okay for the Debian users.
> > 
> > To make this orthogonal, we might need one more jed library dir:
> > 
> >   JED_ROOT/lib       the package default library
> >   Jed_Debian_Library     the debian specific extension library
> >   Jed_Site_Library       the sitewide extension library
> >   Jed_Home_Library       the user local extension library
> >
> > The libraries will be searched in reverse order (of my listing), i.e.
> > with the most local one first. This way we would keep the orthogonality
> > of Debian provided modes and local downloads. Of course, a user or
> > sysadmin that installed modes from Jedmodes will have to be aware, that
> > the local version masks the Debian-provided one (and should eventually
> > be removed when jed-extra got the same or higher version). However,
> > this should be common knowledge, as it is the same for default modes.
> 
> Sounds nice, but who is going to implement this idea?

It should be easy with the applied version of home-lib.sl

  variable Jed_Debian_Library = "wherever/you/want/the/jed/debian/lib/";
  require("<full-path-to>/home-lib.sl");

> > Debian Packages would be free to place additional modes into
> > Jed_Debian_Library. This could extend the "/etc/jed-init.d/" feature (or
> > even replace it) especially for files that do not need to be evaluated
> > at every jed startup.

> IMO, /etc/jed-init.d/ will still be necessary for add_completions,
> autoloads and the like.

... if the files do not come with an INITIALIZATION block.

Günter

 
-- 
G.Milde web.de

--IJpNTDwzlM2Ie8A6
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: attachment; filename="home-lib.sl"
Content-Transfer-Encoding: 8bit

% Extended support for a user-specific directory with private extensions
% 
% % Copyright (c) 2003 Günter Milde and released under the terms 
% of the GNU General Public License (version 2 or later).
% 
% Version 0.9    first public version
%         0.9.1  Jed_Highlight_Cache_Path += Jed_Home_Library;
%         0.9.2  cleanup of code and documentation + bugfix
%                custom_variable for Jed_Site_Library and Jed_Home_Library
%         0.9.3  documentation bugfix: "%!%" -> "%!%-"
%         0.9.4  outsourcing of the registration -> register_library(dir)
%                added custom_variable Jed_Debian_Library = ""
%                
% FEATURES
% 
%  * If a subdirectory .jed/ exists in Jed_Home_Directory, 
%    let Jed_Home_Directory point there,
%  * Prepend site-specific and user-specific libraries to the library path,
%  * evaluate (if existent) the file ini.sl in site and home libraries
%    to enable initialization (autoloads etc).
%  * set Color_Scheme_, dfa-cache- and documentation- path
%  
% Together with make-ini.sl, this provides a convenient way of extending
% jed with contributed or home-made scripts.
% 
% INITIALIZATION
% 
% Write in your .jedrc (or jed.rc on winDOS)
%   require("home-lib", "/FULL_PATH_TO/home-lib.sl")
% or put home-lib.sl in JED_ROOT/lib and write in .jedrc 
%   require("home-lib")
% or rename to (or insert into) defaults.sl.
% On Debian, you can put it in /etc/jed-init.d for automatic evaluation
% 
% With the latter variants "jedrc" is found at following places (assuming UNIX)
%    ~/.jed/.jedrc
%    ~/.jedrc
%    ~/.jed/lib/jed.rc    (actually, Jed_Home_Library + "/jed.rc")
%    Jed_Site_Library + "/jed.rc"
%    JED_ROOT + "/lib/jed.rc"
% 
% CUSTOMIZATION
% 
% For other than the default paths use the environment variables 
% JED_HOME and JED_SITE_LIB or define Jed_Site_Library, and 
% Jed_Home_Library before evaluating home-lib.sl.
%          
% TODO: * adapt and test for windows systems

static variable path;

% --- Jed_Home_Directory ------------------------------------------

% Jed_Home_Directory is defined in site.sl, defaulting to $HOME
% If Jed_Home_Directory/.jed/ exists, point Jed_Home_Directory there,
path = path_concat(Jed_Home_Directory, ".jed");
if(2 == file_status(path))
  Jed_Home_Directory = path; 

% documentation on library functions can reside in
% Jed_Home_Directory/doc/txt/libfuns.txt or
% Jed_Home/lib/libfuns.txt (see later in this file)
if(2 == file_status(Jed_Home_Directory)) % directory does exist
{
   path = expand_filename(Jed_Home_Directory+"/doc/txt/libfuns.txt");
   if(1 == file_status(path))
     Jed_Doc_Files = Jed_Doc_Files + "," + path;
}

% backwards compatibility of jedrc-location 
% (if nonexistent, Jed_Home_Library+"/jed.rc" will be tried)
#ifdef UNIX
Default_Jedrc_Startup_File = "~/.jedrc";
#endif

% --- Jed_Site_Library and Jed_Home_Library  ------------------------

%!%+
%\variable{Jed_Site_Library}
%\synopsis{Directory for site-wide non-standard slang scripts}
%\description
%  The value of this variable specifies the directory for site-wide
%  jed-slang scripts. It is a custom variable that defaults to
%    the value of the \var{JED_SITE_LIB} environment variable,
%    /usr/local/share/jed/lib or 
%    JED_ROOT/site-lib. 
%  Will be set to "" if the library directory is not present.
%\seealso{Jed_Home_Library, get_jed_library_path, set_jed_library_path}
%!%-
custom_variable("Jed_Site_Library", getenv("JED_SITE_LIB"));
if (Jed_Site_Library == NULL) % no custom or environment var set
   Jed_Site_Library = "/usr/local/share/jed/lib";
if (file_status(Jed_Site_Library) != 2) % no directory
  Jed_Site_Library = path_concat(JED_ROOT, "site-lib");
if (file_status(Jed_Site_Library) != 2) % no directory
  Jed_Site_Library = "";

%!%+
%\variable{Jed_Home_Library}
%\synopsis{Directory for private non-standard slang scripts}
%\description
%  The directory for private jed-slang scripts. Defaults to 
%  Jed_Home_Directory/lib.
%  Jed_Home_Library is set to "" if the given/default directory is 
%  not present.
%\seealso{Jed_Site_Library, Jed_Home_Directory, set_jed_library_path}
%!%-
custom_variable("Jed_Home_Library", path_concat(Jed_Home_Directory, "lib"));
if (file_status(Jed_Home_Library) != 2) % no directory
  Jed_Home_Library = "";


% this one will be defined on Debian Gnu/Linux
custom_variable("Jed_Debian_Library", "");

%  * Prepend \var{lib} to the library path,
%  * evaluate (if existent) the file ini.sl in this library
%    to enable initialization (autoloads etc).
%  * set Color_Scheme_, dfa-cache- and documentation- path
define register_library(lib)
{
   !if (2 == file_status(lib)) % directory doesnot exist
     return;
     
   variable path;
   
   % jed library path
   set_jed_library_path(lib + "," + get_jed_library_path());
   % colors
   path = path_concat(lib, "colors");
   if (2 == file_status(path))
     Color_Scheme_Path = Color_Scheme_Path + "," + path;
   % documentation
   path = path_concat(lib, "libfuns.txt");
   if (1 == file_status(path))
     Jed_Doc_Files = path + "," + Jed_Doc_Files;
   % dfa cache
#ifdef HAS_DFA_SYNTAX
   path = path_concat(lib, "dfa");
   if (2 != file_status(path))
     path = lib;
   Jed_Highlight_Cache_Dir = path;
   Jed_Highlight_Cache_Path += "," + path;
#endif
   % Check for a file ini.sl containing initialization code
   % (e.g. autoload declarations) and evaluate it.
   path = path_concat(lib, "ini.sl");
   if (1 == file_status(path))
     () = evalfile(path);
}


% --- "register" the libraries -------------------------------------------

foreach ([Jed_Debian_Library, Jed_Site_Library, Jed_Home_Library])
  register_library(());


--IJpNTDwzlM2Ie8A6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="tm.sl"

% tm.sl
% tm documentation parser
%
% $Id$
% Keywords: slang, doc, tools
%
% Copyright (c) 2004 Paul Boekholt, Guenter Milde
% Released under the terms of the GNU GPL (version 2 or later).
%
% This extracts tm documentation from S-Lang sources the *hard* way. It
% uses string operations, so it should be easy to port to slrn and slsh.
% The tm.sed sed-script is *much* simpler and probably much faster, but
% this may be useful for:
%
%  - windows users who don't have sed
%  - jed hackers who want to preview their tm documentation.
%  - incorporating into other slang scripts (make_ini)
%
%  2005-03-18  added tm documentation
%              new function tm_make_ascii_doc (transfered from make_ini())
%  2005-03-21  rework of tm_make_ascii_doc, tm2ascii called file-wise
%              -> speedup by factor 3...6 (PB)
%  2005-03-22  tm_extract with array_map instead of regexp parsing (GM)
%  2005-03-23  block-wise tm2ascii conversion in tm_get_block()
%              replaced tm_parse() with parse-argument in tm_extract (GM)
%  2005-03-31  restructuring code: (avoid temp file for tm-preview)
%                tm_get_blocks()  -- return array of tm-documentation blocks
%                tm_parse()       -- reintroduced
%  	         tm_make_ascii_doc() and tm_preview() united to
%  	         tm_view([args])  -- args are filenames to extract doc from
%  	                             no arg: extract from current buffer/region
%
%  TODO: let this work for tm-documented C-code too

autoload("str_re_replace_all", "strutils");
autoload("arrayread_file", "bufutils");
autoload("get_lines", "csvutils");
autoload("view_mode", "view");

if (_featurep("tm"))
  use_namespace("tm");
else
  implements("tm");
provide("tm");

static variable Tm_Doc_Buffer = "*tm doc*";

% convert a string with tm-markup to ASCII representation
static define tm2ascii(str)
{
   % indent by 2 spaces. Usually there are already some spaces.
   % Maybe this should be a regexp replace.
   % str = str_replace_all(str, "\n", "\n  ");

   variable pos, len;

   % Blocks (function or variable descriptions)
   str = str_replace_all(str, "\\done", "-----------------------------------");

   %  \function or \variable
   str = str_re_replace_all
     (str, "\\\\function{\\([^\}]+\\)}", "\\1");
   str = str_re_replace_all
     (str, "\\\\variable{\\([^\}]+\\)}", "\\1");
   % \var, \em
   str = str_re_replace_all
     (str, "\\\\var\{\\([^\}]+\\)\}", "`\\1'");
     % this breaks generated doc and tm_preview in jed <= 99.17
     % (str, "\\\\var\{\\([^\}]+\\)\}", "\e[1m\\1\e[0m");
   str = str_re_replace_all
     (str, "\\\\em{\\([^\}]+\\)}", "_\\1_");
   % sections
   str = str_re_replace_all
     (str, "\\\\synopsis{\\([^\}]+\\)}", "\n SYNOPSIS\n  \\1");
   str = str_replace_all(str, "\n\\synopsis{}", "");
   str = str_re_replace_all
     (str, "\\\\usage{\\([^\}]+\\)}", "\n USAGE\n  \\1");
   str = str_replace_all(str, "\n\\usage{}", "");
   str = str_re_replace_all
     (str, "\\\\seealso{\\([^\}]+\\)}", "\n SEE ALSO\n  \\1");
   str = str_replace_all(str, "\n\\seealso{}", "");
   str = str_replace_all(str, "\\example", "\n EXAMPLE");
   str = str_replace_all(str, "\\description", "\n DESCRIPTION");
   str = str_replace_all(str, "\\notes", "\n NOTES");

   % verbatim - it's not likely that there's tm markup in verbatim sections,
   % otherwise we'd have to split and parse the tm verbatim-wise.
   variable pos2, len2;
   while(string_match(str, "\n[ \t]*#v+", 1))
     {
	(pos, len) = string_match_nth(0);
	!if (string_match(str, "\n[ \t]*#v-", pos + len)) break;
	(pos2, len2) = string_match_nth(0);
	str = strcat(str[[:pos]], "\n",
	       str_replace_all(str[[pos + len + 1: pos2 - 1]], "\n", "\n "),
	       "\n", str[[pos2+len2:]]);
     }
   return str;
}

% extract a tm-documentation block from an array of lines 
% the lines-array is given as pointer, so that the function will work in
% an array_map (it would fail else because of the different size of lines 
% and beg_index/end_index).
static define tm_get_block(beg_index, end_index, linesref)
{
   variable lines = @linesref;
   % show(length(@lines), beg_index, end_index);
   % show(lines[[beg_index:end_index]]);
   variable block = lines[[beg_index+1:end_index-1]];
   % remove comments
   block = array_map(String_Type, &strtrim_beg, block, "%");
   block = strjoin(block, "") + "\\done\n\n";
   return block;
}

% Extract tm-documentation blocks from an array of lines
% Return as String-array of blocks
static define tm_get_blocks(lines)
{
   variable tmmarks, beg_marks, end_marks, blocks;

   % get the line numbers of all tm-marks
   tmmarks = array_map(Int_Type, &strncmp, lines, "%!%", 3);
   tmmarks = where(tmmarks == 0);
   % show(tmmarks, lines[[tmmarks]]);
   !if (length(tmmarks))
     return String_Type[0];
   
   % get the line-numbers of beg and end tmmarks
   beg_marks = array_map(Integer_Type, &strncmp, lines[[tmmarks]], "%!%+", 4);
   beg_marks = tmmarks[[where(beg_marks == 0)]];
   end_marks = array_map(Integer_Type, &strncmp, lines[[tmmarks]], "%!%-", 4);
   end_marks = tmmarks[[where(end_marks == 0)]];
   if (length(beg_marks) == 0 or length(end_marks) == 0)
     return String_Type[0];
   if (length(beg_marks) != length(end_marks))
     error("tm-block marks don't match");
   % show(beg_marks, end_marks);
   
   return array_map(String_Type, &tm_get_block, beg_marks, end_marks, &lines);
}
  
  
%!%+
%\function{tm_extract}
%\synopsis{Extract tm documentation blocks from a file}
%\usage{String tm_extract(String filename)}
%\description
%  Return a string with the tm documentation contained in file
%  \var{filename} in the \var{tm} format used by the *.tm files
%  of jed and slang documentation.
%\example
%  To get the tm-doc of a file, do e.g.
%#v+
%      variable tm_doc_str = tm_extract("tm.sl", 0);
%#v-
%\notes
%  Currently, this only works with SLang files.
%  TODO: let it work for tm blocks in C files too.
%\seealso{tm_parse, tm_mode, tm_make_doc, tm->tm2ascii}
%!%-
public define tm_extract(filename)
{
   variable blocks = tm_get_blocks(arrayread_file(filename));
   return strjoin(blocks, "");
}


%!%+
%\function{tm_parse}
%\synopsis{Return ASCII-version of a files tm-documentation blocks}
%\usage{String tm_parse(String filename)}
%\description
%  Parse a file for tm-documentation blocks and convert them to
%  ASCII with tm2ascii.
%\example
%#v+
%   variable doc_str = tm_parse("tm.sl");
%#v-
%\seealso{tm_view, tm_extract}
%!%-
public define tm_parse(filename)
{
   % extract documentation blocks
   variable blocks = tm_get_blocks(arrayread_file(filename));
   !if (length(blocks))
     return "";
   % convert to ASCII
   blocks = array_map(String_Type, &tm2ascii, blocks);
   % return as string
   return strjoin(blocks, "");
}
   
   
%!%+
%\function{tm_view}
%\synopsis{Extract tm documentation, convert to ASCII and show in a buffer}
%\usage{tm_view([args])}
%\description
%  Extract tm documentation from given files or (with emty argument list)
%  the current buffer or (if defined) region.
%  Convert to ASCII and show in a buffer.
%\example
%  View tm-documentation from current buffer (or region):
%#v+
%    tm_view();
%#v-
%  View tm-documentation from all Slang files in the current directory:
%#v+
%    tm_view(directory("*.sl"), pop());
%#v-
%\seealso{tm_parse, tm_extract, tm->tm2ascii}
%!%-
public define tm_view() % ([args])
{
   variable filename, str="";
   
   flush("extracting documentation");
   !if (_NARGS)
     {
	% extract documentation blocks
	variable blocks = tm_get_blocks(get_lines()+"\n");
	% convert to ASCII
	blocks = array_map(String_Type, &tm2ascii, blocks);
	% insert
	str = strjoin(blocks, "");
     }
   else
     loop(_NARGS)
       {
	  filename = ();
	  str += tm_parse(filename);
       }
   vmessage("extracted documentation from %d files", _NARGS);
   
   if (str == "")
     return message("no tm-documentation found");
     
   sw2buf(Tm_Doc_Buffer);
   set_readonly(0);
   erase_buffer();
   insert(str);
   % bob();
   view_mode();
}


_add_completion("tm_parse", "tm_view", 2);

--IJpNTDwzlM2Ie8A6--