NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
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
45
static
bool
is_pattern_prefix
(
wchar_t
c)
46
{
47
return
(c ==
'~'
) || (c ==
'%'
) || (c ==
'='
);
48
}
49
53
static
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
98
const
struct
CompleteOps
CompletePatternOps
= {
99
.complete =
complete_pattern
,
100
};
buf_fix_dptr
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition
buffer.c:189
mutt_label_complete
int mutt_label_complete(struct CompletionData *cd, struct Buffer *buf, int numtabs)
Complete a label name.
Definition
helpers.c:368
lib.h
Auto-completion.
lib.h
Convenience wrapper for the core headers.
FunctionRetval
FunctionRetval
Possible return values for NeoMutt functions.
Definition
dispatcher.h:33
FR_SUCCESS
@ FR_SUCCESS
Valid function - successfully performed.
Definition
dispatcher.h:40
FR_CONTINUE
@ FR_CONTINUE
Remain in the Dialog.
Definition
dispatcher.h:35
FR_NO_ACTION
@ FR_NO_ACTION
Valid function - no action performed.
Definition
dispatcher.h:38
replace_part
void replace_part(struct EnterState *es, size_t from, const char *buf)
Search and replace on a buffer.
Definition
functions.c:150
lib.h
Edit a string.
complete_pattern
static enum FunctionRetval complete_pattern(struct EnterWindowData *wdata, int op)
Complete a NeoMutt Pattern - Implements CompleteOps::complete() -.
Definition
complete.c:53
dlg_pattern
bool dlg_pattern(struct Buffer *buf)
Show menu to select a Pattern -.
Definition
dlg_pattern.c:302
lib.h
Convenience wrapper for the gui headers.
buf_mb_wcstombs
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
lib.h
Convenience wrapper for the library headers.
is_pattern_prefix
static bool is_pattern_prefix(wchar_t c)
Check if a character is a pattern prefix.
Definition
complete.c:45
CompletePatternOps
const struct CompleteOps CompletePatternOps
Auto-Completion of Patterns.
Definition
complete.c:98
lib.h
Match patterns to emails.
Buffer::data
char * data
Pointer to data.
Definition
buffer.h:37
CompleteOps
Definition
compapi.h:36
EnterState::curpos
size_t curpos
Position of the cursor.
Definition
state.h:36
EnterState::wbuf
wchar_t * wbuf
Buffer for the string being entered.
Definition
state.h:33
EnterWindowData
Data to fill the Enter Window.
Definition
wdata.h:57
EnterWindowData::tabs
int tabs
Number of times the user has hit tab.
Definition
wdata.h:74
EnterWindowData::cd
struct CompletionData * cd
Auto-completion state data.
Definition
wdata.h:78
EnterWindowData::buffer
struct Buffer * buffer
struct Buffer for the result
Definition
wdata.h:59
EnterWindowData::state
struct EnterState * state
Current state of text entry.
Definition
wdata.h:61