NeoMutt  2025-12-11-276-g10b23b
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
complete.c
Go to the documentation of this file.
1
22
28
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
44static bool is_pattern_prefix(wchar_t c)
45{
46 return (c == '~') || (c == '%') || (c == '=');
47}
48
52static enum FunctionRetval complete_pattern(struct EnterWindowData *wdata, int op)
53{
54 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
55 return FR_NO_ACTION;
56
57 size_t i = wdata->state->curpos;
58
59 // Check if cursor is right after a pattern prefix (~, %, or =)
60 if (i && is_pattern_prefix(wdata->state->wbuf[i - 1]))
61 {
62 if (dlg_pattern(wdata->buffer))
63 replace_part(wdata->state, i - 1, wdata->buffer->data);
64 buf_fix_dptr(wdata->buffer);
65 return FR_CONTINUE;
66 }
67
68 // Search backwards for a pattern prefix
69 for (; (i > 0) && !is_pattern_prefix(wdata->state->wbuf[i - 1]); i--)
70 ; // do nothing
71
72 if ((i > 0) && (i < wdata->state->curpos) &&
73 (wdata->state->wbuf[i - 1] == '~') && (wdata->state->wbuf[i] == 'y'))
74 {
75 // Label completion for ~y pattern
76 i++;
77 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
78 int rc = mutt_label_complete(wdata->cd, wdata->buffer, wdata->tabs);
79 replace_part(wdata->state, i, wdata->buffer->data);
80 buf_fix_dptr(wdata->buffer);
81 if (rc != 1)
82 {
83 return FR_CONTINUE;
84 }
85 }
86 else
87 {
88 return FR_NO_ACTION;
89 }
90
91 return FR_SUCCESS;
92}
93
98 .complete = complete_pattern,
99};
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:366
Auto-completion.
Convenience wrapper for the core headers.
FunctionRetval
Possible return values for NeoMutt functions.
Definition dispatcher.h:33
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_CONTINUE
Remain in the Dialog.
Definition dispatcher.h:35
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
void replace_part(struct EnterState *es, size_t from, const char *buf)
Search and replace on a buffer.
Definition functions.c:142
Edit a string.
static enum FunctionRetval complete_pattern(struct EnterWindowData *wdata, int op)
Complete a NeoMutt Pattern - Implements CompleteOps::complete() -.
Definition complete.c:52
bool dlg_pattern(struct Buffer *buf)
Show menu to select a Pattern -.
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:257
Convenience wrapper for the library headers.
static bool is_pattern_prefix(wchar_t c)
Check if a character is a pattern prefix.
Definition complete.c:44
const struct CompleteOps CompletePatternOps
Auto-Completion of Patterns.
Definition complete.c:97
Match patterns to emails.
char * data
Pointer to data.
Definition buffer.h:37
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:51
int tabs
Number of times the user has hit tab.
Definition wdata.h:68
struct CompletionData * cd
Auto-completion state data.
Definition wdata.h:72
struct Buffer * buffer
struct Buffer for the result
Definition wdata.h:53
struct EnterState * state
Current state of text entry.
Definition wdata.h:55