#117 Manage Documents (Tabs) Macro Subroutines

Program (79)
Uwe Lehnert

This patch adds a couple of new built-in subroutines to
the macro language of NEdit, which allow to manage tabbed
groups of documents. The patch also adds a "unique
document identifier" property to a document (to get rid of
addressing a document using path + filename). This
"document ID" allows to identify a document, even if the
file name of a document changes (e.g. after "Save as ..")
or if a document was opened by using a relative path (e.g.
../foo.c"). This unique document ID is assigned, when a
document is created.

Following built-in macro subroutines are added (for
details please refer to FEATURE.txt, which is part of the
tar ball):

a.) get_document_id([option])

Returns document ID(s) of current focused document,
all documents, current group of documents, all raised
documents or raised document of current focused tabbed

b.) get_document_info(documentId)

Get document info related to given document ID.

Returns "file_path", "file_name", "raised" info about
document specified by "documentId" within an array.

c.) open_document( [option1, option2, option3, ... ] )

Open an existing or new document & return document ID.
Options control, if the document is to be opened
within an own window or within a tabbed group (before
or after a dedicated document).

Relative path names are allowed. Related document can
be identified by returned document ID.

d.) order_documents( option1 [, option2, option3, ... ] )

Arrange document(s) according to given sequence of
document IDs.

- assume
document "foo1" has doc.ID "1",
document "foo2" has doc.ID "2",
document "foo3" has doc.ID "3",
"foo1", "foo2" & "foo3" are open in own window each

- "order_documents(1, 2, 3)" -> all documents are
grouped within one window with tab order = "foo1",
"foo2", "foo3".
- "order_documents("after=3", 2, 1)" -> order document
"foo2" & "foo1" after document "foo3"; resulting
order = "foo3", "foo2", "foo1".
- "order_documents("before=3", 2, 1)" -> order
documents "foo2" & "foo1" before document "foo3";
resulting order = "foo2", "foo1", "foo3".

Inside the tar ball there is also a macro collection
available, which demonstrates the usage of the new
built-in macro subroutines: sort documents according to
its filename in ascending or descending alphabetical
order; group documents by language mode or restrict number
of documents per tabbed group by split into separate

The patch contains parts of "move tab by drag and drop"
patch "920929" (by courtesty of Tk Soh).

The patch was made against latest CVS Head snapshot
of NEdit (available at

I've tested the patch within following environment:

Built on: Solaris, Sparc, GNU C
With Motif: 1.2.6 [@(#)OSF/Motif Version 1.2.6]
Running Motif: 1.2 [@(#)OSF/Motif Version 1.2.6]
Server: Sun Microsystems, Inc. 6410

Built on: Linux, 386, GNU C (Red Hat 9)
With Motif: 2.1.30 [@(#)Motif Version 2.1.30]
Running Motif: 2.1 [unknown]
Server: The XFree86 Project, Inc 40300000


  • Nathan Gray

    Nathan Gray - 2007-10-03

    Logged In: YES
    Originator: NO

    Uwe: Do you have a version of this patch that works with current NEdit CVS? I'd like to write some project macros that would benefit greatly from this patch.

  • Uwe Lehnert

    Uwe Lehnert - 2007-10-07

    Logged In: YES
    Originator: YES

    Nathaniel: long time ago, since i've written that patch ;-)
    I've made a version 2.0 of the "manage document" patch against
    the "NEdit 5.6 Development CVS HEAD" source tar ball of
    5th October 2007. Some comments, received via mailing list (IIRC)
    were incorporated in version 2.0.

    Changes since Version 1.0:
    * built-in subroutine "open_document" renamed into "open". "open"
    macro subroutine overwrites "open" action routine. To be backward
    compatible, "open" macro subroutine interprets string parameters
    without a keyword as "filenames" just as action routine "open" does.
    * To simplify API of "open" options "after" & "before" were removed.
    * Parameter evaluation of new macro subroutines optimized.

    Enjoy the patch, Uwe
    File Added: md071005-V2-0.tar.gz

  • Uwe Lehnert

    Uwe Lehnert - 2007-10-07

    Version 2.0 for Nedit CVS 05.10.07

  • Nathan Gray

    Nathan Gray - 2007-10-08

    Logged In: YES
    Originator: NO

    Ok, thanks! I had no problem applying and building the new patch.


  • Nathan Gray

    Nathan Gray - 2007-10-08

    Logged In: YES
    Originator: NO

    Just to follow up: I'm generally happy with the patch, but I'm missing a focus_document_id( id ) function to focus by document id. If you're feeling inspired one day you might consider adding it. ;-)

    Thanks again!


Log in to post a comment.