Skip to content

Defined macros can not receive arguments #99

Description

@pcm1k

Version: e21daea

Steps to reproduce:

  • Add :def argtest math,"arg:ins",rtn to joerc and then add either math,"arg:ins",rtn <KEY> or argtest <KEY>. Replace <KEY> with some key, of course
  • Use the "arg" command and then try either one. Observe that the first one correctly prints the argument it was called with, while the second always prints "0". This issue also affects a default indentregion and cutc in jmacsrc

Analysis:

macro.c exmacro:

	/* Take argument */

	/* ANALYSIS: arg is reset to 0 */
	if (argset) {
		larg = arg;
		arg = 0;
		argset = 0;
	} else {
		larg = 1;
	}

	/* Just a simple command? */

	if (!m->steps) {
		/* ANALYSIS: this will be called since defined macros are wrapped in a CMD */
		return exsimple(m, larg, u, k);
	}

macro.c exsimple:

			/* ANALYSIS: execute the CMD */
			ret = execmd(cmd, m->k != NO_MORE_DATA ? m->k : k);

cmd.c execmd:

	if (cmd->m)
		/* ANALYSIS: call back to exmacro to execute the real macro, remember arg will always be 0 now! */
		return exmacro(cmd->m, 0, k);

Proposed fix:

--- a/joe/macro.c
+++ b/joe/macro.c
@@ -395,6 +395,11 @@
 	int o_arg_set = argset;
 	int o_arg = arg;
 
+	/* If it's actually a defined macro, execute it and don't overwrite arg */
+
+	if (!m->steps && m->cmd->m)
+		return exmacro(m->cmd->m, 0, k);
+
 	/* Take argument */
 
 	if (argset) {

This checks if it's a defined macro, and executes it right away without overwriting arg. This seems to fix the issue and makes the 2 test cases act identically as they should.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions