Документ взят из кэша поисковой машины. Адрес оригинального документа : http://mavr.sao.ru/hq/sts/linux/doc/nedit/macro/4/4-22.shtml
Дата изменения: Unknown
Дата индексирования: Fri Dec 28 20:27:21 2007
Кодировка:

Поисковые слова: п п п п п п п п п п п п п п п п
NEdit.org

.
.   
NEdit.org
   .

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

Insert closing HTML tag

[Back]

This Insert closing HTML tag macro checks if tag is not closed somewhere between it and cursor position. If it is, it finds previous opening tag and so it continues until it finds some unclosed tag or reach beginning of document.

So if you have following sequence <TABLE><TR><TD> first run of macro inserts </TD>, second </TR>, third </TABLE> and fourth nothing.

If you uncomment last line of this macro, cursor will be moved to initial position after tag insertion, but usually it's not preferred to have this behaviour.

position = $cursor
start = $cursor
closed = 1
ab_start = $cursor

while (closed == 1)
{
   search_start = search("\\<[a-zA-Z][-.a-zA-Z0-9]*", start - 1, "regex", "backward")
   pom = "</" get_range(search_start + 1, $search_end) ">"
   search2 = search(pom, search_start, "literal", "forward")
   if (search2 > -1 && search2 < ab_start)
      closed = 1
   else
      closed = 0
   start = search_start - 1
}

if (search_start < ab_start)
   insert_string(pom)
# set_cursor_pos(position)
Macro corrected by Reuben Thomas to make sure that the macro works wherever the current cursor is positioned.



You can also use this simple macro for inserting elements, or marking a block of text as an element:
elementName = string_dialog("Element name:", "OK", "Cancel")

cursorPosition = $cursor

if ($string_dialog_button == 1)
{
   if ($selection_start == -1)
   {
      insert_string("<" elementName "></" elementName ">")
      set_cursor_pos(cursorPosition + length(elementName) + 2)
   }
   else
   {
      selection = get_selection()
      replace_selection("<" elementName ">" selection "</" elementName ">")
   }
}
[Back]

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

  
Visit our sponsor
Check Metrolink

© NEdit.org
1999-2001
All rights reserved


.