Blast from the past - "prefix macros" for ed.ex by Mike Nelson
- Posted by K_D_R Nov 20, 2012
- 1887 views
Super Star Euphoria Programmer Mike Nelson wrote this very powerful little routine which is kind of like the .commands in the Vi editor.
Essentially you can assign a series of actions to a label of your choice. When you want to execute the commands you type a semi-colon followed by the label and then hit the space bar. The label is erased together with the prefixed semi-colon and then the commands are executed. The possibilities are endless.
-- enter the following routine immediately before the procedure try_auto_complete(char key) function prefix_macro() -- Mike Nelson 10/14/2000 sequence this_line, macro integer count,index,c this_line=buffer[b_line] count=0 index=1 for i=b_col-1 to 1 by -1 do c=this_line[i] if not ((c>='a' and c<='z') or (c>='A' and c<='Z') or (c>='0' and c<='9') or c=';') then if count<2 then return 0 end if index=i+1 exit end if count+=1 end for if this_line[index]!=';' then return 0 end if macro=this_line[index+1..index+count-1] add_queue(repeat(BS,length(macro)+1)) -- insert the labels and commands you write in the following list of elsif clauses: -- I have included several examples to get you started. if equal(macro, "mc") then -- a macro to enter macros add_queue(HOME & "\telsif equal(macro,\"\") then" & CR & "\tadd_queue(\"\")" & END & repeat(BS, 4) & ARROW_UP & HOME & END & repeat(ARROW_LEFT,7)) elsif equal(macro,"aq") then -- add_queue, a macro to enter macros -- in case another "add-queue" line is needed add_queue( END & CR & HOME & "\t\tadd_queue(\"\")" & repeat(ARROW_LEFT,2)) elsif equal(macro, "c") then -- compile the current file shell("euc " & file_name) add_queue(CONTROL_B & CONTROL_T) elsif equal(macro,"il") then -- shroud the current file shell("eushroud " & file_name) add_queue(CONTROL_B & CONTROL_T) elsif equal(macro,"b") then -- bind the current file shell("eubind " & file_name) add_queue(CONTROL_B & CONTROL_T) elsif equal(macro, "mlc") then add_queue("/* */" & repeat(ARROW_LEFT,3)) elsif equal(macro, "sq") then add_queue("\' \'" & repeat(ARROW_LEFT,2)) elsif equal(macro, "dq") then add_queue("\" \"" & repeat(ARROW_LEFT,2)) elsif equal(macro, "bt") then add_queue("` `" & repeat(ARROW_LEFT,2)) else return 0 end if return 1 end function -- next insert prefix macro code in the procedure try_auto_complete(char key) -- check for a keyword that can be automatically completed sequence word, this_line, white_space, leading_white, begin natural first_non_blank, wordnum -- insert this code: if prefix_macro() then -- for the prefix_macro routine return end if ------------------------------
And you are set to go!
Kenneth Rhodes