NeoMutt  2025-09-05-55-g97fc89
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 <wchar.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#include "history/lib.h"
39#include "mutt_mailbox.h"
40#include "muttlib.h"
41
46{
47 if (!wdata)
48 return FR_NO_ACTION;
49
50 struct FileCompletionData *cdata = wdata->cdata;
51
52 if (op == OP_EDITOR_MAILBOX_CYCLE)
53 {
54 wdata->first = true; /* clear input if user types a real key later */
55 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
56 mutt_mailbox_next(cdata->mailbox, wdata->buffer);
57
58 wdata->state->curpos = wdata->state->lastchar = mutt_mb_mbstowcs(
59 &wdata->state->wbuf, &wdata->state->wbuflen, 0, buf_string(wdata->buffer));
60 return FR_SUCCESS;
61 }
62
63 if ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY))
64 return FR_NO_ACTION;
65
66 int rc = FR_SUCCESS;
67 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
68
69 /* see if the path has changed from the last time */
70 if ((!wdata->tempbuf && !wdata->state->lastchar) ||
71 (wdata->tempbuf && (wdata->templen == wdata->state->lastchar) &&
72 (wmemcmp(wdata->tempbuf, wdata->state->wbuf, wdata->state->lastchar) == 0)))
73 {
75 if (wdata->hclass == HC_MAILBOX)
76 flags |= MUTT_SEL_FOLDER;
77 if (cdata->multiple)
78 flags |= MUTT_SEL_MULTI;
79
80 dlg_browser(wdata->buffer, flags, cdata->mailbox, cdata->files, cdata->numfiles);
81 if (!buf_is_empty(wdata->buffer))
82 {
84 if (!wdata->pass)
85 mutt_hist_add(wdata->hclass, buf_string(wdata->buffer), true);
86 wdata->done = true;
87 return FR_SUCCESS;
88 }
89
90 /* file selection cancelled */
91 return FR_CONTINUE;
92 }
93
94 if (mutt_complete(wdata->cd, wdata->buffer) == 0)
95 {
96 wdata->templen = wdata->state->lastchar;
97 MUTT_MEM_REALLOC(&wdata->tempbuf, wdata->templen, wchar_t);
98 if (wdata->tempbuf)
99 wmemcpy(wdata->tempbuf, wdata->state->wbuf, wdata->templen);
100 }
101 else
102 {
103 return FR_ERROR; // let the user know that nothing matched
104 }
105 replace_part(wdata->state, 0, buf_string(wdata->buffer));
106 return rc;
107}
108
113{
114 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
115 return FR_NO_ACTION;
116
117 int rc = FR_SUCCESS;
118 size_t i;
119 for (i = wdata->state->curpos;
120 (i > 0) && !mutt_mb_is_shell_char(wdata->state->wbuf[i - 1]); i--)
121 {
122 }
123 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
124 if (wdata->tempbuf && (wdata->templen == (wdata->state->lastchar - i)) &&
125 (wmemcmp(wdata->tempbuf, wdata->state->wbuf + i, wdata->state->lastchar - i) == 0))
126 {
127 dlg_browser(wdata->buffer, MUTT_SEL_NO_FLAGS, NULL, NULL, NULL);
128 if (!buf_is_empty(wdata->buffer))
129 replace_part(wdata->state, i, buf_string(wdata->buffer));
130 return FR_CONTINUE;
131 }
132
133 if (mutt_complete(wdata->cd, wdata->buffer) == 0)
134 {
135 wdata->templen = wdata->state->lastchar - i;
136 MUTT_MEM_REALLOC(&wdata->tempbuf, wdata->templen, wchar_t);
137 if (wdata->tempbuf)
138 wmemcpy(wdata->tempbuf, wdata->state->wbuf + i, wdata->templen);
139 }
140 else
141 {
142 rc = FR_ERROR;
143 }
144
145 replace_part(wdata->state, i, buf_string(wdata->buffer));
146 return rc;
147}
148
153 .complete = complete_file_simple,
154};
155
160 .complete = complete_file_mbox,
161};
const struct CompleteOps CompleteFileOps
Auto-Completion of Files.
Definition complete.c:152
const struct CompleteOps CompleteMailboxOps
Auto-Completion of Files / Mailboxes.
Definition complete.c:159
Select a Mailbox from a list.
#define MUTT_SEL_FOLDER
Select a local directory.
Definition lib.h:60
#define MUTT_SEL_MULTI
Multi-selection is enabled.
Definition lib.h:59
#define MUTT_SEL_NO_FLAGS
No flags are set.
Definition lib.h:57
uint8_t SelectFileFlags
Flags for mutt_select_file(), e.g. MUTT_SEL_MAILBOX.
Definition lib.h:56
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
int mutt_complete(struct CompletionData *cd, struct Buffer *buf)
Attempt to complete a partial pathname.
Definition complete.c:57
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_ERROR
Valid function - error occurred.
Definition dispatcher.h:38
@ 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_file_mbox(struct EnterWindowData *wdata, int op)
Complete a Mailbox - Implements CompleteOps::complete() -.
Definition complete.c:45
enum FunctionRetval complete_file_simple(struct EnterWindowData *wdata, int op)
Complete a filename - Implements CompleteOps::complete() -.
Definition complete.c:112
void dlg_browser(struct Buffer *file, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
Let the user select a file -.
Convenience wrapper for the gui headers.
Read/write command history from/to a file.
@ HC_MAILBOX
Mailboxes.
Definition lib.h:60
void mutt_hist_add(enum HistoryClass hclass, const char *str, bool save)
Add a string to a history.
Definition history.c:482
bool mutt_mb_is_shell_char(wchar_t ch)
Is character not typically part of a pathname.
Definition mbyte.c:340
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 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
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:50
Convenience wrapper for the library headers.
struct Mailbox * mutt_mailbox_next(struct Mailbox *m_cur, struct Buffer *s)
Incoming folders completion routine.
Mailbox helper functions.
void buf_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition muttlib.c:518
Some miscellaneous functions.
size_t curpos
Position of the cursor.
Definition state.h:36
size_t wbuflen
Length of buffer.
Definition state.h:34
wchar_t * wbuf
Buffer for the string being entered.
Definition state.h:33
size_t lastchar
Position of the last character.
Definition state.h:35
Data to fill the Enter Window.
Definition wdata.h:46
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
struct Buffer * buffer
struct Buffer for the result
Definition wdata.h:48
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
struct EnterState * state
Current state of text entry.
Definition wdata.h:50
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:39
char *** files
List of files selected.
Definition curs_lib.h:42
struct Mailbox * mailbox
Mailbox.
Definition curs_lib.h:41
bool multiple
Allow multiple selections.
Definition curs_lib.h:40
int * numfiles
Number of files selected.
Definition curs_lib.h:43