NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches

Perform Auto-Completion. More...

+ Collaboration diagram for complete():

Functions

enum FunctionRetval complete_alias_query (struct EnterWindowData *wdata, int op)
 Complete an Alias Query - Implements CompleteOps::complete() -.
 
enum FunctionRetval complete_alias (struct EnterWindowData *wdata, int op)
 Alias completion wrapper - Implements CompleteOps::complete() -.
 
enum FunctionRetval complete_file_mbox (struct EnterWindowData *wdata, int op)
 Complete a Mailbox - Implements CompleteOps::complete() -.
 
enum FunctionRetval complete_file_simple (struct EnterWindowData *wdata, int op)
 Complete a filename - Implements CompleteOps::complete() -.
 
enum FunctionRetval complete_command (struct EnterWindowData *wdata, int op)
 Complete a NeoMutt Command - Implements CompleteOps::complete() -.
 
enum FunctionRetval complete_label (struct EnterWindowData *wdata, int op)
 Complete a label - Implements CompleteOps::complete() -.
 
enum FunctionRetval complete_nm_query (struct EnterWindowData *wdata, int op)
 Complete a Notmuch Query - Implements CompleteOps::complete() -.
 
enum FunctionRetval complete_nm_tag (struct EnterWindowData *wdata, int op)
 Complete a Notmuch Tag - Implements CompleteOps::complete() -.
 
static enum FunctionRetval complete_pattern (struct EnterWindowData *wdata, int op)
 Complete a NeoMutt Pattern - Implements CompleteOps::complete() -.
 

Detailed Description

Perform Auto-Completion.

Parameters
wdataEnter Window data
opOperation to perform, e.g. OP_EDITOR_COMPLETE
Return values
numFunctionRetval, e.g. FR_SUCCESS

Function Documentation

◆ complete_alias_query()

enum FunctionRetval complete_alias_query ( struct EnterWindowData * wdata,
int op )

Complete an Alias Query - Implements CompleteOps::complete() -.

Definition at line 70 of file complete.c.

71{
72 if (!wdata || (op != OP_EDITOR_COMPLETE_QUERY))
73 return FR_NO_ACTION;
74
75 size_t i = wdata->state->curpos;
76 if (i != 0)
77 {
78 for (; (i > 0) && (wdata->state->wbuf[i - 1] != ','); i--)
79 ; // do nothing
80
81 for (; (i < wdata->state->curpos) && (wdata->state->wbuf[i] == ' '); i++)
82 ; // do nothing
83 }
84
85 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
87 replace_part(wdata->state, i, buf_string(wdata->buffer));
88
89 return FR_CONTINUE;
90}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
@ FR_CONTINUE
Remain in the Dialog.
Definition dispatcher.h:35
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
int query_complete(struct Buffer *buf, struct ConfigSubset *sub)
Perform auto-complete using an Address Query.
Definition dlg_query.c:406
void replace_part(struct EnterState *es, size_t from, const char *buf)
Search and replace on a buffer.
Definition functions.c:151
void buf_mb_wcstombs(struct Buffer *dest, const wchar_t *wstr, size_t wlen)
Convert a string from wide to multibyte characters.
Definition mbyte.c:257
size_t curpos
Position of the cursor.
Definition state.h:36
wchar_t * wbuf
Buffer for the string being entered.
Definition state.h:33
struct Buffer * buffer
struct Buffer for the result
Definition wdata.h:53
struct EnterState * state
Current state of text entry.
Definition wdata.h:55
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complete_alias()

enum FunctionRetval complete_alias ( struct EnterWindowData * wdata,
int op )

Alias completion wrapper - Implements CompleteOps::complete() -.

Definition at line 95 of file complete.c.

96{
97 if (op == OP_EDITOR_COMPLETE)
98 return complete_alias_complete(wdata, op);
99 if (op == OP_EDITOR_COMPLETE_QUERY)
100 return complete_alias_query(wdata, op);
101
102 return FR_NO_ACTION;
103}
enum FunctionRetval complete_alias_query(struct EnterWindowData *wdata, int op)
Complete an Alias Query - Implements CompleteOps::complete() -.
Definition complete.c:70
enum FunctionRetval complete_alias_complete(struct EnterWindowData *wdata, int op)
Complete an Alias - Implements CompleteOps::complete() -.
Definition complete.c:41
+ Here is the call graph for this function:

◆ complete_file_mbox()

enum FunctionRetval complete_file_mbox ( struct EnterWindowData * wdata,
int op )

Complete a Mailbox - Implements CompleteOps::complete() -.

Definition at line 45 of file complete.c.

46{
47 if (!wdata)
48 return FR_NO_ACTION;
49
50 struct FileCompletionData *cdata = wdata->cdata;
51
52 if (op == OP_EDITOR_MAILBOX_CYCLE)
53 {
54 wdata->first = true; /* clear input if user types a real key later */
55 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
56 mutt_mailbox_next(cdata->mailbox, wdata->buffer);
57
58 wdata->state->curpos = wdata->state->lastchar = mutt_mb_mbstowcs(
59 &wdata->state->wbuf, &wdata->state->wbuflen, 0, buf_string(wdata->buffer));
60 return FR_SUCCESS;
61 }
62
63 if ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY))
64 return FR_NO_ACTION;
65
66 int rc = FR_SUCCESS;
67 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
68
69 /* see if the path has changed from the last time */
70 if ((!wdata->tempbuf && !wdata->state->lastchar) ||
71 (wdata->tempbuf && (wdata->templen == wdata->state->lastchar) &&
72 (wmemcmp(wdata->tempbuf, wdata->state->wbuf, wdata->state->lastchar) == 0)))
73 {
75 if (wdata->hclass == HC_MAILBOX)
76 flags |= MUTT_SEL_FOLDER;
77 if (cdata->multiple)
78 flags |= MUTT_SEL_MULTI;
79
80 dlg_browser(wdata->buffer, flags, cdata->mailbox, cdata->files, cdata->numfiles);
81 if (!buf_is_empty(wdata->buffer))
82 {
83 pretty_mailbox(wdata->buffer);
84 if (!wdata->pass)
85 mutt_hist_add(wdata->hclass, buf_string(wdata->buffer), true);
86 wdata->done = true;
87 return FR_SUCCESS;
88 }
89
90 /* file selection cancelled */
91 return FR_CONTINUE;
92 }
93
94 if (mutt_complete(wdata->cd, wdata->buffer) == 0)
95 {
96 wdata->templen = wdata->state->lastchar;
97 MUTT_MEM_REALLOC(&wdata->tempbuf, wdata->templen, wchar_t);
98 if (wdata->tempbuf)
99 wmemcpy(wdata->tempbuf, wdata->state->wbuf, wdata->templen);
100 }
101 else
102 {
103 return FR_ERROR; // let the user know that nothing matched
104 }
105 replace_part(wdata->state, 0, buf_string(wdata->buffer));
106 return rc;
107}
#define MUTT_SEL_FOLDER
Select a local directory.
Definition lib.h:61
#define MUTT_SEL_MULTI
Multi-selection is enabled.
Definition lib.h:60
#define MUTT_SEL_NO_FLAGS
No flags are set.
Definition lib.h:58
uint8_t SelectFileFlags
Flags for mutt_select_file(), e.g. MUTT_SEL_MAILBOX.
Definition lib.h:57
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
int mutt_complete(struct CompletionData *cd, struct Buffer *buf)
Attempt to complete a partial pathname.
Definition complete.c:58
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
void dlg_browser(struct Buffer *file, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
Let the user select a file -.
@ HC_MAILBOX
Mailboxes.
Definition lib.h:61
void mutt_hist_add(enum HistoryClass hclass, const char *str, bool save)
Add a string to a history.
Definition history.c:482
size_t mutt_mb_mbstowcs(wchar_t **pwbuf, size_t *pwbuflen, size_t i, const char *buf)
Convert a string from multibyte to wide characters.
Definition mbyte.c:292
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:55
struct Mailbox * mutt_mailbox_next(struct Mailbox *m_cur, struct Buffer *s)
Incoming folders completion routine.
void pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition muttlib.c:427
size_t wbuflen
Length of buffer.
Definition state.h:34
size_t lastchar
Position of the last character.
Definition state.h:35
bool pass
Password mode, conceal characters.
Definition wdata.h:63
void * cdata
Auto-Completion private data.
Definition wdata.h:58
struct CompletionData * cd
Auto-completion state data.
Definition wdata.h:72
bool done
Is text-entry done?
Definition wdata.h:70
bool first
First time through, no input yet.
Definition wdata.h:64
wchar_t * tempbuf
Buffer used by completion.
Definition wdata.h:65
enum HistoryClass hclass
History to use, e.g. HC_NEO_COMMAND.
Definition wdata.h:56
size_t templen
Length of complete buffer.
Definition wdata.h:66
Input for the file completion function.
Definition curs_lib.h:39
char *** files
List of files selected.
Definition curs_lib.h:42
struct Mailbox * mailbox
Mailbox.
Definition curs_lib.h:41
bool multiple
Allow multiple selections.
Definition curs_lib.h:40
int * numfiles
Number of files selected.
Definition curs_lib.h:43
+ Here is the call graph for this function:

◆ complete_file_simple()

enum FunctionRetval complete_file_simple ( struct EnterWindowData * wdata,
int op )

Complete a filename - Implements CompleteOps::complete() -.

Definition at line 112 of file complete.c.

113{
114 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
115 return FR_NO_ACTION;
116
117 int rc = FR_SUCCESS;
118 size_t i;
119 for (i = wdata->state->curpos;
120 (i > 0) && !mutt_mb_is_shell_char(wdata->state->wbuf[i - 1]); i--)
121 {
122 }
123 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
124 if (wdata->tempbuf && (wdata->templen == (wdata->state->lastchar - i)) &&
125 (wmemcmp(wdata->tempbuf, wdata->state->wbuf + i, wdata->state->lastchar - i) == 0))
126 {
127 dlg_browser(wdata->buffer, MUTT_SEL_NO_FLAGS, NULL, NULL, NULL);
128 if (!buf_is_empty(wdata->buffer))
129 replace_part(wdata->state, i, buf_string(wdata->buffer));
130 return FR_CONTINUE;
131 }
132
133 if (mutt_complete(wdata->cd, wdata->buffer) == 0)
134 {
135 wdata->templen = wdata->state->lastchar - i;
136 MUTT_MEM_REALLOC(&wdata->tempbuf, wdata->templen, wchar_t);
137 if (wdata->tempbuf)
138 wmemcpy(wdata->tempbuf, wdata->state->wbuf + i, wdata->templen);
139 }
140 else
141 {
142 rc = FR_ERROR;
143 }
144
145 replace_part(wdata->state, i, buf_string(wdata->buffer));
146 return rc;
147}
bool mutt_mb_is_shell_char(wchar_t ch)
Is character not typically part of a pathname.
Definition mbyte.c:341
+ Here is the call graph for this function:

◆ complete_command()

enum FunctionRetval complete_command ( struct EnterWindowData * wdata,
int op )

Complete a NeoMutt Command - Implements CompleteOps::complete() -.

Definition at line 482 of file helpers.c.

483{
484 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
485 return FR_NO_ACTION;
486
487 int rc = FR_SUCCESS;
488 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
489 size_t i = buf_len(wdata->buffer);
490 if ((i != 0) && (buf_at(wdata->buffer, i - 1) == '=') &&
491 (mutt_var_value_complete(wdata->cd, wdata->buffer, i) != 0))
492 {
493 wdata->tabs = 0;
494 }
495 else if (mutt_command_complete(wdata->cd, wdata->buffer, i, wdata->tabs, wdata->cdata) == 0)
496 {
497 rc = FR_ERROR;
498 }
499
500 replace_part(wdata->state, 0, buf_string(wdata->buffer));
501 return rc;
502}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition buffer.c:668
int mutt_var_value_complete(struct CompletionData *cd, struct Buffer *buf, int pos)
Complete a variable/value.
Definition helpers.c:429
int mutt_command_complete(struct CompletionData *cd, struct Buffer *buf, int pos, int numtabs, void *cdata)
Complete a command name.
Definition helpers.c:124
int tabs
Number of times the user has hit tab.
Definition wdata.h:68
+ Here is the call graph for this function:

◆ complete_label()

enum FunctionRetval complete_label ( struct EnterWindowData * wdata,
int op )

Complete a label - Implements CompleteOps::complete() -.

Definition at line 507 of file helpers.c.

508{
509 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
510 return FR_NO_ACTION;
511
512 size_t i;
513 for (i = wdata->state->curpos; (i > 0) && (wdata->state->wbuf[i - 1] != ',') &&
514 (wdata->state->wbuf[i - 1] != ':');
515 i--)
516 {
517 }
518 for (; (i < wdata->state->lastchar) && (wdata->state->wbuf[i] == ' '); i++)
519 ; // do nothing
520
521 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
522 int rc = mutt_label_complete(wdata->cd, wdata->buffer, wdata->tabs);
523 replace_part(wdata->state, i, buf_string(wdata->buffer));
524 if (rc != 1)
525 return FR_CONTINUE;
526
527 return FR_SUCCESS;
528}
int mutt_label_complete(struct CompletionData *cd, struct Buffer *buf, int numtabs)
Complete a label name.
Definition helpers.c:367
+ Here is the call graph for this function:

◆ complete_nm_query()

enum FunctionRetval complete_nm_query ( struct EnterWindowData * wdata,
int op )

Complete a Notmuch Query - Implements CompleteOps::complete() -.

Definition at line 213 of file complete.c.

214{
215 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
216 return FR_NO_ACTION;
217
218 int rc = FR_SUCCESS;
219 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
220 if (!mutt_nm_query_complete(wdata->cd, wdata->buffer, wdata->tabs))
221 rc = FR_ERROR;
222
223 replace_part(wdata->state, 0, buf_string(wdata->buffer));
224 return rc;
225}
bool mutt_nm_query_complete(struct CompletionData *cd, struct Buffer *buf, int numtabs)
Complete to the nearest notmuch tag.
Definition complete.c:101
+ Here is the call graph for this function:

◆ complete_nm_tag()

enum FunctionRetval complete_nm_tag ( struct EnterWindowData * wdata,
int op )

Complete a Notmuch Tag - Implements CompleteOps::complete() -.

Definition at line 230 of file complete.c.

231{
232 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
233 return FR_NO_ACTION;
234
235 int rc = FR_SUCCESS;
236 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
237 if (!mutt_nm_tag_complete(wdata->cd, wdata->buffer, wdata->tabs))
238 rc = FR_ERROR;
239
240 replace_part(wdata->state, 0, buf_string(wdata->buffer));
241 return rc;
242}
bool mutt_nm_tag_complete(struct CompletionData *cd, struct Buffer *buf, int numtabs)
Complete to the nearest notmuch tag.
Definition complete.c:161
+ Here is the call graph for this function:

◆ complete_pattern()

static enum FunctionRetval complete_pattern ( struct EnterWindowData * wdata,
int op )
static

Complete a NeoMutt Pattern - Implements CompleteOps::complete() -.

Definition at line 53 of file complete.c.

54{
55 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
56 return FR_NO_ACTION;
57
58 size_t i = wdata->state->curpos;
59
60 // Check if cursor is right after a pattern prefix (~, %, or =)
61 if (i && is_pattern_prefix(wdata->state->wbuf[i - 1]))
62 {
63 if (dlg_pattern(wdata->buffer))
64 replace_part(wdata->state, i - 1, wdata->buffer->data);
65 buf_fix_dptr(wdata->buffer);
66 return FR_CONTINUE;
67 }
68
69 // Search backwards for a pattern prefix
70 for (; (i > 0) && !is_pattern_prefix(wdata->state->wbuf[i - 1]); i--)
71 ; // do nothing
72
73 if ((i > 0) && (i < wdata->state->curpos) &&
74 (wdata->state->wbuf[i - 1] == '~') && (wdata->state->wbuf[i] == 'y'))
75 {
76 // Label completion for ~y pattern
77 i++;
78 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
79 int rc = mutt_label_complete(wdata->cd, wdata->buffer, wdata->tabs);
80 replace_part(wdata->state, i, wdata->buffer->data);
81 buf_fix_dptr(wdata->buffer);
82 if (rc != 1)
83 {
84 return FR_CONTINUE;
85 }
86 }
87 else
88 {
89 return FR_NO_ACTION;
90 }
91
92 return FR_SUCCESS;
93}
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition buffer.c:182
bool dlg_pattern(struct Buffer *buf)
Show menu to select a Pattern -.
static bool is_pattern_prefix(wchar_t c)
Check if a character is a pattern prefix.
Definition complete.c:45
char * data
Pointer to data.
Definition buffer.h:37
+ Here is the call graph for this function: