Skip to content

Commit

Permalink
Allow querying user-defined variables ($my_var) via -Q
Browse files Browse the repository at this point in the history
  • Loading branch information
rayfordshire authored and flatcap committed Feb 22, 2023
1 parent b455758 commit f8ba654
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,40 +926,53 @@ int mutt_query_variables(struct ListHead *queries, bool show_docs)
mutt_buffer_reset(&value);

struct HashElem *he = cs_subset_lookup(NeoMutt->sub, np->data);
if (!he)
if (he)
{
mutt_warning(_("No such variable: %s"), np->data);
rc = 1;
continue;
}
if (he->type & DT_DEPRECATED)
{
mutt_warning(_("Config variable '%s' is deprecated"), np->data);
rc = 1;
continue;
}

if (he->type & DT_DEPRECATED)
{
mutt_warning(_("Config variable '%s' is deprecated"), np->data);
rc = 1;
continue;
}
int rv = cs_subset_he_string_get(NeoMutt->sub, he, &value);
if (CSR_RESULT(rv) != CSR_SUCCESS)
{
rc = 1;
continue;
}

int rv = cs_subset_he_string_get(NeoMutt->sub, he, &value);
if (CSR_RESULT(rv) != CSR_SUCCESS)
{
rc = 1;
int type = DTYPE(he->type);
if (type == DT_PATH)
mutt_pretty_mailbox(value.data, value.dsize);

if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) && (type != DT_QUAD))
{
mutt_buffer_reset(&tmp);
pretty_var(value.data, &tmp);
mutt_buffer_strcpy(&value, tmp.data);
}

dump_config_neo(NeoMutt->sub->cs, he, &value, NULL,
show_docs ? CS_DUMP_SHOW_DOCS : CS_DUMP_NO_FLAGS, stdout);
continue;
}

int type = DTYPE(he->type);
if (type == DT_PATH)
mutt_pretty_mailbox(value.data, value.dsize);

if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) && (type != DT_QUAD))
const char *myvar_value = myvar_get(np->data);
if (myvar_value)
{
mutt_buffer_reset(&tmp);
pretty_var(value.data, &tmp);
mutt_buffer_strcpy(&value, tmp.data);
pretty_var(myvar_value, &value);
/* style should match style of dump_config_neo() */
if (show_docs)
printf("# user-defined variable\n");
printf("set %s = %s\n", np->data, value.data);
if (show_docs)
printf("\n");
continue;
}

dump_config_neo(NeoMutt->sub->cs, he, &value, NULL,
show_docs ? CS_DUMP_SHOW_DOCS : CS_DUMP_NO_FLAGS, stdout);
mutt_warning(_("No such variable: %s"), np->data);
rc = 1;
}

mutt_buffer_dealloc(&value);
Expand Down

0 comments on commit f8ba654

Please sign in to comment.