This topic contains 1 reply, has 2 voices, and was last updated by  Eliot Muir 11 months ago.

Script editor-new file, templates

  • Some free standing editors and editors within Integrated Development Environments (IDEs) offer quick code template insertion upon creation of file or while typing. Those features save a significant amount of time typing and verifying for typos for the lifetime of a product development.

    The few code writing conventions turned into patterns used throughout the Iguana-apps repository could easily save a lot of work.

    See the them at http://help.interfaceware.com/v6/how-repo-modules-use-the-require-statement

    For example, if the new file dialog for a file with lua extension had an option (checkbox and a dropdown list) to create the file content with said patterns, there would be savings immediately.

    From those three documented patterns above, two that could easily become templates for new files are :
    1) Returning a local table: Which contains the functions for the module.

    local m={}
    function m.<|>()
    return nil
    end
    return m

    where <|> is the place the cursor would be presented when the editor opens with the new file
    Why m? The actual letter choice for templating the variable is irrelevant. Because it is a local variable to hold the list of functions, so the actual name does not show outside the module and therefore it is an unnecessary hassle to name it after the file name; and by being one letter it is very short to type and unobtrusive to read; and one can think of “m”odule.

    2) Returning a function: Used when a module is “single use” (there is only one function)

    local function fn()
    return nil
    end
    return fn

    The most repeated text to type everywhere in these lua files is the very verbose

    local function m. ...()
    return ...
    end

    If there was a quick way to paste that leaving the cursor where the function name should be, that would be great!! Say a button or very explicit hotkey.

    Interesting…. see if one else chimes in on this one. I could see some value in making a new module file with a template for the module name and help (although if we to invest effort in help authoring a GUI editor for help would be even better…)

You must be logged in to reply to this topic.