Hiho,
with this simple patch (hack?) it is now possible to
implement more complex smartIndent macros. The reason
is that the return value for a smartIndent macro can
now also be -2 which tells nedit to ommit the newline
after indentation.
Here is a simple smartIndent macro that copies the
indentation of the previous line conserving any
combinations of tabs and spaces (I have been looking
forward to this feature for years now :-) ):
---------------------------------------------------------
define copyPreviousLineIndentation {
lineStart = startOfLine($1)
search("^[ \t]*", lineStart, "regex")
insert_string("\n" get_range(lineStart, $search_end))
}
---------------------------------------------------------
The newline macro then looks like this:
---------------------------------------------------------
copyPreviousLineIndentation($1)
return -2
---------------------------------------------------------
Without this patch it isn't possible to get this
functionality because nedit would append a newline
after the indentation string.
Cheers,
Tom
Logged In: YES
user_id=918104
> Without this patch it isn't possible to get this
> functionality because nedit would append a newline
> after the indentation string.
Well, it is possible, although it may not be obvious.
For your language mode bind the *Return* key to
define copyPreviousLineIndentation {
pos = search("^\\s*", $cursor, "regex", "backward")
insert_string("\n" get_range(pos, $search_end))
}
This is just the function you defined above.
Now, you'd like to have an automagic newline. For
this turn Wrap to *None* (Yes, this is important).
You have smart indent on. Your Newline macro will
only be return -1 and only called with Ctrl+Return -
recall that we've bound Return to the macro above
via a menu definition and turned wrapping to none!
As *Type-in* Macro we define:
if ($column >= $wrap_margin) {
f = search("\\s", $cursor-1, "regex", "backward")
if (f != -1) {
right = search("$", $cursor, "regex", "nowrap")
back = length(get_range($cursor,right))
c = get_range(f+1, right)
pos = search("^\\s*",$cursor,"regex","backward")
set_cursor_pos(f+1)
delete_to_end_of_line()
insert_string("\n" get_range(pos,$search_end) c)
set_cursor_pos($cursor - back)
}
}
Hence if you write over the margin, you'll get
your automatic newline respecting the spaces/tabs
thing w/o using the Newline Macro.