home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / elvos221.zip / lib / elvis.ali < prev    next >
Text File  |  1998-12-10  |  8KB  |  349 lines

  1. alias lf !!ls -CF
  2.  
  3. alias save {
  4.  "Write this file, but only if it has been modified
  5.  if modified
  6.  then w!? !*
  7. }
  8.  
  9. alias w {
  10.  "Write this file, but if readonly then check it out first
  11.  if readonly && "!?!%!*" == ""
  12.  then !!co -l %
  13.  then w!!
  14.  else !%w!? !*
  15. }
  16.  
  17. alias man split +mantweak !man
  18.  
  19. alias mantweak {
  20.  "Convert nroff output back into man source
  21.  local report=0 nosaveregexp
  22.  try 1 s/^Reformatting.*ait\.\.\.$//
  23.  try %s/\\/\\\\/g
  24.  try %s/_\(.\)/\\fI\1\\fR/g
  25.  try %s/.\(.\)/\\fB\1\\fR/g
  26.  try %s/\\fR\\fB//g
  27.  try %s/\\fR\\fI//g
  28.  1 i .nf
  29.  set bd=man nomod
  30.  dis man
  31. }
  32.  
  33. alias text {
  34.  "Like :tag but for any text in *.c or *.h
  35.  set tagprgonce="grep -nsw '(quote(\"'\",$1))' *.[ch] /dev/null \| sed 's/^\\\\\\(.*\\\\\\):\\\\\\(.*\\\\\\):.*/!^    \\1    \\2/'"
  36.  tag!? !*
  37. }
  38.  
  39. alias btext {
  40.  "Like :browse but for any text in *.c or *.h
  41.  set tagprgonce="grep -nsw '(quote(\"'\",$1))' *.[ch] /dev/null \| sed 's/^\\\\\\(.*\\\\\\):\\\\\\(.*\\\\\\):.*/!^    \\1    \\2/'"
  42.  browse!! !*
  43. }
  44.  
  45. if gui=="x11"
  46. then {
  47.  alias courier {
  48.   "Use courier fonts of a given size
  49.   set normalfont=*-courier-medium-r-*-!(18)^-*
  50.   set italicfont=*-courier-medium-o-*-!(18)^-*
  51.   set boldfont=*-courier-bold-r-*-!(18)^-*
  52.  }
  53. }
  54.  
  55. alias copying split (elvispath("license"))
  56.  
  57. alias howto {
  58.  "Search elvis' "How To" appendix.  ! makes it try harder.
  59.  if "!?" == "!!"
  60.  then split +/*!1.*!2.*!3.*!4 (elvispath("howto.html"))
  61.  else split +/^<dt>.*!1.*!2.*!3.*!4 (elvispath("howto.html"))
  62. }
  63.  
  64. alias cbload {
  65.  "Load cut-buffers from a file
  66.  local b report=0
  67.  let b=buffer
  68.  if "!1" == ""
  69.  then error cbload requires a file name
  70.  e !1
  71.  %s:^--CBS-- \([a-z]\)$:+;/^--CBS--/-1 y \1:x
  72.  eval buffer (b)
  73. }
  74.  
  75. alias cbsave {
  76.  "Save cut-buffers to a file
  77.  local a b report=0
  78.  let b = buffer
  79.  if "!1" == ""
  80.  then error cbsave requires a file name
  81.  e !1
  82.  %d
  83.  let a = 'a'
  84.  while a <= 'z'
  85.  do {
  86.   if buffer("Elvis cut buffer "char(a))
  87.   then {
  88.    eval $ a --CBS-- (char(a))
  89.    eval $ put (char(a))
  90.   }
  91.   let a = a + 1
  92.  }
  93.  $ a --CBS--  
  94.  w!?
  95.  eval buffer (b)
  96. }
  97.  
  98. alias config {
  99.  "Describe the configuration of this elvis
  100.  local m n o
  101.  let m="normal"
  102.  let m=m (feature("syntax") ? " syntax")
  103.  let m=m (feature("hex") ? " hex")
  104.  let m=m (feature("html") ? " html man tex")
  105.  let n=(feature("ftp") ? "ftp":"none")
  106.  let n=n (feature("http") ? " http")
  107.  let o=(feature("showtag") ? " showtag")
  108.  let o=o (feature("lpr") ? " lpr")
  109.  let o=o (feature("alias") ? " alias")
  110.  let o=o (feature("mkexrc") ? " mkexrc")
  111.  let o=o (feature("complete") ? " complete")
  112.  let o=o (feature("ram") ? " ram")
  113.  calc "Elvis version:     " version
  114.  calc "Display modes:     " m
  115.  calc "Network protocols: " n
  116.  calc "Other features:   " o
  117. }
  118.  
  119. alias left {
  120.  "Move text to the left side of each line
  121.  local report=0
  122.  !%s/^\s*
  123.  !%s/\s*$
  124. }
  125.  
  126. alias right {
  127.  "Move text to the right side of each line
  128.  local w report=0
  129.  !%left
  130.  try !%s/ \{2,}/ /g
  131.  let w = (textwidth == 0) ? columns : textwidth
  132.  eval !%s/.$/&("" << w)
  133.  eval !%s/^\\\(.\\{(w)}\\\).*/\\1
  134.  !%s/^\(.*[^ ]\)\( \+\)$/\2\1/
  135. }
  136.  
  137. alias center {
  138.  "Move text to the center of each line
  139.  local report=0
  140.  !%right
  141.  !%s/  / /g
  142. }
  143.  
  144. alias rot13 {
  145.  "Perform rot-13 encryption/decryption
  146.  local i report=0
  147.  let i=0
  148.  while i < 13
  149.  do {
  150.   try eval !%s/(char(i + 'a'))/<TEMP>/g
  151.   try eval !%s/(char(i + 'n'))/(char(i + 'a'))/g
  152.   try eval !%s/<TEMP>/(char(i + 'n'))/g
  153.   try eval !%s/(char(i + 'A'))/<temp>/g
  154.   try eval !%s/(char(i + 'N'))/(char(i + 'A'))/g
  155.   try eval !%s/<temp>/(char(i + 'N'))/g
  156.   let i=i+1
  157.  }
  158. }
  159.  
  160. alias cfmt {
  161.  "Adjust C or C++ comment block.  Omit the */ line from range.
  162.  local report=0 nosaveregexp
  163.  if !< == !>
  164.  then error you must invoke cfmt with a range of two or more lines
  165.  !>a STOP!!
  166.  try !%s,^\(\s*\)//\s*,\1,
  167.  then {
  168.   "C++ comments, already removed the //
  169.   !%!!fmt
  170.   !<,/^STOP!!$/- s,^\s*,&// ,
  171.  }
  172.  else {
  173.   "C comments, still need to remove the /* or *
  174.   !<s,^\s*\([/ ]\*\)\s*,let a="\1",x
  175.   !%s,^\(\s*\)[/ ]\*\s*,\1,
  176.   !%!!fmt
  177.   eval !< s,^\\s*,&(a) ,
  178.   try !<+,/^STOP!!$/- s,^\s*,& * ,
  179.  }
  180.  /^STOP!!$/d
  181. }
  182.  
  183.  
  184. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  185. " The following were contributed by Ian Utley (iu@apertus.uk.com)
  186.  
  187. alias align {
  188.     "Align any = signs (or other given text) in selected line
  189.     local f=0 i=0 k report=0 nosaveregexp
  190.     "
  191.     " The following if tests to see if we have visually highlighted lines.
  192.     "
  193.     if ( !> !!= "" )
  194.     then {
  195.         !< mark a
  196.         !> mark b
  197.         let f=1
  198.     }
  199.     if ( f == 1)
  200.     then {
  201.         "
  202.         " Initialise i which will store the alignment column.
  203.         " Mark the current line to return the cursor at the end.
  204.         "
  205.         set i=0
  206.         mark z
  207.         "
  208.         " Remove any whitespace before the alignment character.
  209.         "
  210.         'a,'b s/[     ]*!(=)\$/!(=)\$/
  211.         "
  212.         " We could be aligning != <= or >= so we want to keep this letter
  213.         " near. Of course we may not be aligning an equals but we commonly do.
  214.         "
  215.         if ( "!(=)\$" == "=" )
  216.         then {
  217.             'a,'b s/[     ]*\([!!<>]*\)!(=)\$[     ]*/ \1!(=)\$ /
  218.         } 
  219.         "
  220.         "
  221.         let f=0
  222.         'a,'bglobal /!(=)\$/ {
  223.             " 
  224.             " Special case for the top line as -1 will not work.
  225.             "
  226.             if ( current("line") == 1 )
  227.             then {
  228.                 1 insert ""
  229.                 let f=1
  230.             }
  231.             -1
  232.             /!(=)\$
  233.             "
  234.             "
  235.             " Remember the largest column number for alignment.
  236.             "
  237.             if (current("column")>i)
  238.             then let i=current("column")
  239.             "
  240.             " Special case removal
  241.             "
  242.             if ( current("line") > 1 && f == 1)
  243.             then {
  244.                 1 delete
  245.                 let f=0
  246.             }
  247.         }
  248.         "
  249.         " Do the alignment.
  250.         "
  251.         let f=0
  252.         'a,'bglobal /!(=)\$/ {
  253.             " 
  254.             " Special case for the top line as -1 will not work.
  255.             "
  256.             if ( current("line") == 1 )
  257.             then {
  258.                 1i ""
  259.                 let f=1
  260.             }
  261.             -1
  262.             /!(=)\$
  263.             "
  264.             " Not sure why I need to add +1
  265.             "
  266.             let k=i-current("column")+1
  267.             s/\([!!<>]*\)!(=)\$/                                                                                \1!(=)\$/
  268.             eval s/ *\\\( \{(k)\}[!!<>]*!(=)\$\\\)/\1
  269.             "
  270.             " Special case removal
  271.             "
  272.             if ( current("line") > 1 && f == 1 )
  273.             then {
  274.                 1 delete
  275.                 let f=0
  276.             }
  277.         }
  278.         "
  279.         " Return the cursor to the line it was previously on.
  280.         "
  281.         'z
  282.     }
  283. }
  284.  
  285. alias match {
  286.     "Move to the line where the pairing keyword is located
  287.     local a b="" d x y i nowrapscan
  288.     "x and y are lists of matching words -- we'll seek forward from x words
  289.     "and backward from y words.  The words listed here are appropriate for
  290.     "Unix shell scripts.
  291.     set x="if/then/case/do" y="fi/else/esac/done"
  292.     let a=current("word")
  293.     if (a == "")
  294.     then error Cursor is not on a word
  295.     while d=="" && x!="."
  296.     do {
  297.     if a==dirfile(x)
  298.     then {
  299.         let b=dirfile(y)
  300.         set d=forward
  301.     }
  302.     if a==dirfile(y)
  303.     then {
  304.         let b=dirfile(x)
  305.         set d=backward
  306.     }
  307.     let x=dirdir(x)
  308.     let y=dirdir(y)
  309.     }
  310.     if ( b=="" )
  311.     then error (a) is not a matchable keyword 
  312.     mark c
  313.     set i=1
  314.     if (d=="forward")
  315.     then {
  316.         while ( i != 0 )
  317.         do {
  318.             set i=0
  319.             try eval /\<(b)\>
  320.             else {
  321.                 " Failed to locate a match
  322.                 'c
  323.                 error No matching (b) located
  324.             }
  325.             mark d
  326.             eval 'c,'d global /\<(a)\>/ let i=i+1
  327.             eval 'c,'d global /\<(b)\>/ let i=i-1
  328.         }
  329.     }
  330.     if (d=="backward") 
  331.     then {
  332.         while ( i != 0 )
  333.         do {
  334.             set i=0
  335.             try eval ?\<(b)\>
  336.             else {
  337.                 " Failed to find a match
  338.                 'c
  339.                 error No matching (b) located
  340.             }
  341.             mark d
  342.             eval 'd,'c global /\<(a)\>/ let i=i+1
  343.             eval 'd,'c global /\<(b)\>/ let i=i-1
  344.             " global command has moved cursor back to 'c
  345.             'd
  346.         }
  347.     }
  348. }
  349.