Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.sao.ru/hq/sts/linux/doc/nedit/macro/1/1-01.shtml
Дата изменения: Unknown
Дата индексирования: Sat Sep 11 22:14:14 2010
Кодировка:

Поисковые слова: voyager
NEdit

.
.   
NEdit.org
   .

Home
 - News - Download - Documentation - Search - FTP     
.
.
  

Complete word

[Back]

Description

Completes a partly typed word by searching the text. Available in two versions, the version distributed with NEdit v5, which searches forwards and backwards to find a match, and a modifed version which just searches backwards, but gives alternatives with repeated use.

Standard version

# Tuning parameters
ScanDistance = 200

# Search back to a word boundary to find the word to complete
startScan = max(0, $cursor - ScanDistance)
endScan = min($text_length, $cursor + ScanDistance)
scanString = get_range(startScan, endScan)
keyEnd = $cursor-startScan
keyStart = search_string(scanString, "<", keyEnd, "backward", "regex")
if (keyStart == -1)
    return
keyString = "<" substring(scanString, keyStart, keyEnd)

# search both forward and backward from the cursor position.  Note that
# using a regex search can lead to incorrect results if any of the special
# regex characters is encountered, which is not considered a delimiter
backwardSearchResult = search_string(scanString, keyString, keyStart-1,"backward", "regex")
forwardSearchResult = search_string(scanString, keyString, keyEnd, "regex")
if (backwardSearchResult == -1 && forwardSearchResult == -1) {
    beep()
    return
}

# if only one direction matched, use that, otherwise use the nearest
if (backwardSearchResult == -1)
    matchStart = forwardSearchResult
else if (forwardSearchResult == -1)
    matchStart = backwardSearchResult
else {
    if (keyStart - backwardSearchResult <= forwardSearchResult - keyEnd)
        matchStart = backwardSearchResult
    else
        matchStart = forwardSearchResult
}

# find the complete word
matchEnd = search_string(scanString, ">", matchStart, "regex")
completedWord = substring(scanString, matchStart, matchEnd)

# replace it in the window
replace_range(startScan + keyStart, $cursor, completedWord)

Modified version

if ($compword_end == $cursor)
	$compword_rep++
else
{
   $compword_rep = 1
   $compword_init = $cursor

   # search back to a word boundary to find the word to complete

   $compword_start = search("<", $cursor, "backward", "regex", "wrap")

   if ($compword_start == -1)
      return

   $compword = "<" get_range($compword_start, $cursor)
}

s=$cursor

for (i=0; i<=$compword_rep; i++)
   s=search($compword, s-1, "backward", "regex", "wrap")

if (s==$compword_start) 
{
   beep()
   $compword_rep=0
   s=$compword_start
   se=$compword_init
}
else
   se = search(">", s, "regex")

replace_range($compword_start, $cursor, get_range(s, se))

$compword_end = $cursor
You'll need to add $compword_end=0 to your .neditmacro file.

[Back]


. Released on  Wed, 21 Nov 2001  by C. Denat  

  
Visit our sponsor
Check Metrolink

© NEdit.org
1999-2001
All rights reserved


.