Arbortext Command Language > Using the Arbortext Command Language > Example: Tailoring Dash Insertion
  
Example: Tailoring Dash Insertion
Arbortext Editor cycles through three different types of dashes (- or hyphen, – or en dash, and — or em dash) when you press the - key. The following commands change the order of this cycling.
# Here we define individual aliases to insert each
# kind of dash:
#
alias insert_hyphen
{
insert_string -sgml "-X";
delete_character;
}
alias insert_ndash {insert_string -sgml "–"}
alias insert_mdash {insert_string -sgml "—"}
#
# Here we define what dash type should be inserted
# for each case. To change the order, only these
# aliases need to be swapped:
#
alias insert_dash_after_non_dash insert_hyphen
alias insert_dash_after_hyphen insert_ndash
alias insert_dash_after_ndash insert_mdash
alias insert_dash_after_mdash insert_hyphen
#
# Insert the appropriate dash depending on what's
# already there.
#
alias insert_dash
{
# assume pending delete, so if there is a selection,
# delete it before inserting the dash
if ( selected() > 0 )
{delete_mark;}
# now select the character before the cursor
clear_mark;
mark begin;
caret 0,-1;
mark end;
# figure out what dash to insert based on the previous
# character, since sgmlselection may be set on or off,
# we need to test two cases where the SGML and ASCII
# versions are different.
if ( $selection == "-" ) # type one dash
{
delete_mark;
insert_dash_after_hyphen;
}
else if ( $selection == "–" || \
$selection == "––" ) # type two dashes
{
delete_mark;
insert_dash_after_ndash;
}
else if ( $selection == "—" || \
$selection == "–––" ) # type three dashes
{
delete_mark;
insert_dash_after_mdash;
}
else
{
clear_mark;
caret 0,+1;
insert_dash_after_non_dash;
}
};
#
# Finally, we map the hyphen/dash/minus key to our
# insert_dash alias.
map edit - insert_dash;
If you were operating in an environment when pending delete was disabled, you would want to remove the lines that deleted a selected region.