Kurt McKee

lessons learned in production

Archive

Hey there! This article was written in 2015.

It might not have aged well for any number of reasons, so keep that in mind when reading (or clicking outgoing links!).

Tera Term subroutines

Posted 8 May 2015 in function, macro, programming, subroutine, tera term, and teraterm

A long time ago I inherited a big monolithic mess of Tera Term macro code. After a few years the code base had grown considerably and become extremely unwieldy. I finally decided that it was time to fix the problem and created some utility code that would allow me to make the code more modular (and make the code more reusable for other projects). The result is subroutine.ttl, licensed under the terms of the MIT license.

This creates something akin to a namespace and function notation for Tera Term macros:

callsub = 'logging:backup_logs'
include 'subroutine.ttl'

For this to work, just create a logging.ttl file, copy some boilerplate/hook code to the top of the file, and add a block of code like this:

:backup_logs
    ; The backup code goes here
return

Thanks to Tera Term's scope-less variables (or, from another point of view, global-only namespace) you can even "pass" arguments and "return" values. Enjoy!

☕ Like my work? I accept tips!