// -*- ASCII:EDT -*- // Auto Response to: \label{} // suggests a name for the label // (schlicht 20010918) //////////////////////////////// BeginGroup; SetTracking(0); CMD("Char Left"); Mark(0); LetReg(0,""); LetRegNum(1,%l); SaveFind; SetFindTextSelect(1); SetSearchSelected; SetSearchCurrentDoc; SetSearchCyclic(0); SetSearchEntire(0); SetSearchForward(0); SetSearchInline(0); SetRegEx(1); SetSearchCaseSensitive(1); SetNotFoundNotify(0); SetFindStr("\\{begin\{*\}}|{{part|chapter|{@{sub}section}|caption}\{*\}}|{footnote\{}"); // Do you know more labelable items (not environments)? Tell me. SearchReset; IfFound(!"> RestoreFind;> Refresh;> GetSel(0,0);> // Does this make sense? IfNum(%!1-5,%l,'>',> 'Prompt(''The last labelable item (""%!0"")%\is further than five lines away.%\> It is supposed to be good style to put the label directly after the anchor.%\%\> Do you want to continue?'',1,3,'''',> ''Goto(0);> CMD(|Delete|);> CMD(|Select Word Left|);> CMD(|Delete|);> SetTracking(1);> Refresh;> Exit;'');> ');> ","RestoreFind;> SetSel(0);> Goto(0);> CMD('Char Right');> SetTracking(1);> Refresh;> Prompt('I didn''t find anything to attach a label to!',2,1);> Exit;> "); // ** Suggest a name for the label: SetOK(1); // ... but not if it's an environment FindInString("%!0","\begin",1,2,0010,0); IfOK("LetReg(1,'');",> !"GetLength(3,'%!0');> SetOK(1);> FindInString('%!0','{',1,2,0000,0);> ExtractByIndex(1,'%!0',%!2+1,%!3-2);"); // get the words... LetRegNum(3,-1); LetReg(9,""); Loop(!`> SetOK(1);> FindInString("%!1","+{^ }",2,3,1001,%!3+1);> IfOK(!"> // ... only if they have more than 3 letters: IfNum(%!3-%!2,2,'>',> !'ExtractByIndex(8,''%!1'',%!2,%!3);> // ... and take the first 7 letters only: ExtractByIndex(8,''%!8'',0,6);> LetReg(9,''%!9%!8-'');');",> !"GetLength(3,'%!9');> IfNum(%!3,0,'>',> !'ReplaceInString(''%!9'','''',%!3-1,%!3-1,0,9);',> 'LetReg(9,''NAME'');');> Stop;");> `); // ** The type (fancyref compatible): SetOK(1); FindInString("%!0","\\{part|chapter|{@{sub}section|footnote}",1,2,0011,0); IfOK(!`> ExtractByIndex(1,"%!0",1,%!2);> IfStr("%!1","chapter","=","LetReg(1,'chap');");> IfStr("%!1","section","=","LetReg(1,'sec');");> IfStr("%!1","subsection","=","LetReg(1,'ssec');");> IfStr("%!1","subsubsection","=","LetReg(1,'sssec');");> IfStr("%!1","footnote","=","LetReg(1,'fn');");> LetReg(9,"%!1:%!9");> `,!`> SetOK(1);> FindInString("%!0","\\begin\{*\}",1,2,1);> IfOK(!"ExtractByIndex(2,'%!0',7,%!2-1);> IfStr('%!2','enumerate','=','LetReg(1,|enum|);');> IfStr('%!2','figure','=','LetReg(1,|fig|);');> IfStr('%!2','equation','=','LetReg(1,|eq|);');> ");> IfStr("%!1","0","=",!"ExtractByIndex(1,'%!0',7,9);");> LetReg(9,'%!1:%!9');> `); // ** Check whether a same label already exists: Loop(!`> EnterReg(9,"%!0 ...","Label for:");> GDIReset;> GDISetPage("Label","");> GDIUpdate;> CopyFromClipboard(2);> GDICopy;> CopyFromClipboard(1);> CopyToClipboard("%!2",0);> FindInString("%!1","<%!9>",2,3,0011,0);> IfOK(!"> Prompt('This label already exists. Please choose another name.',3,0,'',> 'Goto(0);> SetTracking(1);> Refresh;> EndGroup;'> );",> "Stop;");> `); // Finish Goto(0); Ins("%!9"); CMD("Char Right"); GDIUpdate; SetTracking(1); Refresh; EndGroup; LetReg(0,"");LetReg(1,""); LetReg(2,"");LetReg(3,""); LetReg(8,"");LetReg(9,""); End; /////////////////////////////////// // This macro suggests a name for a // label. // It's meant to be the response to // the Active String "\label{}". // // If a caption or some kind of // section command exists, it // suggests a name consisting of // parts of its words. This is // prefixed by three letters for // the type of the label. // // R Schlicht w.m.l@gmx.net /////////////////////////////////// $Id: autoLabel.edt,v 1.2 2006-11-30 17:09:17+01 schlicht Exp schlicht $