#91 File Name Hook

open
nobody
None
5
2003-09-30
2003-09-30
No

This adds a file name hook to some of NEdit's file open
procedures. If a macro function named file_name_hook()
exists, it is executed before the filename is handed
over to the low-level file functions. The filename is
handed to the hook. The hook is expected to return the
filename after whatever manipulations are done. NEdit
will open the returned filename.

Note: This is a very rough hack, more like a proof of
concept. Use it at your own risk, but if you do, tell
me how the handling could be improved from the
point-of-view of the user/hook author.

Note: The patch includes C++ comments (to make
absolutely sure that they will not trickle into
released code). If your compiler chokes on them,
replace ^(\s*)//(.*)$ with \1/*\2*/ to replace them
with C comments.

For the developers, please have a look at the FIXME
comments in menu.c.

Discussion

  • Scott Tringali

    Scott Tringali - 2004-09-22

    Logged In: YES
    user_id=11321

    Good idea, I think all we have to do is plan how to scale it
    out to possibly a large set of events.

    If we take the "define a special name" approach, it may be
    better to name the hooks like this:

    hook_post_file_open
    hook_pre_file_save
    hook_post_file_save

    ...etc, so all the "hooks" are under a single namespace to
    reduce conflicts.

    Another idea is a specific registration procedure:

    set_file_open_hook("my_hook") or:
    set_hook("post_file_open", "my_hook")

    Though I can't really think why this would be better than
    the "magic name" approach, just more typing.

     
  • Thorsten Haude

    Thorsten Haude - 2004-09-22

    Logged In: YES
    user_id=119143

    Names: I would rather put eg. search-related stuff in the
    same namespace, so search_string, search_document,
    search_hook. It also feels much more natural. Of course,
    hook.file_name() would make sense, since hooks *are* a
    special case and with this syntax you could make use of it.

     
  • Thorsten Haude

    Thorsten Haude - 2004-09-22

    Logged In: YES
    user_id=119143

    hook.file_name() would have the additional advantage of
    being in a clean namespace. If that syntax would be
    introduces, we could reserve some namespaces (nedit, hook,
    etc.) for internal use.

     
  • Thorsten Haude

    Thorsten Haude - 2004-09-22

    Logged In: YES
    user_id=119143

    To elaborate yet again on the name thing (I really dislike
    these inverted names): What would hook_open be, something
    that fires if you open a file or the hook dialog's AP?

     

Log in to post a comment.