- Timestamp:
- May 22, 2005 11:53:51 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VSlickMacros/kdev.e
r214 r288 1 /* $Id$ 1 /* $Id$ -*- tab-width: 4 c-indent-level: 4 -*- 2 2 * 3 3 * Visual SlickEdit Documentation Macros. … … 68 68 def 'C-S-S' = k_box_structs 69 69 def 'C-S-T' = odin32_maketagfile 70 def 'C-S-L' = k_style_load 70 71 71 72 //optional stuff … … 2301 2302 } 2302 2303 } 2304 2305 2306 /** 2307 * Takes necessary steps to convert a string to integer. 2308 */ 2309 static int k_style_emacs_var_integer(_str sVal) 2310 { 2311 int i = (int)sVal; 2312 say 'k_style_emacs_var_integer('sVal') -> 'i; 2313 return (int)sVal; 2314 } 2315 2316 2317 /** 2318 * Sets a Emacs style variable. 2319 */ 2320 static int k_style_emacs_var(_str sVar, _str sVal) 2321 { 2322 /* check input. */ 2323 if (sVar == '' || sVal == '') 2324 return -1; 2325 say 'k_style_emacs_var: 'sVar'='sVal; 2326 say 'p_extension='p_extension' p_mode_name='p_mode_name; 2327 2328 2329 /* prepare style changes (C) */ 2330 _str sStyle = name_info(_edit_window().p_index); 2331 typeless iIndentAmount, fExpansion, iMinAbbrivation, fIndentAfterOpenParen, iBeginEndStyle, fIndent1stLevel, iMainStyle, iSwitchStyle, sRest; 2332 parse sStyle with iIndentAmount fExpansion iMinAbbrivation fIndentAfterOpenParen iBeginEndStyle fIndent1stLevel iMainStyle iSwitchStyle sRest; 2333 2334 /* process the variable. */ 2335 switch (sVar) 2336 { 2337 case 'mode': 2338 case 'Mode': 2339 { 2340 switch (sVal) 2341 { 2342 case 'c': 2343 case 'C': 2344 case 'c++': 2345 case 'C++': 2346 case 'cpp': 2347 case 'CPP': 2348 case 'cxx': 2349 case 'CXX': 2350 p_extension = 'c'; 2351 p_mode_name = 'C'; 2352 break; 2353 2354 case 'e': 2355 case 'slick-c': 2356 case 'Slick-c': 2357 case 'Slick-C': 2358 p_extension = 'e'; 2359 p_mode_name = 'Slick-C'; 2360 break; 2361 2362 default: 2363 message('emacs mode "'sVal'" is not known to us'); 2364 return -3; 2365 } 2366 break; 2367 } 2368 2369 case 'c-file-style': 2370 case 'c-indentation-style': 2371 switch (sVal) 2372 { 2373 case 'BSD': 2374 case 'bsd': 2375 iBeginEndStyle = 1 | (iBeginEndStyle & ~3); 2376 p_indent_with_tabs = true; 2377 iIndentAmount = 8; 2378 p_SyntaxIndent = 8; 2379 p_tabs = "+8"; 2380 say 'bsd'; 2381 break; 2382 2383 case 'k&r': 2384 case 'K&R': 2385 iBeginEndStyle = 0 | (iBeginEndStyle & ~3); 2386 p_indent_with_tabs = false; 2387 iIndentAmount = 4; 2388 p_SyntaxIndent = 4; 2389 p_tabs = "+4"; 2390 say 'k&r'; 2391 break; 2392 2393 case 'linux-c': 2394 iBeginEndStyle = 0 | (iBeginEndStyle & ~3); 2395 p_indent_with_tabs = true; 2396 iIndentAmount = 4; 2397 p_SyntaxIndent = 4; 2398 p_tabs = "+4"; 2399 say 'linux-c'; 2400 break; 2401 2402 case 'yet-to-be-found': 2403 iBeginEndStyle = 2 | (iBeginEndStyle & ~3); 2404 p_indent_with_tabs = false; 2405 iIndentAmount = 4; 2406 p_SyntaxIndent = 4; 2407 p_tabs = "+4"; 2408 say 'todo'; 2409 break; 2410 2411 default: 2412 message('emacs "'sVar'" value "'sVal'" is not known to us.'); 2413 return -3; 2414 } 2415 break; 2416 2417 case 'indent-tabs-mode': 2418 p_indent_with_tabs = sVal == 't'; 2419 break; 2420 2421 case 'c-indent-level': 2422 case 'c-basic-offset': 2423 { 2424 int i = k_style_emacs_var_integer(sVal); 2425 if (i > 0 && i <= 16) 2426 { 2427 iIndentAmount = i; 2428 p_SyntaxIndent = i; 2429 } 2430 else 2431 { 2432 message('emacs "'sVar'" value "'sVal'" is out of range.'); 2433 return -4; 2434 } 2435 break; 2436 } 2437 2438 case 'tab-width': 2439 { 2440 int i = k_style_emacs_var_integer(sVal); 2441 if (i > 0 && i <= 16) 2442 p_tabs = '+'i; 2443 else 2444 { 2445 message('emacs "'sVar'" value "'sVal'" is out of range.'); 2446 return -4; 2447 } 2448 break; 2449 } 2450 2451 default: 2452 message('emacs variable "'sVar'" (value "'sVal'") is unknown to us.'); 2453 return -5; 2454 } 2455 2456 /* change the style? (C only) */ 2457 if (p_mode_name == 'C') 2458 { 2459 _str sNewStyle = iIndentAmount' 'fExpansion' 'iMinAbbrivation' 'fIndentAfterOpenParen' 'iBeginEndStyle' 'fIndent1stLevel' 'iMainStyle' 'iSwitchStyle' 'sRest; 2460 if (sNewStyle != sStyle) 2461 { 2462 say ' sStyle='sStyle; 2463 say 'sNewStyle='sNewStyle; 2464 set_name_info(_edit_window().p_index, sNewStyle); 2465 } 2466 } 2467 2468 return 0; 2469 } 2470 2471 2472 /** 2473 * Parses a string with emacs variables. 2474 * 2475 * The variables are separated by new line. Junk at 2476 * the start and end of the line is ignored. 2477 */ 2478 static int k_style_emac_vars(_str sVars) 2479 { 2480 /* process them line by line */ 2481 int iLine = 0; 2482 while (sVars != '' && iLine++ < 20) 2483 { 2484 int iNext, iEnd; 2485 iEnd = iNext = pos("\n", sVars); 2486 if (iEnd <= 0) 2487 iEnd = iNext = length(sVars); 2488 else 2489 iEnd--; 2490 iNext++; 2491 2492 sLine = strip(substr(sVars, 1, iEnd), 'B', " \t\n\r"); 2493 sVars = strip(substr(sVars, iNext), 'L', " \t\n\r"); 2494 //say 'iLine='iLine' sVars='sVars'<eol>'; 2495 //say 'iLine='iLine' sLine='sLine'<eol>'; 2496 if (sLine != '') 2497 { 2498 rc = pos('[^a-zA-Z0-9-_]*([a-zA-Z0-9-_]+)[ \t]*:[ \t]*([^ \t]*)', sLine, 1, 'U'); 2499 //say '0={'pos('S0')','pos('0')',"'substr(sLine,pos('S0'),pos('0'))'"' 2500 //say '1={'pos('S1')','pos('1')',"'substr(sLine,pos('S1'),pos('1'))'"' 2501 //say '2={'pos('S2')','pos('2')',"'substr(sLine,pos('S2'),pos('2'))'"' 2502 //say '3={'pos('S3')','pos('3')',"'substr(sLine,pos('S3'),pos('3'))'"' 2503 //say '4={'pos('S4')','pos('4')',"'substr(sLine,pos('S4'),pos('4'))'"' 2504 if (rc > 0) 2505 k_style_emacs_var(substr(sLine,pos('S1'),pos('1')), 2506 substr(sLine,pos('S2'),pos('2'))); 2507 } 2508 } 2509 return 0; 2510 } 2511 2512 /** 2513 * Searches for Emacs style specification for the current document. 2514 */ 2515 void k_style_load() 2516 { 2517 /* save the position before we start looking around the file. */ 2518 typeless saved_pos; 2519 _save_pos2(saved_pos); 2520 2521 int rc; 2522 2523 /* Check first line. */ 2524 top_of_buffer(); 2525 _str sLine; 2526 get_line(sLine); 2527 strip(sLine); 2528 if (pos('-*-[ \t]+(.*:.*)[ \t]+-*-', sLine, 1, 'U')) 2529 { 2530 _str sVars; 2531 sVars = substr(sLine, pos('S1'), pos('1')); 2532 sVars = translate(sVars, "\n", ";"); 2533 k_style_emac_vars(sVars); 2534 } 2535 2536 /* Look for the "Local Variables:" stuff from the end of the file. */ 2537 bottom_of_buffer(); 2538 rc = search('Local Variables:[ \t]*\n\om(.*)\ol\n.*End:.*\n', '-EU'); 2539 if (!rc) 2540 { 2541 /* copy the variables out to a buffer. */ 2542 _str sVars; 2543 sVars = get_text(match_length("1"), match_length("S1")); 2544 k_style_emac_vars(sVars); 2545 } 2546 2547 _restore_pos2(saved_pos); 2548 } 2549 2303 2550 2304 2551
Note:
See TracChangeset
for help on using the changeset viewer.