Changeset 3318
- Timestamp:
- Dec 11, 2018, 2:58:35 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/netlabs/macros/stdprocs.e ¶
r3317 r3318 419 419 endif 420 420 421 ; PCENTER_MARK: center the strings between the block marks 421 ; --------------------------------------------------------------------------- 422 ; Center the text within the mark, linewise. Reduces 1599 as EndCol to 78 423 ; to place the text at a useful place. Replaces trailing and leading 424 ; whitespace with spaces. Handle cases when one or both sides don't have 425 ; whitespace. Allows for all mark types. 422 426 defproc pcenter_mark 423 if marktype() = 'BLOCK' then 424 getmark firstline, lastline, firstcol, lastcol, fileid 425 elseif marktype() = 'LINE' then 426 getmark firstline,lastline, firstcol, lastcol, fileid 427 parse value pmargins() with firstcol lastcol . 428 elseif marktype() = '' then 429 getfileid fileid 430 parse value pmargins() with firstcol lastcol . 431 firstline = .line 432 lastline = .line 433 else 434 sayerror CHAR_INVALID__MSG 435 stop 436 endif 437 sz = lastcol + 1 - firstcol 438 for i=firstline to lastline 439 getline line, i, fileid 440 inblock = strip( substr( line, firstcol, sz)) 441 if inblock = '' then iterate endif 442 replaceline strip( overlay( center( inblock, sz), line, firstcol), 'T'), i, fileid 443 endfor 427 getmark markfirstline, marklastline, markfirstcol, marklastcol, markfid 428 getfileid fid 429 if fid <> markfid then 430 sayerror OTHER_FILE_MARKED__MSG 431 return 432 endif 433 434 StartCol = markfirstcol 435 EndCol = marklastcol 436 mt = marktype() 437 if mt = 'CHAR' then 438 if markfirstline = marklastline then 439 -- OK 440 EndCol = marklastcol 441 else 442 if marklastcol < markfirstcol then 443 marklastline = marklastline - 1 444 marklastcol = 1599 445 endif 446 -- Change to block mark 447 call pset_mark( markfirstline, marklastline, markfirstcol, 1599, 'BLOCK', markfid) 448 EndCol = marklastcol 449 endif 450 elseif mt = 'LINE' then 451 parse value pmargins() with StartCol EndCol . 452 endif 453 454 if EndCol = 1599 then 455 EndCol = 78 456 endif 457 458 do Line = markfirstline to marklastline 459 getline LineStr, Line 460 461 -- Calculate length of whitespace before and after the text part 462 TmpLineStr = translate( LineStr, ' ', \t) 463 StartTextCol = Max( 1, verify( TmpLineStr, ' ')) 464 EndTextCol = length( strip( TmpLineStr, 'T')) 465 LSpaceLen = Max( 0, StartTextCol - StartCol) 466 RSpaceLen = Max( 0, EndCol - EndTextCol) 467 -- Calculate NewLSpaceLen for centering text 468 NewLSpaceLen = (LSpaceLen + RSpaceLen) % 2 469 NewRSpaceLen = (LSpaceLen + RSpaceLen) - NewLSpaceLen 470 if NewLSpaceLen > 0 then 471 472 -- Replace trailing blanks with NewRSpaceLen 473 SearchStr = substr( LineStr, EndTextCol + 1, RSpaceLen) 474 ReplaceStr = copies( ' ', NewRSpaceLen) 475 if RSpaceLen > 0 then 476 rcx = SearchReplaceLine( SearchStr, ReplaceStr, 1, '', Line, EndTextCol + 1, EndCol) 477 else 478 call psave_pos( SavedPos) 479 .lineg = Line 480 .col = EndTextCol + 1 481 keyin ReplaceStr 482 call prestore_pos( SavedPos) 483 endif 484 485 -- Replace leading blanks with NewLSpaceLen 486 SearchStr = substr( LineStr, StartCol, LSpaceLen) 487 ReplaceStr = copies( ' ', NewLSpaceLen) 488 if LSpaceLen > 0 then 489 rcx = SearchReplaceLine( SearchStr, ReplaceStr, 1, '', Line, StartCol, StartTextCol - 1) 490 else 491 call psave_pos( SavedPos) 492 .lineg = Line 493 .col = StartCol 494 keyin ReplaceStr 495 call prestore_pos( SavedPos) 496 endif 497 endif 498 enddo 499 500 return 444 501 445 502 compile if 0 -- The following two routines are unused; why waste space?? LAM 503 ; --------------------------------------------------------------------------- 446 504 ; PDISPLAY_MARGINS: put the margins mark on the current line 447 505 defproc pdisplay_margins() … … 457 515 return 0 458 516 517 ; --------------------------------------------------------------------------- 459 518 ; PDISPLAY_TABS: put the tab stops on the current line 460 519 defproc pdisplay_tabs() … … 480 539 compile endif 481 540 541 ; --------------------------------------------------------------------------- 482 542 ; Check if file already exists in ring 483 543 defproc pfile_exists … … 490 550 return zzfileid <> '' 491 551 552 ; --------------------------------------------------------------------------- 492 553 ; Find first blank line after the current one. Make that the new current 493 554 ; line. If no such line is found before the end of file, don't change the … … 505 566 endfor 506 567 568 ; --------------------------------------------------------------------------- 507 569 ; different from PE 508 570 defproc pfirst_nonblank … … 513 575 endif 514 576 577 ; --------------------------------------------------------------------------- 515 578 ; Move cursor to end of line like end_line, but ignore trailing blanks 516 579 defproc pEnd_Line
Note:
See TracChangeset
for help on using the changeset viewer.