% Name: xhtml (an xml/xhtml mode for jed) % Author: James Dean Palmer % Revision: 0.2 (March 5, 2000) % Creation: 0.1 (July 5, 1998) % This is my xml/xhtml mode extensions for jed. It began as an html mode % for jed that had more emacsish key bindings than jed's native html mode. % I have recently resurrected it to be a general purpose xml mode with % xhtml extensions (and still with the emacs style keybindings). % It steals a few functions and the syntax highlighting code from html.sl % by Raikanta Sahu, John E. Davis, and Jim Knoble. % To install xml.sl, you can put the file in directory named ~/jed and % then add something like this to your .jedrc file: % % set_jed_library_path (strcat (expand_filename ("~/jed"), % ",", get_jed_library_path ())); % autoload ("xml_mode", "xml.sl"); % add_mode_for_extension ("xml", "xml"); % % Add this line if you want to override Jed's html mode: % add_mode_for_extension ("xml", "html"); % % Change these variables to reflect your system. variable xhtml_server = "http://www.tiger-marmalade.com/"; variable xhtml_home = "http://www.tiger-marmalade.com/~james/"; variable xhtml_name = "James Dean Palmer"; variable xhtml_email = "james@tiger-marmalade.com"; variable xhtml_lang = "en"; % This variable effects the amount of indentation that is done (in spaces). variable xml_indent = 2; % This simple formatting routine formats the current line relative to the % previous line. It uses a simple technique -- it counts the open tags % on the previous lines and subtracts the closed tags on the previous lines % and any close tag that starts on the current line. This value then becomes % the amount we format relative to the amount of whitespace on the previous % line. Comments like ")) { go_right_1 (); end_tag_count++; tag_count++; } goto_line (line); bol (); variable comment_tag_count = 0; while ((what_line () == line) and ffind (" 0, then indent right. column += open_tags * xml_indent; column--; if (column < 0) column = 0; bol_trim (); whitespace (column); pop_spot (); if (what_column () < column) bol_skip_white (); } % Apply xml_indent_line to the entire buffer. define xml_indent_buffer () { bob (); while (not(eobp ())) { xml_indent_line (); go_down_1; } } define xml_paragraph_separator () { bol_skip_white (); eolp () or ffind_char ('>') or ffind_char ('<'); } define xml_skip_tag() { !if (fsearch_char ('>')) return; go_right_1 (); } define xml_bskip_tag() { () = bsearch_char ('<'); } define xml_mark_next_tag() { variable taglng = 1; !if (fsearch_char ('>')) return; go_right(taglng); set_mark_cmd (); go_left(taglng); () = find_matching_delimiter (0); } define xml_mark_prev_tag() { !if (bsearch_char ('<')) return; set_mark_cmd (); () = find_matching_delimiter(0); go_right_1 (); exchange_point_and_mark(); } % xhtml_insert_address define xhtml_insert_address () { vinsert ("%s", xhtml_email, xhtml_name, 2); } % The time stamp stuff was somewhat inspired by Jan Hlavacek's html extensions % for Jed. Mine works a little better with my formatting routines. define xhtml_insert_time_stamp () { variable a; a = time (); vinsert ("\nModified on %s by ", a, 1); xhtml_insert_address; insert (".\n"); go_up (2); xml_indent_line; go_down_1; xml_indent_line; go_down_1; xml_indent_line; eol (); } define xhtml_update_time_stamp () { push_spot(); eob(); if (re_bsearch ("")) { bol (); push_mark (); if (re_fsearch ("")) { eol (); del_region (); xhtml_insert_time_stamp (); } } pop_spot (); } % A template for new files. define xhtml_template () { insert ("\n"); vinsert ("\n", xhtml_lang, xhtml_lang, 2); insert ("\n"); insert ("\n"); insert ("Untitled Document\n"); insert ("\n"); insert ("\n\n"); push_spot (); xhtml_insert_time_stamp (); insert ("\n\n\n"); xml_indent_buffer (); bob (); pop_spot (); } define xhtml_insert_paired_tag (a, b) { vinsert ("%s\n\n", a, 1); push_spot (); vinsert ("%s\n", b, 1); go_up (3); xml_indent_line; go_down_1; xml_indent_line; go_down_1; xml_indent_line; pop_spot (); } define xhtml_insert_single_tag (a) { vinsert ("%s", a, 1); } % Paired tag commands define xhtml_paragraph () { xhtml_insert_paired_tag ("

", "

"); } define xhtml_strong () { xhtml_insert_paired_tag ("", ""); } define xhtml_emphasized () { xhtml_insert_paired_tag ("", ""); } define xhtml_blockquote () { xhtml_insert_paired_tag ("
", "
"); } define xhtml_preformatted () { xhtml_insert_paired_tag ("
", "
"); } define xhtml_unordered_list () { xhtml_insert_paired_tag (""); } define xhtml_ordered_list () { xhtml_insert_paired_tag ("
    ", "
"); } define xhtml_title () { xhtml_insert_paired_tag ("", ""); } define xhtml_anchor () { xhtml_insert_paired_tag ("", ""); } define xhtml_target_anchor () { xhtml_insert_paired_tag ("", ""); } define xhtml_header_6 () { xhtml_insert_paired_tag ("
", "
"); } define xhtml_header_5 () { xhtml_insert_paired_tag ("
", "
"); } define xhtml_header_4 () { xhtml_insert_paired_tag ("

", "

"); } define xhtml_header_3 () { xhtml_insert_paired_tag ("

", "

"); } define xhtml_header_2 () { xhtml_insert_paired_tag ("

", "

"); } define xhtml_header_1 () { xhtml_insert_paired_tag ("

", "

"); } define xhtml_text_area () { xhtml_insert_paired_tag (""); } define xhtml_form () { xhtml_insert_paired_tag ("
", "
"); } define xhtml_margin () { xhtml_insert_paired_tag ("", ""); } define xhtml_footnote () { xhtml_insert_paired_tag ("", ""); } define xhtml_note () { xhtml_insert_paired_tag ("", ""); } define xhtml_abstract () { xhtml_insert_paired_tag ("", ""); } define xhtml_subscript () { xhtml_insert_paired_tag ("", ""); } define xhtml_superscript () { xhtml_insert_paired_tag ("", ""); } define xhtml_strikethru () { xhtml_insert_paired_tag ("", ""); } define xhtml_fixed () { xhtml_insert_paired_tag ("", ""); } define xhtml_underline () { xhtml_insert_paired_tag ("", ""); } define xhtml_italics () { xhtml_insert_paired_tag ("", ""); } define xhtml_bold () { xhtml_insert_paired_tag ("", ""); } define xhtml_address () { xhtml_insert_paired_tag ("
", "
"); } define xhtml_lit () { xhtml_insert_paired_tag ("", ""); } define xhtml_arg () { xhtml_insert_paired_tag ("", ""); } define xhtml_cmd () { xhtml_insert_paired_tag ("", ""); } define xhtml_abbrev () { xhtml_insert_paired_tag ("", ""); } define xhtml_acronym () { xhtml_insert_paired_tag ("", ""); } define xhtml_person () { xhtml_insert_paired_tag ("", ""); } define xhtml_quote () { xhtml_insert_paired_tag ("", ""); } define xhtml_definition () { xhtml_insert_paired_tag ("", ""); } define xhtml_variable () { xhtml_insert_paired_tag ("", ""); } define xhtml_keyboard () { xhtml_insert_paired_tag ("", ""); } define xhtml_citation () { xhtml_insert_paired_tag ("", ""); } define xhtml_sample () { xhtml_insert_paired_tag ("", ""); } define xhtml_table () { xhtml_insert_paired_tag ("", "
"); } define xhtml_table_row () { xhtml_insert_paired_tag ("", ""); } define xhtml_table_column () { xhtml_insert_paired_tag ("", ""); } define xhtml_item () { xhtml_insert_paired_tag ("
  • ", "
  • "); } % Single tag commands define xhtml_greater_than () { xhtml_insert_single_tag (">"); } define xhtml_less_than () { xhtml_insert_single_tag ("<"); } define xhtml_ampersand () { xhtml_insert_single_tag ("&"); } define xhtml_nonbreaking_space () { xhtml_insert_single_tag (" "); } define xhtml_definition_item () { xhtml_insert_single_tag ("
    "); } define xhtml_horizontal_rule () { xhtml_insert_single_tag ("
    "); } define xhtml_break () { xhtml_insert_single_tag ("
    "); } define xhtml_break_all () { xhtml_insert_single_tag ("
    "); } define xhtml_break_left () { xhtml_insert_single_tag ("
    "); } define xhtml_break_right () { xhtml_insert_single_tag ("
    "); } define xhtml_align_alt_image () { xhtml_insert_single_tag ("\"\""); } define xhtml_alt_image () { xhtml_insert_single_tag ("\"\""); } define xhtml_align_image () { xhtml_insert_single_tag (""); } define xhtml_input_reset () { xhtml_insert_single_tag (""); } define xhtml_input_submit () { xhtml_insert_single_tag (""); } define xhtml_input_audio () { xhtml_insert_single_tag (""); } define xhtml_input_scribble () { xhtml_insert_single_tag (""); } define xhtml_input_image () { xhtml_insert_single_tag (""); } define xhtml_input_radio () { xhtml_insert_single_tag (""); } define xhtml_input_select () { xhtml_insert_single_tag (""); } define xhtml_input_url () { xhtml_insert_single_tag (""); } define xhtml_input_date () { xhtml_insert_single_tag (""); } define xhtml_input_float () { xhtml_insert_single_tag (""); } define xhtml_input_int () { xhtml_insert_single_tag (""); } define xhtml_input_text () { xhtml_insert_single_tag (""); } define xhtml_base () { xhtml_insert_single_tag (""); } define xhtml_link () { xhtml_insert_single_tag (""); } define xhtml_nextid () { xhtml_insert_single_tag (""); } define xhtml_isindex () { xhtml_insert_single_tag (""); } % Complex paired tag commands define xhtml_definition_list () { xhtml_insert_paired_tag ("
    ", "
    "); xhtml_definition_item (); } define xhtml_menu () { xhtml_insert_paired_tag ("", ""); xhtml_item (); } define xhtml_dir () { xhtml_insert_paired_tag ("", ""); xhtml_item (); } % Turn off wrapping in html mode. variable mode, modestr; (modestr, mode) = what_mode (); mode = mode & ~(1); set_mode (modestr, mode); % Use the template for new files with *htm(l) in the file extension. { variable filename; (filename,,,) = getbuf_info (); if (string_match (filename, "htm[l]?$", 1)) { bob (); if (eobp ()) xhtml_template (); } } % The key bindings follow (X)emacs' convention almost exactly. $1 = "xml"; !if (keymap_p ($1)) make_keymap ($1); definekey ("xml_indent_line", "\t", $1); definekey ("xhtml_update_time_stamp", "\e'", $1); definekey ("xhtml_paragraph", "\e\r", $1); definekey ("xhtml_greater_than", "^c>", $1); definekey ("xhtml_less_than", "^c<", $1); definekey ("xhtml_nonbreaking_space", "^c ", $1); definekey ("xhtml_ampersand", "^c&", $1); definekey ("xhtml_strong", "^c^ss", $1); definekey ("xhtml_emphasized", "^c^se", $1); definekey ("xhtml_blockquote", "^c^sb", $1); definekey ("xhtml_preformatted", "^c^sp", $1); definekey ("xhtml_unordered_list", "^c^lu", $1); definekey ("xhtml_ordered_list", "^c^lo", $1); definekey ("xhtml_definition_item", "^c^lt", $1); definekey ("xhtml_item", "^c^ll", $1); definekey ("xhtml_item", "^c^li", $1); definekey ("xhtml_menu", "^c^lm", $1); definekey ("xhtml_dir", "^c^lr", $1); definekey ("xhtml_break", "^c\r", $1); definekey ("xhtml_title", "^c^bt", $1); definekey ("xhtml_anchor", "^c^al", $1); definekey ("xhtml_target_anchor", "^c^an", $1); definekey ("xhtml_header_1", "^c^t1", $1); definekey ("xhtml_header_2", "^c^t2", $1); definekey ("xhtml_header_3", "^c^t3", $1); definekey ("xhtml_header_4", "^c^t4", $1); definekey ("xhtml_header_5", "^c^t5", $1); definekey ("xhtml_header_6", "^c^t6", $1); definekey ("xhtml_horizontal_rule", "^c-", $1); definekey ("xhtml_align_alt_image", "^c\te", $1); definekey ("xhtml_alt_image", "^c\ti", $1); definekey ("xhtml_align_image", "^c\ta", $1); definekey ("xhtml_input_textarea", "^c^fp", $1); definekey ("xhtml_input_reset", "^c^fx", $1); definekey ("xhtml_input_submit", "^c^fb", $1); definekey ("xhtml_input_audio", "^c^fa", $1); definekey ("xhtml_input_scribble", "^c^fs", $1); definekey ("xhtml_input_image", "^c^fg", $1); definekey ("xhtml_input_radio", "^c^fr", $1); definekey ("xhtml_input_select", "^c^fc", $1); definekey ("xhtml_input_url", "^c^fu", $1); definekey ("xhtml_input_date", "^c^fd", $1); definekey ("xhtml_input_float", "^c^f.", $1); definekey ("xhtml_input_int", "^c^fi", $1); definekey ("xhtml_input_text", "^c^ft", $1); definekey ("xhtml_form", "^c^ff", $1); definekey ("xhtml_margin", "^c^nm", $1); definekey ("xhtml_footnote", "^c^nf", $1); definekey ("xhtml_note", "^c^nn", $1); definekey ("xhtml_abstract", "^c^na", $1); definekey ("xhtml_render", "^c^pr", $1); definekey ("xhtml_subscript", "^c^p_", $1); definekey ("xhtml_superscript", "^c^p\^", $1); definekey ("xhtml_strikethru", "^c^px", $1); definekey ("xhtml_underline", "^c^pu", $1); definekey ("xhtml_bold", "^c^pb", $1); definekey ("xhtml_address", "^c^sa", $1); definekey ("xhtml_lit", "^c^sl", $1); definekey ("xhtml_arg", "^c^sg", $1); definekey ("xhtml_cmd", "^c^sm", $1); definekey ("xhtml_abbrev", "^c^s.", $1); definekey ("xhtml_acronym", "^c^sy", $1); definekey ("xhtml_person", "^c^sn", $1); definekey ("xhtml_quote", "^c^sq", $1); definekey ("xhtml_definition", "^c^sd", $1); definekey ("xhtml_variable", "^c^sv", $1); definekey ("xhtml_keyboard", "^c^sk", $1); definekey ("xhtml_cite", "^c^sr", $1); definekey ("xhtml_sample", "^c^sx", $1); definekey ("xhtml_code", "^c^sc", $1); definekey ("xhtml_base", "^c^bb", $1); definekey ("xhtml_link", "^c^bl", $1); definekey ("xhtml_nextid", "^c^bn", $1); definekey ("xhtml_isindex", "^c^bi", $1); definekey ("xhtml_table", "^c^tt", $1); definekey ("xhtml_table_row", "^c^tr", $1); definekey ("xhtml_table_column", "^c^tc", $1); definekey ("xhtml_table_column", "^c^td", $1); % Now create and initialize the syntax tables. create_syntax_table ("xml"); define_syntax ("<", ">", '(', $1); % make these guys blink match define_syntax ("<>", '<', $1); define_syntax ("", '%', $1); define_syntax ("A-Za-z&", 'w', $1); define_syntax ('#', '#', $1); #ifdef HAS_DFA_SYNTAX % The highlighting copes with comments, "ð" type things, and type % HTML tags. An unrecognised &..; construct or an incomplete <...> construct % is flagged in delimiter colour. enable_highlight_cache ("xml.dfa", $1); define_highlight_rule ("", "Qcomment", $1); define_highlight_rule ("^([^\\-]|-+[^>])*-+[ \t]*>", "Qcomment", $1); define_highlight_rule ("\"]|\"[^\"]*\")*>", "keyword", $1); define_highlight_rule ("<([^>\"]|\"[^\"]*\")*(\"[^\"]*)?$", "delimiter", $1); define_highlight_rule ("&#[0-9]+;", "keyword1", $1); define_highlight_rule ("&[A-Za-z]+;", "Kdelimiter", $1); define_highlight_rule (".", "normal", $1); build_highlight_table ($1); #endif () = define_keywords ($1, "><", 3); () = define_keywords ($1, "Ð&ð", 4); () = define_keywords ($1, strcat ( "ÄËÏÖÜ", "äëï ö"üÿ" ), 5); () = define_keywords ($1, strcat ( "ÆÂÅÊÎÔÞÛâ", "æåêîôßþû" ), 6); () = define_keywords ($1, strcat ( "ÁÀÃÇÉÈÍÌ", "ÑÓÒØÕÚÙÝ", "áàãçéèíì", "ñóòøõúùý"), 7); define xml_mode () { variable xml = "xml"; set_mode (xml, 1); set_buffer_hook ("par_sep", "xml_paragraph_separator"); set_buffer_hook ("indent_hook", "xml_indent_line"); use_keymap (xml); use_syntax_table (xml); runhooks ("xml_mode_hook"); }