NeoMutt  2025-09-05-43-g177ed6
Teaching an old dog new tricks
DOXYGEN
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
functions.c File Reference

Menu functions. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "functions.h"
#include "lib.h"
#include "editor/lib.h"
#include "history/lib.h"
#include "protos.h"
#include "type.h"
+ Include dependency graph for functions.c:

Go to the source code of this file.

Macros

#define MUTT_SEARCH_UP   1
 
#define MUTT_SEARCH_DOWN   2
 

Functions

static int search (struct Menu *menu, int op)
 Search a menu.
 
static int menu_movement (struct Menu *menu, int op)
 Handle all the common Menu movements - Implements menu_function_t -.
 
static int menu_search (struct Menu *menu, int op)
 Handle Menu searching - Implements menu_function_t -.
 
static int op_help (struct Menu *menu, int op)
 Show the help screen - Implements menu_function_t -.
 
static int op_jump (struct Menu *menu, int op)
 Jump to an index number - Implements menu_function_t -.
 
int menu_function_dispatcher (struct MuttWindow *win, int op)
 Perform a Menu function - Implements function_dispatcher_t -.
 

Variables

char * SearchBuffers []
 Previous search string, one for each MenuType.
 
static const struct MenuFunction MenuFunctions []
 All the NeoMutt functions that the Menu supports.
 

Detailed Description

Menu functions.

Authors
  • Pietro Cerutti
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file functions.c.

Macro Definition Documentation

◆ MUTT_SEARCH_UP

#define MUTT_SEARCH_UP   1

Definition at line 48 of file functions.c.

◆ MUTT_SEARCH_DOWN

#define MUTT_SEARCH_DOWN   2

Definition at line 49 of file functions.c.

Function Documentation

◆ search()

static int search ( struct Menu * menu,
int op )
static

Search a menu.

Parameters
menuMenu to search
opSearch operation, e.g. OP_SEARCH_NEXT
Return values
>=0Index of matching item
-1Search failed, or was cancelled

Definition at line 58 of file functions.c.

59{
60 int rc = -1;
61 int wrap = 0;
62 int search_dir;
63 regex_t re = { 0 };
64 struct Buffer *buf = buf_pool_get();
65
66 char *search_buf = ((menu->type < MENU_MAX)) ? SearchBuffers[menu->type] : NULL;
67
68 if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
69 {
70 buf_strcpy(buf, search_buf && (search_buf[0] != '\0') ? search_buf : "");
71 if ((mw_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ? _("Search for: ") : _("Reverse search for: "),
72 buf, MUTT_COMP_CLEAR, HC_OTHER, NULL, NULL) != 0) ||
73 buf_is_empty(buf))
74 {
75 goto done;
76 }
77 if (menu->type < MENU_MAX)
78 {
80 search_buf = SearchBuffers[menu->type];
81 }
82 menu->search_dir = ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
85 }
86
87 search_dir = (menu->search_dir == MUTT_SEARCH_UP) ? -1 : 1;
88 if (op == OP_SEARCH_OPPOSITE)
89 search_dir = -search_dir;
90
91 if (search_buf)
92 {
93 uint16_t flags = mutt_mb_is_lower(search_buf) ? REG_ICASE : 0;
94 rc = REG_COMP(&re, search_buf, REG_NOSUB | flags);
95 }
96
97 if (rc != 0)
98 {
99 regerror(rc, &re, buf->data, buf->dsize);
100 mutt_error("%s", buf_string(buf));
101 rc = -1;
102 goto done;
103 }
104
105 rc = menu->current + search_dir;
106search_next:
107 if (wrap)
108 mutt_message(_("Search wrapped to top"));
109 while ((rc >= 0) && (rc < menu->max))
110 {
111 if (menu->search(menu, &re, rc) == 0)
112 {
113 regfree(&re);
114 goto done;
115 }
116
117 rc += search_dir;
118 }
119
120 const bool c_wrap_search = cs_subset_bool(menu->sub, "wrap_search");
121 if (c_wrap_search && (wrap++ == 0))
122 {
123 rc = (search_dir == 1) ? 0 : menu->max - 1;
124 goto search_next;
125 }
126 regfree(&re);
127 mutt_error(_("Not found"));
128 rc = -1;
129
130done:
131 buf_pool_release(&buf);
132 return rc;
133}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
int mw_get_field(const char *prompt, struct Buffer *buf, CompletionFlags complete, enum HistoryClass hclass, const struct CompleteOps *comp_api, void *cdata)
Ask the user for a string -.
Definition window.c:273
#define mutt_error(...)
Definition logging2.h:93
#define mutt_message(...)
Definition logging2.h:92
@ HC_OTHER
Miscellaneous strings.
Definition lib.h:59
bool mutt_mb_is_lower(const char *s)
Does a multi-byte string contain only lowercase characters?
Definition mbyte.c:354
#define MUTT_SEARCH_DOWN
Definition functions.c:49
#define MUTT_SEARCH_UP
Definition functions.c:48
char * SearchBuffers[]
Previous search string, one for each MenuType.
Definition menu.c:43
#define _(a)
Definition message.h:28
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:282
#define MUTT_COMP_CLEAR
Clear input if printable character is pressed.
Definition mutt.h:57
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:96
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition regex3.h:50
String manipulation buffer.
Definition buffer.h:36
size_t dsize
Length of data.
Definition buffer.h:39
char * data
Pointer to data.
Definition buffer.h:37
int search_dir
Direction of search.
Definition lib.h:92
int current
Current entry.
Definition lib.h:80
int(* search)(struct Menu *menu, regex_t *rx, int line)
Definition lib.h:119
enum MenuType type
Menu definition for keymap entries.
Definition lib.h:83
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:87
@ MENU_MAX
Definition type.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ SearchBuffers

char* SearchBuffers[]
extern

Previous search string, one for each MenuType.

Definition at line 43 of file menu.c.

◆ MenuFunctions

const struct MenuFunction MenuFunctions[]
static

All the NeoMutt functions that the Menu supports.

Definition at line 278 of file functions.c.

278 {
279 // clang-format off
280 { OP_BOTTOM_PAGE, menu_movement },
281 { OP_CURRENT_BOTTOM, menu_movement },
282 { OP_CURRENT_MIDDLE, menu_movement },
283 { OP_CURRENT_TOP, menu_movement },
284 { OP_FIRST_ENTRY, menu_movement },
285 { OP_HALF_DOWN, menu_movement },
286 { OP_HALF_UP, menu_movement },
287 { OP_HELP, op_help },
288 { OP_JUMP, op_jump },
289 { OP_JUMP_1, op_jump },
290 { OP_JUMP_2, op_jump },
291 { OP_JUMP_3, op_jump },
292 { OP_JUMP_4, op_jump },
293 { OP_JUMP_5, op_jump },
294 { OP_JUMP_6, op_jump },
295 { OP_JUMP_7, op_jump },
296 { OP_JUMP_8, op_jump },
297 { OP_JUMP_9, op_jump },
298 { OP_LAST_ENTRY, menu_movement },
299 { OP_MIDDLE_PAGE, menu_movement },
300 { OP_NEXT_ENTRY, menu_movement },
301 { OP_NEXT_LINE, menu_movement },
302 { OP_NEXT_PAGE, menu_movement },
303 { OP_PREV_ENTRY, menu_movement },
304 { OP_PREV_LINE, menu_movement },
305 { OP_PREV_PAGE, menu_movement },
306 { OP_SEARCH, menu_search },
307 { OP_SEARCH_NEXT, menu_search },
308 { OP_SEARCH_OPPOSITE, menu_search },
309 { OP_SEARCH_REVERSE, menu_search },
310 { OP_TOP_PAGE, menu_movement },
311 { 0, NULL },
312 // clang-format on
313};
static int op_help(struct EnterWindowData *wdata, int op)
Display Help - Implements enter_function_t -.
Definition functions.c:424
static int op_jump(struct IndexSharedData *shared, struct IndexPrivateData *priv, int op)
Jump to an index number - Implements index_function_t -.
Definition functions.c:907
static int menu_search(struct Menu *menu, int op)
Handle Menu searching - Implements menu_function_t -.
Definition functions.c:216
static int menu_movement(struct Menu *menu, int op)
Handle all the common Menu movements - Implements menu_function_t -.
Definition functions.c:140