Skip to content

Conversation

Copy link

Copilot AI commented Jan 3, 2026

The parsing macros MoreArgs(), MoreArgsF(), and SKIPWS() were hard to understand, debug, and test. This PR converts them to proper functions and unifies the MoreArgs variants.

Changes

  • New functions replacing macros

    • skip_ws(char **ptr) in mutt/string.c — skips whitespace, used by SKIPWS macro
    • more_args(struct Buffer *buf, TokenFlags flags) in parse/extract.c — unified function for argument checking
  • Backward-compatible macro aliases

    • SKIPWS(ch)skip_ws(&(ch))
    • MoreArgs(buf)more_args(buf, TOKEN_SPACE)
    • MoreArgsF(buf, flags)more_args(buf, flags)
  • New tests

    • test/parse/more_args.c — tests for MoreArgs() and MoreArgsF() behavior
    • test/parse/skipws.c — tests for SKIPWS() behavior

Example usage

// Old macro usage still works
if (MoreArgs(line))
  parse_extract_token(token, line, TOKEN_NO_FLAGS);

// New function can be called directly with flags
if (more_args(line, TOKEN_SPACE | TOKEN_COMMENT))
  parse_extract_token(token, line, TOKEN_COMMENT);
Original prompt

Improve the Parsing of NeoMutt Commands

Introduction

When a user enters a command, the string is first passed to parse_rc_line().

It uses macro SKIPWS() and function parse_extract_token() to extract the first 'token' -- the Command name.
parse_rc_line() uses command_find_by_name() which returns a struct Command.

Further work is delegated to a custom parsing function, found in Command.parse().

The custom parse functions use macros: MoreArgs(), MoreArgsF(), SKIPWS() and function parse_extract_token()
to extract the parameters for the Command.

About the Commands

Most of the Commands are defined in two places:

  • MuttCommands in commands/commands.c
  • HookCommands in hooks/commands.c

For each Command, struct Command contains:

  • Name
  • Description
  • Prototype
  • Parsing function
  • Data

Problems

The macros work, but are hard to understand, hard to debug and hard to test.

MoreArgsF() was created to be a more nuanced version of MoreArgs().
It was felt that altering MoreArgs() to support other flags would likely break some existing parsing.

Tasks

  1. Create tests for the macros: MoreArgs(), MoreArgsF() and SKIPWS()
    Use the existing code, and Command Prototypes, for inspiration.

  2. Turn MoreArgs(), MoreArgsF() and SKIPWS() into functions
    Check the tests still work.

  3. Merge the MoreArgs() and MoreArgsF() into a single function.
    Update the tests to match


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@flatcap flatcap added the topic:refactoring Code refactoring label Jan 3, 2026
Copilot AI changed the title [WIP] Improve the parsing mechanism for NeoMutt commands Improve parsing macros: convert to functions and merge MoreArgs variants Jan 3, 2026
Copilot AI requested a review from flatcap January 3, 2026 23:38
@flatcap flatcap force-pushed the copilot/improve-parsing-of-neomutt-commands branch from a482e02 to b77af4d Compare January 4, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:refactoring Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants