@@ -2062,7 +2062,7 @@ def _perform_completion(
20622062 if custom_settings is None :
20632063 # Check if a macro was entered
20642064 if command in self .macros :
2065- completer_func = self .path_complete
2065+ completer_func = self .macro_arg_complete
20662066
20672067 # Check if a command was entered
20682068 elif command in self .get_all_commands ():
@@ -3542,6 +3542,27 @@ def _alias_list(self, args: argparse.Namespace) -> None:
35423542 # Parsers and functions for macro command and subcommands
35433543 #############################################################
35443544
3545+ def macro_arg_complete (
3546+ self ,
3547+ text : str ,
3548+ line : str ,
3549+ begidx : int ,
3550+ endidx : int ,
3551+ ) -> list [str ]:
3552+ """Tab completes arguments to a macro.
3553+
3554+ Its default behavior is to call path_complete, but you can override this as needed.
3555+
3556+ The args required by this function are defined in the header of Python's cmd.py.
3557+
3558+ :param text: the string prefix we are attempting to match (all matches must begin with it)
3559+ :param line: the current input line with leading whitespace removed
3560+ :param begidx: the beginning index of the prefix text
3561+ :param endidx: the ending index of the prefix text
3562+ :return: a list of possible tab completions
3563+ """
3564+ return self .path_complete (text , line , begidx , endidx )
3565+
35453566 # Top-level parser for macro
35463567 @staticmethod
35473568 def _build_macro_parser () -> Cmd2ArgumentParser :
@@ -3609,8 +3630,8 @@ def _build_macro_create_parser(cls) -> Cmd2ArgumentParser:
36093630 " macro create show_results print_results -type {1} \" |\" less" ,
36103631 "\n " ,
36113632 (
3612- "Because macros do not resolve until after hitting Enter, tab completion "
3613- "will only complete paths while typing a macro."
3633+ "Since macros don't resolve until after you press Enter, their arguments tab complete as paths. "
3634+ "This default behavior changes if custom tab completion for macro arguments has been implemented ."
36143635 ),
36153636 )
36163637 macro_create_parser .epilog = macro_create_parser .create_text_group ("Notes" , macro_create_notes )
0 commit comments