Difference between revisions of "Using your own editor"
(Added larger Vim wrapper, written by Tom Potts.) |
m (→Larger Program: Reworded the warning - it only overwrites the item.) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 26: | Line 26: | ||
==Larger Program== | ==Larger Program== | ||
+ | [[Image:Qm-vim.png|thumb|right|Editing the VIM program in Vim]] | ||
Written by Tom Potts. | Written by Tom Potts. | ||
− | This is a more sophisticated program with the beginnings of some extra | + | This is a more sophisticated program with the beginnings of some extra usefulness. The syntax highlighting is naive, but useful; the dynamic-file editing is dangerous, but works okay, and it is robust enough to work with multifiles and Q-pointers. If enough people think this is worthwhile, I'll clean it up a bit and put it in the main repository. Oh, and there has to be a better way to do the 'itempath' stuff -- any ideas, anyone? |
+ | |||
+ | '''DISCLAIMER''': | ||
+ | If you use this program to edit an item in a dynamic file, it '''will''' overwrite it when you have finished editing. It is very unsafe, and I'm not happy about it, but if you use it carefully it should be okay. If you think of a neat way of avoiding this problem, please let me know! | ||
===Installation=== | ===Installation=== | ||
− | + | Save this program in GPL.BP as 'ITEMPATH', and compile it. | |
+ | <pre> | ||
+ | function itempath(item.id) | ||
+ | |||
+ | $catalogue global | ||
+ | |||
+ | path = "" | ||
+ | |||
+ | for i = 1 to len(item.id) | ||
+ | char = item.id[i,1] | ||
+ | begin case | ||
+ | case char = '"' | ||
+ | path := '%Q' | ||
+ | case char = '%' | ||
+ | path := '%P' | ||
+ | case char = '*' | ||
+ | path := '%A' | ||
+ | case char = '+' | ||
+ | path := '%V' | ||
+ | case char = ',' | ||
+ | path := '%C' | ||
+ | case char = '/' | ||
+ | path := '%S' | ||
+ | case char = ':' | ||
+ | path := '%X' | ||
+ | case char = ';' | ||
+ | path := '%Y' | ||
+ | case char = '<' | ||
+ | path := '%L' | ||
+ | case char = '=' | ||
+ | path := '%E' | ||
+ | case char = '>' | ||
+ | path := '%G' | ||
+ | case char = '?' | ||
+ | path := '%Z' | ||
+ | case char = '\' | ||
+ | path := '%B' | ||
+ | case 1 | ||
+ | path := char | ||
+ | end case | ||
+ | next i | ||
+ | |||
+ | return path | ||
+ | |||
+ | end | ||
+ | </pre> | ||
+ | Save this program in GPL.BP as 'VIM' and compile it. | ||
<pre> | <pre> | ||
$include keys.h | $include keys.h | ||
Line 512: | Line 562: | ||
let b:current_syntax = "qmbasic" | let b:current_syntax = "qmbasic" | ||
</pre> | </pre> | ||
− | Finally, | + | To enable editing of non-directory files (see the note above before enabling this), create a directory '$VIMFILE' in /usr/qmsys, and create the NEWVOC entry '$VIMFILE': |
+ | File - Vim temporary file | ||
+ | @QMSYS/$VIMFILE | ||
+ | Finally, save this entry as 'VIM' in NEWVOC | ||
V | V | ||
CA | CA | ||
$VIM | $VIM | ||
and then use UPDATE.ACCOUNT to copy it to your VOC. | and then use UPDATE.ACCOUNT to copy it to your VOC. |
Latest revision as of 12:07, 1 May 2009
There are two programs listed below, both of which accomplish similar goals. The first is the simplest to install, while the second is more powerful. Note that either may be altered to use your favourite editor, but that the second is much more closely tied to Vim.
Small Script
This little script was given to me by Tom Hoogenboom:
To use your favorite editor, just change "leafpad" to "vi", "pico", etc.
Save the program below in your GPL.BP file and globally catalog it.
* 'nano' caller for system editor s = @sentence s = trim(s) convert ' ' to @am in s filename = s<2> itemname = s<3> * es = \sh nano \:@path:\/\:filename:\/\:itemname crt es execute es * end
Note - this currently doesn't work when OpenQM is executed by xinetd under 2.6-6. If you execute OpenQM from the command line it works ok. It appears that the I/O redirection is somehow broken when OpenQM is executed as a server (accessed via telnet <hostname> <port>)
Larger Program
Written by Tom Potts.
This is a more sophisticated program with the beginnings of some extra usefulness. The syntax highlighting is naive, but useful; the dynamic-file editing is dangerous, but works okay, and it is robust enough to work with multifiles and Q-pointers. If enough people think this is worthwhile, I'll clean it up a bit and put it in the main repository. Oh, and there has to be a better way to do the 'itempath' stuff -- any ideas, anyone?
DISCLAIMER: If you use this program to edit an item in a dynamic file, it will overwrite it when you have finished editing. It is very unsafe, and I'm not happy about it, but if you use it carefully it should be okay. If you think of a neat way of avoiding this problem, please let me know!
Installation
Save this program in GPL.BP as 'ITEMPATH', and compile it.
function itempath(item.id) $catalogue global path = "" for i = 1 to len(item.id) char = item.id[i,1] begin case case char = '"' path := '%Q' case char = '%' path := '%P' case char = '*' path := '%A' case char = '+' path := '%V' case char = ',' path := '%C' case char = '/' path := '%S' case char = ':' path := '%X' case char = ';' path := '%Y' case char = '<' path := '%L' case char = '=' path := '%E' case char = '>' path := '%G' case char = '?' path := '%Z' case char = '\' path := '%B' case 1 path := char end case next i return path end
Save this program in GPL.BP as 'VIM' and compile it.
$include keys.h $include syscom parser.h $internal $catalogue $VIM equate vimfile to "$VIMFILE" equate qmbasic.vim to "/usr/qmsys/qmbasic.vim" equate filetype$unset to 0 equate filetype$null to 1 equate filetype$basic to 2 equate filetype$paragraph to 3 equate filetype$proc to 4 deffun itempath(id) filename = "" filetype = filetype$unset itemids = "" *** Get variables call !parser(parser$reset, 0, @sentence, 0) call !parser(parser$get.token, token.type, string, keyword) ;* Verb * Get the file (using mfile rather than get.token for multifiles) call !parser(PARSER$MFILE, token.type, filename, keyword) if filename = "" then * prompted.for.file.name = @true display sysmsg(6501) : ;* File name? input filename * filename = trimf(trimb(filename)) * if filename = "" then goto exit.sed if filename = "" then stop end else * prompted.for.file.name = @false if keyword = KW$DICT then * dict.flag = "DICT" call !parser(PARSER$MFILE, token.type, filename, keyword) filename = "DICT " : filename end end *** Validate file open filename to filevar else filename = upcase(filename) open filename to filevar else crt "Could not open file." stop end end using.vimfile = @false if fileinfo(filevar, FL$TYPE) # FL$TYPE.DIR then open vimfile to vimfilevar then using.vimfile = @true end else crt "vim can only act on directory files." stop end end if filetype = filetype$unset then * If there exists a '.OUT' file... open filename : ".OUT" to dummyfile then filetype = filetype$basic close dummyfile end else * ... end end if (using.vimfile) then path = fileinfo(vimfilevar, FL$PATH) end else path = fileinfo(filevar, FL$PATH) end *** Get the items to edit loop call !parser(parser$get.token, token.type, string, keyword) until token.type = parser$end * crt " ~" : string itemids<-1> = string repeat command = "vim" for i = 1 to dcount(itemids, @am) read record from filevar, itemids<i> else * We shouldn't really convert to uppercase. * read record from filevar, upcase(itemids<i>) then * itemids<i> = upcase(itemids<i>) * end end if (using.vimfile) then execute "copy from " : filename : " to " : vimfile : " " : itemids<i> : ", " : @userno : itemids<i> : " overwriting" capturing junk item.path = itempath(@userno : itemids<i>) end else item.path = itempath(itemids<i>) end command := " " : path : "/" : item.path next i command = swap(command, "$", "\$") command = swap(command, "&", "\&") if filetype = filetype$basic then command := " -S " : qmbasic.vim end os.execute command if (using.vimfile) then for i = 1 to dcount(itemids, @am) execute "copy from " : vimfile : " to " : filename : " " : @userno : itemids<i> : ", " : itemids<i> : " overwriting deleting" capturing junk next i end end
To enable syntax highlighting, save this file as 'qmbasic.vim' in /usr/qmsys.
syntax clear syntax case ignore "set autoindent set tabstop=3 set shiftwidth=3 set nu function GetQMBasicIndent() let bob = getline(".") if (match(bob, '\cthen *$') >= 0) return indent(".") + 3 endif return -1 endfunction set indentexpr=GetQMBasicIndent() set smartindent setlocal iskeyword+=. setlocal iskeyword+=$ setlocal iskeyword+=@-@ setlocal iskeyword+=! "syn keyword qmbasicCompilerDir $catalogue $catalog "syn keyword qmbasicCompilerDir $debug "syn keyword qmbasicCompilerDir $define "syn keyword qmbasicCompilerDir $execute "syn keyword qmbasicCompilerDir $ifdef $ifndef "syn keyword qmbasicCompilerDir $include ""not sure whether this is a CompilerDir, or a Statement "syn keyword qmbasicCompilerDir include "syn keyword qmbasicCompilerDir $list "syn keyword qmbasicCompilerDir $mode "syn keyword qmbasicCompilerDir $nocase.strings "syn keyword qmbasicCompilerDir $qmcall syn region qmbasicCompilerDir start="^[ \t]*#" end="$" syn region qmbasicCompilerDir start="^[ \t]*\$" end="$" syn region qmbasicCompilerDir start="^[ \t]*include" end="$" "syntax region qmbasicThenBlock start=/then$/ end=/end/ contains=qmbasicThenBlock contains=qmbasicElseBloc "syntax region qmbasicElseBlock start=/else$/ end=/end/ contains=qmbasicThenBlock contains=qmbasicElseBlock syn keyword qmbasicAtVar @am @fm @im @sm @svm @tm @vm syn keyword qmbasicAtVar @true @false syn keyword qmbasicAtVar @abort.code @abort.message syn keyword qmbasicAtVar @ans @command @command.stack @crthigh @crtwide syn keyword qmbasicAtVar @data.pending @date @day @ds @file.name syn keyword qmbasicAtVar @hostname @id @ip.addr @itype.mode @level syn keyword qmbasicAtVar @logname @lptrhigh @lptrwide @month @nb syn keyword qmbasicAtVar @ni @option @parasentence @path @pib @pob syn keyword qmbasicAtVar @qmsys @record @selected @sentence @sib @sob syn keyword qmbasicAtVar @system.return.code @sys.bell @term.type @time syn keyword qmbasicAtVar @transaction.id @transaction.level syn keyword qmbasicAtVar @trigger.return.code @tty @user syn keyword qmbasicAtVar @user0 @user1 @user2 @user4 @user4 syn keyword qmbasicAtVar @userno @user.no @user.return.code syn keyword qmbasicAtVar @voc @who @year @year4 syn keyword qmbasicStatement abort aborte abortm syn keyword qmbasicFunction abs abss syn keyword qmbasicFunction accept.socket.connection syn keyword qmbasicFunction acos asin atan syn keyword qmbasicFunction alpha syn keyword qmbasicFunction ands syn keyword qmbasicFunction arg arg.count syn keyword qmbasicFunction ascii syn keyword qmbasicFunction assigned "no, not quite right syn keyword qmbasicStatement begin transaction syn keyword qmBasicFunction bindkey syn keyword qmBasicFunction bitand bitnot bitor bitxor syn keyword qmBasicFunction bitset bitreset bittest syn keyword qmbasicStatement break syn keyword qmbasicStatement call enter "important syn keyword qmbasicStatement case syn keyword qmbasicFunction catalogued() "syn keyword qmbasicFunction cataloged() syn keyword qmbasicFunction cats syn keyword qmbasicStatement chain syn keyword qmbasicFunction change swap syn keyword qmbasicFunction char syn keyword qmbasicStatement class "not quite right syn keyword qmbasicStatement clear clearcommon cleardata clearinput inputclear syn keyword qmbasicStatement clearfile syn keyword qmbasicStatement clear data syn keyword qmbasicStatement clear input syn keyword qmbasicStatement clearselect syn keyword qmbasicStatement close closeseq close.socket syn keyword qmbasicFunction col1 col2 syn keyword qmbasicStatement commit "a bit special syn keyword qmbasicStatement common syn keyword qmbasicFunction compare syn keyword qmbasicFunction config syn keyword qmbasicStatement continue "Both of these! syn keyword qmbasicStatement convert "syn keyword qmbasicFunction convert syn keyword qmbasicFunction cos sin tan syn keyword qmbasicFunction count counts dcount syn keyword qmbasicStatement create create.file syn keyword qmbasicFunction create.server.socket syn keyword qmbasicFunction crop syn keyword qmbasicFunction csvdq syn keyword qmbasicStatement data syn keyword qmbasicFunction date syn keyword qmbasicStatement debug syn keyword qmbasicStatement deffun syn keyword qmbasicStatement del "again with the buggery "syn keyword qmbasicFunction delete syn keyword qmbasicStatement delete deleteu syn keyword qmbasicStatement deletelist syn keyword qmbasicStatement deleteseq syn keyword qmbasicStatement dimension dim syn keyword qmbasicFunction dir syn keyword qmbasicStatement display crt syn keyword qmbasicFunction div syn keyword qmbasicFunction downcase upcase syn keyword qmbasicFunction dparse dparse.csv syn keyword qmbasicFunction dtx syn keyword qmbasicFunction ebcdic syn keyword qmbasicStatement echo "a bit special syn keyword qmbasicStatement end syn keyword qmbasicFunction env syn keyword qmbasicFunction eqs syn keyword qmbasicStatement equate equ syn keyword qmbasicStatement errmsg syn keyword qmbasicStatement execute perform syn keyword qmbasicStatement exit syn keyword qmbasicFunction exp syn keyword qmbasicFunction extract syn keyword qmbasicFunction field fields syn keyword qmbasicFunction fieldstore syn keyword qmbasicStatement file syn keyword qmbasicFunction fileinfo syn keyword qmbasicStatement filelock fileunlock syn keyword qmbasicStatement find findstr syn keyword qmbasicStatement flush syn keyword qmbasicFunction fmt fmts syn keyword qmbasicFunction fold folds syn keyword qmbasicStatement footing syn keyword qmbasicStatement for next syn keyword qmbasicStatement formlist "special? syn keyword qmbasicStatement function syn keyword qmbasicFunction ges syn keyword qmbasicStatement getlist syn keyword qmbasicFunction get.messages syn keyword qmbasicFunction getnls syn keyword qmbasicFunction get.port.params syn keyword qmbasicFunction getpu syn keyword qmbasicFunction getrem syn keyword qmbasicStatement gosub goto syn keyword qmbasicFunction gts syn keyword qmbasicStatement heading syn keyword qmbasicStatement hush syn keyword qmbasicFunction iconv iconvs syn keyword qmbasicFunction idiv "a bit special syn keyword qmbasicStatement if syn keyword qmbasicFunction ifs syn keyword qmbasicStatement in syn keyword qmbasicFunction index indexs syn keyword qmbasicFunction indices syn keyword qmbasicFunction inmat "also input @ syn keyword qmbasicStatement input syn keyword qmbasicStatement inputcsv syn keyword qmbasicStatement inputfield syn keyword qmbasicStatement ins syn keyword qmbasicFunction insert syn keyword qmbasicFunction int syn keyword qmbasicFunction itype syn keyword qmbasicFunction keycode syn keyword qmbasicStatement keyedit syn keyword qmbasicStatement keyexit syn keyword qmbasicFunction keyin keyinc keyinr syn keyword qmbasicFunction keyready syn keyword qmbasicStatement keytrap syn keyword qmbasicFunction len lens syn keyword qmbasicFunction les syn keyword qmbasicFunction listindex syn keyword qmbasicFunction ln syn keyword qmbasicStatement local "and again syn keyword qmbasicStatement locate "syn keyword qmbasicFunction locate syn keyword qmbasicStatement lock syn keyword qmbasicStatement logmsg "special syn keyword qmbasicStatement loop repeat syn keyword qmbasicFunction lower syn keyword qmbasicFunction lts syn keyword qmbasicStatement mark.mapping syn keyword qmbasicStatement mat matbuild matparse syn keyword qmbasicStatement matread matreadl matreadu matreadcsv syn keyword qmbasicStatement matwrite matwriteu syn keyword qmbasicFunction matchfield syn keyword qmbasicFunction max[imum] min[imum] syn keyword qmbasicFunction mod mods syn keyword qmbasicStatement nap syn keyword qmbasicFunction neg negs syn keyword qmbasicFunction nes syn keyword qmbasicFunction nobuf syn keyword qmbasicFunction not nots syn keyword qmbasicStatement null syn keyword qmbasicFunction num nums syn keyword qmbasicFunction object syn keyword qmbasicFunction objinfo syn keyword qmbasicFunction oconv oconvs "umm... "syn keyword qmbasicStatement on gosub "syn keyword qmbasicStatement on goto syn keyword qmbasicStatement open openpath openseq syn keyword qmbasicFunction open.socket syn keyword qmbasicFunction ors syn keyword qmbasicFunction os.error syn keyword qmbasicStatement os.execute syn keyword qmbasicFunction outerjoin syn keyword qmbasicStatement page syn keyword qmbasicStatement pause syn keyword qmbasicStatement precision syn keyword qmbasicStatement print printcsv "a load of printer stuff syn keyword qmbasicStatement printer "This is even worse - it's a function AND a statement, but the function is depreciated "syn keyword qmbasicFunction printer.setting syn keyword qmbasicStatement printerr inputerr syn keyword qmbasicStatement private syn keyword qmbasicStatement procread procwrite "special syn keyword qmbasicStatement program syn keyword qmbasicStatement prompt syn keyword qmbasicStatement public syn keyword qmbasicFunction pwr syn keyword qmbasicFunction quote dquote syn keyword qmbasicFunction raise syn keyword qmbasicStatement randomize syn keyword qmbasicFunction rdiv syn keyword qmbasicStatement read readu readv readvl readvu syn keyword qmbasicStatement readblk readcsv readseq syn keyword qmbasicStatement readl syn keyword qmbasicStatement readlist "special? syn keyword qmbasicStatement readnext syn keyword qmbasicFunction recordlocked syn keyword qmbasicStatement recordlockl recordlocku syn keyword qmbasicStatement release "more! syn keyword qmbasicFunction rem "syn keyword qmbasicStatement rem[ark] "and again! syn keyword qmbasicStatement remove "syn keyword qmbasicFunction remove syn keyword qmbasicFunction replace syn keyword qmbasicStatement restore.screen "special? syn keyword qmbasicStatement return syn keyword qmbasicFunction reuse syn keyword qmbasicFunction rnd syn keyword qmbasicStatement rollback syn keyword qmbasicFunction save.screen syn keyword qmbasicStatement savelist syn keyword qmbasicStatement seek syn keyword qmbasicStatement select selectn selectv selecte syn keyword qmbasicStatement selectindex selectleft selectright syn keyword qmbasicFunction selectinfo syn keyword qmbasicFunction sentence syn keyword qmbasicFunction seq syn keyword qmbasicFunction server.addr syn keyword qmbasicStatement set.arg syn keyword qmbasicStatement set.exit.status syn keyword qmbasicFunction set.port.params syn keyword qmbasicFunction set.socket.mode syn keyword qmbasicStatement setleft setright syn keyword qmbasicStatement setnls syn keyword qmbasicStatement setpu syn keyword qmbasicStatement setrem syn keyword qmbasicFunction shift syn keyword qmbasicStatement sleep rqm syn keyword qmbasicFunction socket.info syn keyword qmbasicFunction soundex syn keyword qmbasicFunction space syn keyword qmbasicFunction spaces syn keyword qmbasicFunction splice syn keyword qmbasicFunction sqrt syn keyword qmbasicFunction squote syn keyword qmbasicStatement sselect "another double syn keyword qmbasicFunction status "syn keyword qmbasicStatement status syn keyword qmbasicStatement stop stope stopm syn keyword qmbasicFunction str strs "really a function? syn keyword qmbasicFunction subr "special syn keyword qmbasicStatement subroutine syn keyword qmbasicFunction substitute syn keyword qmbasicFunction substrings syn keyword qmbasicFunction sum summation swapcase system tan terminfo time timedata trans xlate rtrans trim trimb trimbs trimf trimfs trims ttyget unassigned upcase vslice syn keyword qmbasicStatement tclread timeout ttyset unlock until wake weofseq write writeu writeblk writecsv writeseqf writev writevu syn keyword qmbasicFunction write.socket xtd "special syn keyword qmbasicStatement while "transaction "general keywords syn keyword qmbasicKeyword then else on off to and or from do syn keyword qmbasicKeyword capturing returning rtnlist passlist setting "syntax match qmbasicFunction // nextgroup= "syntax match qmbasicLineContinue /~/ contained syn region qmbasicString start=/"/ end=/"/ oneline syn region qmbasicString start=/'/ end=/'/ oneline syn region qmbasicString start=/\\/ end=/\\/ oneline "syn region qmbasicComment start="^[ \t]*'" end="$" contains=basicTodo syn region qmbasicComment start="REM " end="$" syn region qmbasicComment start="REMARK " end="$" "includes REMARK syn region qmbasicComment start="^[ \t]*\*" end="$" syn region qmbasicComment start="^[ \t]*!" end="$" "This is a bit of a cheat syn region qmbasicComment start=";[ \t]*\*" end="$" syn region qmbasicComment start=";[ \t]*!" end="$" "syn match qmbasicMathsOperator "[+*^=-]" "syn match qmbasicMathsOperator "-\|=\|[:<>+\*^/\\]\|AND\|OR" " Assign colours command -nargs=+ HiLink hi def link <args> HiLink qmbasicStatement Statement HiLink qmbasicString String HiLink qmbasicComment Comment HiLink qmbasicFunction Function HiLink qmbasicCompilerDir Special HiLink qmbasicAtVar Identifier HiLink qmbasicKeyword Statement "temp: "HiLink qmbasicMathsOperator String delcommand HiLink let b:current_syntax = "qmbasic"
To enable editing of non-directory files (see the note above before enabling this), create a directory '$VIMFILE' in /usr/qmsys, and create the NEWVOC entry '$VIMFILE':
File - Vim temporary file @QMSYS/$VIMFILE
Finally, save this entry as 'VIM' in NEWVOC
V CA $VIM
and then use UPDATE.ACCOUNT to copy it to your VOC.