NeoMutt  2025-12-11-694-ga89709
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 <stdbool.h>
31#include <stddef.h>
32#include "mutt/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "lib.h"
36#include "complete/lib.h"
37#include "editor/lib.h"
38
45static bool is_pattern_prefix(wchar_t c)
46{
47 return (c == '~') || (c == '%') || (c == '=');
48}
49
53static enum FunctionRetval complete_pattern(struct EnterWindowData *wdata, int op)
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}
94
99 .complete = complete_pattern,
100};
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:368
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:151
Edit a string.
static enum FunctionRetval complete_pattern(struct EnterWindowData *wdata, int op)
Complete a NeoMutt Pattern - Implements CompleteOps::complete() -.
Definition complete.c:53
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:45
const struct CompleteOps CompletePatternOps
Auto-Completion of Patterns.
Definition complete.c:98
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