NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Auto-Completion API

Auto-Completion API. More...

+ Collaboration diagram for Auto-Completion API:

Modules

 complete()
 Perform Auto-Completion.
 

Functions

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

Detailed Description

Auto-Completion API.

Prototype for an Auto-Completion Function.

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

Function Documentation

◆ complete_alias_complete()

int complete_alias_complete ( struct EnterWindowData wdata,
int  op 
)

Complete an Alias - Implements complete_function_t -.

Definition at line 41 of file complete.c.

42{
43 if (!wdata || (op != OP_EDITOR_COMPLETE))
44 return FR_NO_ACTION;
45
46 /* invoke the alias-menu to get more addresses */
47 size_t i;
48 for (i = wdata->state->curpos; (i > 0) && (wdata->state->wbuf[i - 1] != ',') &&
49 (wdata->state->wbuf[i - 1] != ':');
50 i--)
51 {
52 }
53 for (; (i < wdata->state->lastchar) && (wdata->state->wbuf[i] == ' '); i++)
54 ; // do nothing
55
56 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
57 int rc = alias_complete(wdata->buffer, NeoMutt->sub);
58 replace_part(wdata->state, i, buf_string(wdata->buffer));
59 if (rc != 1)
60 {
61 return FR_CONTINUE;
62 }
63
64 return FR_SUCCESS;
65}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
@ FR_CONTINUE
Remain in the Dialog.
Definition: dispatcher.h:34
@ FR_NO_ACTION
Valid function - no action performed.
Definition: dispatcher.h:37
int alias_complete(struct Buffer *buf, struct ConfigSubset *sub)
Alias completion routine.
Definition: dlg_alias.c:385
void replace_part(struct EnterState *es, size_t from, const char *buf)
Search and replace on a buffer.
Definition: functions.c:132
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:255
size_t curpos
Position of the cursor.
Definition: state.h:36
wchar_t * wbuf
Buffer for the string being entered.
Definition: state.h:33
size_t lastchar
Position of the last character.
Definition: state.h:35
struct Buffer * buffer
struct Buffer for the result
Definition: wdata.h:48
struct EnterState * state
Current state of text entry.
Definition: wdata.h:50
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complete_alias_query()

int complete_alias_query ( struct EnterWindowData wdata,
int  op 
)

Complete an Alias Query - Implements complete_function_t -.

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}
int query_complete(struct Buffer *buf, struct ConfigSubset *sub)
Perform auto-complete using an Address Query.
Definition: dlg_query.c:456
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complete_alias()

int complete_alias ( struct EnterWindowData wdata,
int  op 
)

Alias completion wrapper - Implements complete_function_t -.

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}
int complete_alias_complete(struct EnterWindowData *wdata, int op)
Complete an Alias - Implements complete_function_t -.
Definition: complete.c:41
int complete_alias_query(struct EnterWindowData *wdata, int op)
Complete an Alias Query - Implements complete_function_t -.
Definition: complete.c:70
+ Here is the call graph for this function:

◆ complete_file_mbox()

int complete_file_mbox ( struct EnterWindowData wdata,
int  op 
)

Complete a Mailbox - Implements complete_function_t -.

Definition at line 46 of file complete.c.

47{
48 if (!wdata)
49 return FR_NO_ACTION;
50
51 struct FileCompletionData *cdata = wdata->cdata;
52
53 if (op == OP_EDITOR_MAILBOX_CYCLE)
54 {
55 wdata->first = true; /* clear input if user types a real key later */
56 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
57 mutt_mailbox_next(cdata->mailbox, wdata->buffer);
58
59 wdata->state->curpos = wdata->state->lastchar = mutt_mb_mbstowcs(
60 &wdata->state->wbuf, &wdata->state->wbuflen, 0, buf_string(wdata->buffer));
61 return FR_SUCCESS;
62 }
63
64 if ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY))
65 return FR_NO_ACTION;
66
67 int rc = FR_SUCCESS;
68 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
69
70 /* see if the path has changed from the last time */
71 if ((!wdata->tempbuf && !wdata->state->lastchar) ||
72 (wdata->tempbuf && (wdata->templen == wdata->state->lastchar) &&
73 (memcmp(wdata->tempbuf, wdata->state->wbuf,
74 wdata->state->lastchar * sizeof(wchar_t)) == 0)))
75 {
77 if (wdata->hclass == HC_MAILBOX)
78 flags |= MUTT_SEL_FOLDER;
79 if (cdata->multiple)
80 flags |= MUTT_SEL_MULTI;
81
82 dlg_browser(wdata->buffer, flags, cdata->mailbox, cdata->files, cdata->numfiles);
83 if (!buf_is_empty(wdata->buffer))
84 {
86 if (!wdata->pass)
87 mutt_hist_add(wdata->hclass, buf_string(wdata->buffer), true);
88 wdata->done = true;
89 return FR_SUCCESS;
90 }
91
92 /* file selection cancelled */
93 return FR_CONTINUE;
94 }
95
96 if (mutt_complete(wdata->cd, wdata->buffer) == 0)
97 {
98 wdata->templen = wdata->state->lastchar;
99 mutt_mem_realloc(&wdata->tempbuf, wdata->templen * sizeof(wchar_t));
100 memcpy(wdata->tempbuf, wdata->state->wbuf, wdata->templen * sizeof(wchar_t));
101 }
102 else
103 {
104 return FR_ERROR; // let the user know that nothing matched
105 }
106 replace_part(wdata->state, 0, buf_string(wdata->buffer));
107 return rc;
108}
#define MUTT_SEL_FOLDER
Select a local directory.
Definition: lib.h:60
#define MUTT_SEL_MULTI
Multi-selection is enabled.
Definition: lib.h:59
#define MUTT_SEL_NO_FLAGS
No flags are set.
Definition: lib.h:57
uint8_t SelectFileFlags
Flags for mutt_select_file(), e.g. MUTT_SEL_MAILBOX.
Definition: lib.h:56
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:303
int mutt_complete(struct CompletionData *cd, struct Buffer *buf)
Attempt to complete a partial pathname.
Definition: complete.c:55
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
void dlg_browser(struct Buffer *file, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
Let the user select a file -.
Definition: dlg_browser.c:1226
@ HC_MAILBOX
Mailboxes.
Definition: lib.h:57
void mutt_hist_add(enum HistoryClass hclass, const char *str, bool save)
Add a string to a history.
Definition: history.c:485
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:290
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
struct Mailbox * mutt_mailbox_next(struct Mailbox *m_cur, struct Buffer *s)
Incoming folders completion routine.
Definition: mutt_mailbox.c:366
void buf_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:556
size_t wbuflen
Length of buffer.
Definition: state.h:34
bool pass
Password mode, conceal characters.
Definition: wdata.h:58
void * cdata
Auto-Completion private data.
Definition: wdata.h:53
struct CompletionData * cd
Auto-completion state data.
Definition: wdata.h:67
bool done
Is text-entry done?
Definition: wdata.h:65
bool first
First time through, no input yet.
Definition: wdata.h:59
wchar_t * tempbuf
Buffer used by completion.
Definition: wdata.h:60
enum HistoryClass hclass
History to use, e.g. HC_NEO_COMMAND.
Definition: wdata.h:51
size_t templen
Length of complete buffer.
Definition: wdata.h:61
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()

int complete_file_simple ( struct EnterWindowData wdata,
int  op 
)

Complete a filename - Implements complete_function_t -.

Definition at line 113 of file complete.c.

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

◆ complete_command()

int complete_command ( struct EnterWindowData wdata,
int  op 
)

Complete a NeoMutt Command - Implements complete_function_t -.

Definition at line 424 of file helpers.c.

425{
426 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
427 return FR_NO_ACTION;
428
429 int rc = FR_SUCCESS;
430 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
431 size_t i = buf_len(wdata->buffer);
432 if ((i != 0) && (buf_at(wdata->buffer, i - 1) == '=') &&
433 (mutt_var_value_complete(wdata->cd, wdata->buffer, i) != 0))
434 {
435 wdata->tabs = 0;
436 }
437 else if (mutt_command_complete(wdata->cd, wdata->buffer, i, wdata->tabs) == 0)
438 {
439 rc = FR_ERROR;
440 }
441
442 replace_part(wdata->state, 0, buf_string(wdata->buffer));
443 return rc;
444}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:466
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition: buffer.c:638
int mutt_var_value_complete(struct CompletionData *cd, struct Buffer *buf, int pos)
Complete a variable/value.
Definition: helpers.c:371
int mutt_command_complete(struct CompletionData *cd, struct Buffer *buf, int pos, int numtabs)
Complete a command name.
Definition: helpers.c:110
int tabs
Number of times the user has hit tab.
Definition: wdata.h:63
+ Here is the call graph for this function:

◆ complete_label()

int complete_label ( struct EnterWindowData wdata,
int  op 
)

Complete a label - Implements complete_function_t -.

Definition at line 449 of file helpers.c.

450{
451 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
452 return FR_NO_ACTION;
453
454 size_t i;
455 for (i = wdata->state->curpos; (i > 0) && (wdata->state->wbuf[i - 1] != ',') &&
456 (wdata->state->wbuf[i - 1] != ':');
457 i--)
458 {
459 }
460 for (; (i < wdata->state->lastchar) && (wdata->state->wbuf[i] == ' '); i++)
461 ; // do nothing
462
463 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
464 int rc = mutt_label_complete(wdata->cd, wdata->buffer, wdata->tabs);
465 replace_part(wdata->state, i, buf_string(wdata->buffer));
466 if (rc != 1)
467 return FR_CONTINUE;
468
469 return FR_SUCCESS;
470}
int mutt_label_complete(struct CompletionData *cd, struct Buffer *buf, int numtabs)
Complete a label name.
Definition: helpers.c:309
+ Here is the call graph for this function:

◆ complete_nm_query()

int complete_nm_query ( struct EnterWindowData wdata,
int  op 
)

Complete a Notmuch Query - Implements complete_function_t -.

Definition at line 214 of file complete.c.

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

◆ complete_nm_tag()

int complete_nm_tag ( struct EnterWindowData wdata,
int  op 
)

Complete a Notmuch Tag - Implements complete_function_t -.

Definition at line 232 of file complete.c.

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

◆ complete_pattern()

int complete_pattern ( struct EnterWindowData wdata,
int  op 
)

Complete a NeoMutt Pattern - Implements complete_function_t -.

Definition at line 41 of file complete.c.

42{
43 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
44 return FR_NO_ACTION;
45
46 size_t i = wdata->state->curpos;
47 if (i && (wdata->state->wbuf[i - 1] == '~'))
48 {
49 if (dlg_pattern(wdata->buffer->data, wdata->buffer->dsize))
50 replace_part(wdata->state, i - 1, wdata->buffer->data);
51 buf_fix_dptr(wdata->buffer);
52 return FR_CONTINUE;
53 }
54
55 for (; (i > 0) && (wdata->state->wbuf[i - 1] != '~'); i--)
56 ; // do nothing
57
58 if ((i > 0) && (i < wdata->state->curpos) &&
59 (wdata->state->wbuf[i - 1] == '~') && (wdata->state->wbuf[i] == 'y'))
60 {
61 i++;
62 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
63 int rc = mutt_label_complete(wdata->cd, wdata->buffer, wdata->tabs);
64 replace_part(wdata->state, i, wdata->buffer->data);
65 buf_fix_dptr(wdata->buffer);
66 if (rc != 1)
67 {
68 return FR_CONTINUE;
69 }
70 }
71 else
72 {
73 return FR_NO_ACTION;
74 }
75
76 return FR_SUCCESS;
77}
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:194
bool dlg_pattern(char *buf, size_t buflen)
Show menu to select a Pattern -.
Definition: dlg_pattern.c:337
size_t dsize
Length of data.
Definition: buffer.h:37
char * data
Pointer to data.
Definition: buffer.h:35
+ Here is the call graph for this function: