Skip to content

Commit

Permalink
globals: Add LIST_MACROS debugging macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuh committed Apr 25, 2023
1 parent e7eac33 commit 0bf6ddb
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions globals.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,51 @@ gcode:
{% endif %}
{% endfor %}
{ action_respond_info(output|join("\n")) }

[gcode_macro list_macros]
description: Lists registered macros (and optionally show variable state).
Usage: LISTVARS SEARCH=<search_string> VARS=<0|1>
variable_macros: {}
gcode:
{% set SEARCH = params.SEARCH | default(params.S) | default("") | lower %}
{% set VARS = params.VARS | default(params.V) | default(0) | int != 0 %}

# Load the config state once and save it.
{% if not macros %}
{% set renames = {} %}
{% for k in printer.configfile.config %}
{% if k.lower().startswith("gcode_macro") and
printer.configfile.config[k].rename_existing %}
{% set name = k.split(None, 1)[1] | lower %}
{% set dummy = renames.__setitem__(name,
[printer.configfile.config[k].rename_existing] +
(renames[name] if name in renames else [])) %}
{% endif %}
{% endfor %}
{% for k in printer %}
{% if k.lower().startswith("gcode_macro") %}
{% set name = k.split(None, 1)[1] | lower %}
{% set dummy = macros.__setitem__(k, renames[name] if renames[name] else
[]) %}
{% endif %}
{% endfor %}
{% endif %}

{% set output = [] %}
{% for k in macros %}
{% if SEARCH in k | lower %}
{% set line = k.split(None, 1)[1] %}
{% if macros[k] %}
{% set line = "%s (renames: %s)" % (line, macros[k] | join(",")) %}
{% endif %}
{% set outvars = [] %}
{% if VARS %}
{% for v in printer[k] | sort %}
{% set dummy = outvars.append(
"\n* %s: %s" % (v, printer[k][v]|string)) %}
{% endfor %}
{% endif %}
{% set dummy = output.append(line + outvars | join("")) %}
{% endif %}
{% endfor %}
{ action_respond_info(output | sort | join("\n")) }

0 comments on commit 0bf6ddb

Please sign in to comment.