- Subject: outlining text files
- From: Abel Morabito <amorabito@xxxxxxxxxxxxxxxx>
- Date: Mon, 13 Jan 2003 19:58:49 +0000
Dear Jed users,
I'm new to the list and I'd like to share with you a piece of code to outline
text. It's modified from 'latex.sl' by Guido Gonzato. Thank you again Guido!
It takes a plain ascii file and outlines lines beginning with asterisks up to five
levels:
* A first level
bla bla bla
** A second level
bla bla
etc.
Best regards!
Abel Morabito
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File name: outline.sl
% Original code was utterly taken from 'latex.sl' by Guido Gonzato.
% Just a few changes were made to deal with regex.
% THANK YOU GUIDO!
% Lines starting with '*' up to '*****' will be outlined.
% Of course this is free and not guaranteed --but it works fine. Enjoy!
%
% You should copy this file wherever your JED's libraries are and add
% this in your '.jedrc' file:
% () = evalfile ("outline");
%
% Then you must call 'ouline_browse_tree' as you need it. To do it with <F8>
% you should add this line in your '.jedrc' file under a UNIX environment:
% unsetkey("\e[19~"); setkey("outline_browse_tree","\e[19~");
%
% Abel Morabito <amorabito@xxxxxxxxxxxxxxxx>. Jan, 2003.
static variable Outline_Buffer;
static variable Outline_Tree_Buffer;
static variable TRUE = 1;
static variable FALSE = 0;
static variable line_mark;
custom_variable ("Outline_Indent", 2);
define goto_error_line ()
{
variable line, tmp = get_word_chars ();
% extract the line number
bol ();
define_word ("0-9");
skip_word ();
push_mark ();
bskip_word ();
line = integer (bufsubstr ());
sw2buf (Outline_Buffer);
bob ();
() = down (line - 1);
define_word (tmp);
}
static define getline ()
{
variable line, numline;
push_mark ();
eol ();
line = bufsubstr ();
pop_mark_0 ();
numline = what_line ();
return (line, numline);
}
% this one creates the buffer that contains the document tree (outline)
define outline_build_doc_tree ()
{
variable i, found, line, numline, num_sections = 0, level = -1;
variable sections = String_Type [5];
Outline_Buffer = whatbuf ();
sw2buf ("Outline_Tree_Buffer");
set_readonly (0);
erase_buffer ();
insert ("Document outline ('q' to quit, <Return> or double click to select):\n\n");
sw2buf (Outline_Buffer);
push_spot ();
bob ();
% get the line
(line, numline) = getline ();
sw2buf ("Outline_Tree_Buffer");
% TODO: find a better solution
vinsert ("%6d%s", numline, " ");
insert (line + "\n");
% We insert the first entry on the outline, preceded by its line
% number. That's very important, see below.
sections [0] = "^\\* ";
sections [1] = "^\\*\\* ";
sections [2] = "^\\*\\*\\* ";
sections [3] = "^\\*\\*\\*\\* ";
sections [4] = "^\\*\\*\\*\\*\\* ";
% now, let's look for sectioning commands.
for (i = 0; i < 5; i++) {
sw2buf (Outline_Buffer);
bob ();
do {
found = FALSE;
sw2buf (Outline_Buffer);
if (0 != re_fsearch (sections [i])) { %%% search forward for regexp %%%
if (-1 == level)
level = i; % first level of indentation
% TODO: check for comments!!!
(line, numline) = getline ();
num_sections++;
() = down (1);
sw2buf ("Outline_Tree_Buffer");
vinsert ("%6d%s", numline, " ");
insert_spaces ((i - level + 1) * Outline_Indent);
insert (line + "\n");
found = TRUE;
}
} while (TRUE == found);
}
% got it? as soon as you find an element, you insert it in the buffer. It's
% preceded by its line number and the right amount of spaces.
% ok, now the tree is done; let's sort it
sw2buf ("Outline_Tree_Buffer");
bob ();
() = down (2);
push_mark ();
() = down (num_sections);
eol ();
sort ();
pop_mark_0 ();
set_readonly (1);
text_mode ();
setbuf_info (getbuf_info () & 0xFE); % not modified
sw2buf (Outline_Buffer);
pop_spot ();
}
static define update_tree_hook ()
{
line_mark = create_line_mark (color_number ("menu_selection"));
}
define outline_browse_tree ()
{
variable tmode = "tree";
!if (keymap_p (tmode))
make_keymap (tmode);
definekey ("delbuf (whatbuf())", "q", tmode);
definekey ("goto_error_line", "\r", tmode);
outline_build_doc_tree ();
sw2buf ("Outline_Tree_Buffer");
set_buffer_hook ("update_hook", &update_tree_hook);
set_readonly (1);
use_keymap (tmode);
set_mode (tmode, 0);
set_buffer_hook ("mouse_2click", "goto_error_line");
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.
[2003 date index]
[2003 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]