NeoMutt  2024-10-02-37-gfa9146
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() -.
 
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_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:34
@ FR_NO_ACTION
Valid function - no action performed.
Definition: dispatcher.h:37
int query_complete(struct Buffer *buf, struct ConfigSubset *sub)
Perform auto-complete using an Address Query.
Definition: dlg_query.c:480
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:256
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:48
struct EnterState * state
Current state of text entry.
Definition: wdata.h:50
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ 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 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 (wmemcmp(wdata->tempbuf, wdata->state->wbuf, wdata->state->lastchar) == 0)))
74 {
76 if (wdata->hclass == HC_MAILBOX)
77 flags |= MUTT_SEL_FOLDER;
78 if (cdata->multiple)
79 flags |= MUTT_SEL_MULTI;
80
81 dlg_browser(wdata->buffer, flags, cdata->mailbox, cdata->files, cdata->numfiles);
82 if (!buf_is_empty(wdata->buffer))
83 {
85 if (!wdata->pass)
86 mutt_hist_add(wdata->hclass, buf_string(wdata->buffer), true);
87 wdata->done = true;
88 return FR_SUCCESS;
89 }
90
91 /* file selection cancelled */
92 return FR_CONTINUE;
93 }
94
95 if (mutt_complete(wdata->cd, wdata->buffer) == 0)
96 {
97 wdata->templen = wdata->state->lastchar;
98 mutt_mem_realloc(&wdata->tempbuf, wdata->templen * sizeof(wchar_t));
99 if (wdata->tempbuf)
100 wmemcpy(wdata->tempbuf, wdata->state->wbuf, wdata->templen);
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:59
#define MUTT_SEL_MULTI
Multi-selection is enabled.
Definition: lib.h:58
#define MUTT_SEL_NO_FLAGS
No flags are set.
Definition: lib.h:56
uint8_t SelectFileFlags
Flags for mutt_select_file(), e.g. MUTT_SEL_MAILBOX.
Definition: lib.h:55
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:57
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
@ 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:1290
@ 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:490
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:291
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:115
struct Mailbox * mutt_mailbox_next(struct Mailbox *m_cur, struct Buffer *s)
Incoming folders completion routine.
Definition: mutt_mailbox.c:361
void buf_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:519
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: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:40
char *** files
List of files selected.
Definition: curs_lib.h:43
struct Mailbox * mailbox
Mailbox.
Definition: curs_lib.h:42
bool multiple
Allow multiple selections.
Definition: curs_lib.h:41
int * numfiles
Number of files selected.
Definition: curs_lib.h:44
+ 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 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 (wmemcmp(wdata->tempbuf, wdata->state->wbuf + i, wdata->state->lastchar - i) == 0))
127 {
128 dlg_browser(wdata->buffer, MUTT_SEL_NO_FLAGS, NULL, NULL, NULL);
129 if (!buf_is_empty(wdata->buffer))
130 replace_part(wdata->state, i, buf_string(wdata->buffer));
131 return FR_CONTINUE;
132 }
133
134 if (mutt_complete(wdata->cd, wdata->buffer) == 0)
135 {
136 wdata->templen = wdata->state->lastchar - i;
137 mutt_mem_realloc(&wdata->tempbuf, wdata->templen * sizeof(wchar_t));
138 if (wdata->tempbuf)
139 wmemcpy(wdata->tempbuf, wdata->state->wbuf + i, wdata->templen);
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:340
+ 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 426 of file helpers.c.

427{
428 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
429 return FR_NO_ACTION;
430
431 int rc = FR_SUCCESS;
432 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
433 size_t i = buf_len(wdata->buffer);
434 if ((i != 0) && (buf_at(wdata->buffer, i - 1) == '=') &&
435 (mutt_var_value_complete(wdata->cd, wdata->buffer, i) != 0))
436 {
437 wdata->tabs = 0;
438 }
439 else if (mutt_command_complete(wdata->cd, wdata->buffer, i, wdata->tabs) == 0)
440 {
441 rc = FR_ERROR;
442 }
443
444 replace_part(wdata->state, 0, buf_string(wdata->buffer));
445 return rc;
446}
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:670
int mutt_var_value_complete(struct CompletionData *cd, struct Buffer *buf, int pos)
Complete a variable/value.
Definition: helpers.c:373
int mutt_command_complete(struct CompletionData *cd, struct Buffer *buf, int pos, int numtabs)
Complete a command name.
Definition: helpers.c:112
int tabs
Number of times the user has hit tab.
Definition: wdata.h:63
+ 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 451 of file helpers.c.

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

enum FunctionRetval complete_pattern ( struct EnterWindowData wdata,
int  op 
)

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

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:182
bool dlg_pattern(char *buf, size_t buflen)
Show menu to select a Pattern -.
Definition: dlg_pattern.c:342
size_t dsize
Length of data.
Definition: buffer.h:39
char * data
Pointer to data.
Definition: buffer.h:37
+ Here is the call graph for this function: