NeoMutt  2024-12-12-14-g7b49f7
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 <stdbool.h>
31#include <stddef.h>
32#include <wchar.h>
33#include "mutt/lib.h"
34#include "core/lib.h"
35#include "gui/lib.h"
36#include "lib.h"
37#include "complete/lib.h"
38#include "editor/lib.h"
39#include "history/lib.h"
40#include "mutt_mailbox.h"
41#include "muttlib.h"
42
47{
48 if (!wdata)
49 return FR_NO_ACTION;
50
51 struct FileCompletionData *cdata = wdata->cdata;
52
53 if (op == OP_EDITOR_MAILBOX_CYCLE)
54 {
55 wdata->first = true; /* clear input if user types a real key later */
56 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
57 mutt_mailbox_next(cdata->mailbox, wdata->buffer);
58
59 wdata->state->curpos = wdata->state->lastchar = mutt_mb_mbstowcs(
60 &wdata->state->wbuf, &wdata->state->wbuflen, 0, buf_string(wdata->buffer));
61 return FR_SUCCESS;
62 }
63
64 if ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY))
65 return FR_NO_ACTION;
66
67 int rc = FR_SUCCESS;
68 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->curpos);
69
70 /* see if the path has changed from the last time */
71 if ((!wdata->tempbuf && !wdata->state->lastchar) ||
72 (wdata->tempbuf && (wdata->templen == wdata->state->lastchar) &&
73 (wmemcmp(wdata->tempbuf, wdata->state->wbuf, wdata->state->lastchar) == 0)))
74 {
76 if (wdata->hclass == HC_MAILBOX)
77 flags |= MUTT_SEL_FOLDER;
78 if (cdata->multiple)
79 flags |= MUTT_SEL_MULTI;
80
81 dlg_browser(wdata->buffer, flags, cdata->mailbox, cdata->files, cdata->numfiles);
82 if (!buf_is_empty(wdata->buffer))
83 {
85 if (!wdata->pass)
86 mutt_hist_add(wdata->hclass, buf_string(wdata->buffer), true);
87 wdata->done = true;
88 return FR_SUCCESS;
89 }
90
91 /* file selection cancelled */
92 return FR_CONTINUE;
93 }
94
95 if (mutt_complete(wdata->cd, wdata->buffer) == 0)
96 {
97 wdata->templen = wdata->state->lastchar;
98 MUTT_MEM_REALLOC(&wdata->tempbuf, wdata->templen, wchar_t);
99 if (wdata->tempbuf)
100 wmemcpy(wdata->tempbuf, wdata->state->wbuf, wdata->templen);
101 }
102 else
103 {
104 return FR_ERROR; // let the user know that nothing matched
105 }
106 replace_part(wdata->state, 0, buf_string(wdata->buffer));
107 return rc;
108}
109
114{
115 if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
116 return FR_NO_ACTION;
117
118 int rc = FR_SUCCESS;
119 size_t i;
120 for (i = wdata->state->curpos;
121 (i > 0) && !mutt_mb_is_shell_char(wdata->state->wbuf[i - 1]); i--)
122 {
123 }
124 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
125 if (wdata->tempbuf && (wdata->templen == (wdata->state->lastchar - i)) &&
126 (wmemcmp(wdata->tempbuf, wdata->state->wbuf + i, wdata->state->lastchar - i) == 0))
127 {
128 dlg_browser(wdata->buffer, MUTT_SEL_NO_FLAGS, NULL, NULL, NULL);
129 if (!buf_is_empty(wdata->buffer))
130 replace_part(wdata->state, i, buf_string(wdata->buffer));
131 return FR_CONTINUE;
132 }
133
134 if (mutt_complete(wdata->cd, wdata->buffer) == 0)
135 {
136 wdata->templen = wdata->state->lastchar - i;
137 MUTT_MEM_REALLOC(&wdata->tempbuf, wdata->templen, wchar_t);
138 if (wdata->tempbuf)
139 wmemcpy(wdata->tempbuf, wdata->state->wbuf + i, wdata->templen);
140 }
141 else
142 {
143 rc = FR_ERROR;
144 }
145
146 replace_part(wdata->state, i, buf_string(wdata->buffer));
147 return rc;
148}
149
155};
156
162};
const struct CompleteOps CompleteFileOps
Auto-Completion of Files.
Definition: complete.c:153
const struct CompleteOps CompleteMailboxOps
Auto-Completion of Files / Mailboxes.
Definition: complete.c:160
#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:46
enum FunctionRetval complete_file_simple(struct EnterWindowData *wdata, int op)
Complete a filename - Implements CompleteOps::complete() -.
Definition: complete.c:113
void dlg_browser(struct Buffer *file, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
Let the user select a file -.
Definition: dlg_browser.c:853
Convenience wrapper for the gui headers.
Read/write command history from/to a file.
@ HC_MAILBOX
Mailboxes.
Definition: lib.h:59
void mutt_hist_add(enum HistoryClass hclass, const char *str, bool save)
Add a string to a history.
Definition: history.c:494
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:43
Convenience wrapper for the library headers.
struct Mailbox * mutt_mailbox_next(struct Mailbox *m_cur, struct Buffer *s)
Incoming folders completion routine.
Definition: mutt_mailbox.c:361
Mailbox helper functions.
void buf_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:519
Some miscellaneous functions.
Key value store.
enum FunctionRetval(* complete)(struct EnterWindowData *wdata, int op)
Definition: compapi.h:46
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:40
char *** files
List of files selected.
Definition: curs_lib.h:43
struct Mailbox * mailbox
Mailbox.
Definition: curs_lib.h:42
bool multiple
Allow multiple selections.
Definition: curs_lib.h:41
int * numfiles
Number of files selected.
Definition: curs_lib.h:44