NeoMutt  2024-04-25-97-g7d2481
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
complete.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include "mutt/lib.h"
32#include "core/lib.h"
33#include "gui/lib.h"
34#include "lib.h"
35#include "complete/lib.h"
36#include "editor/lib.h"
37
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}
78
84};
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:182
int mutt_label_complete(struct CompletionData *cd, struct Buffer *buf, int numtabs)
Complete a label name.
Definition: helpers.c:311
Auto-completion.
Convenience wrapper for the core headers.
FunctionRetval
Possible return values for NeoMutt functions.
Definition: dispatcher.h:32
@ 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
void replace_part(struct EnterState *es, size_t from, const char *buf)
Search and replace on a buffer.
Definition: functions.c:132
Edit a string.
enum FunctionRetval complete_pattern(struct EnterWindowData *wdata, int op)
Complete a NeoMutt Pattern - Implements CompleteOps::complete() -.
Definition: complete.c:41
bool dlg_pattern(char *buf, size_t buflen)
Show menu to select a Pattern -.
Definition: dlg_pattern.c:342
Convenience wrapper for the gui headers.
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
Convenience wrapper for the library headers.
const struct CompleteOps CompletePatternOps
Auto-Completion of Patterns.
Definition: complete.c:82
Key value store.
size_t dsize
Length of data.
Definition: buffer.h:39
char * data
Pointer to data.
Definition: buffer.h:37
enum FunctionRetval(* complete)(struct EnterWindowData *wdata, int op)
Definition: compapi.h:46
size_t curpos
Position of the cursor.
Definition: state.h:36
wchar_t * wbuf
Buffer for the string being entered.
Definition: state.h:33
Data to fill the Enter Window.
Definition: wdata.h:46
int tabs
Number of times the user has hit tab.
Definition: wdata.h:63
struct CompletionData * cd
Auto-completion state data.
Definition: wdata.h:67
struct Buffer * buffer
struct Buffer for the result
Definition: wdata.h:48
struct EnterState * state
Current state of text entry.
Definition: wdata.h:50