NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 "key/lib.h"
#include "module_data.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, int *match)
 Search a menu.
 
static int menu_movement (struct MenuFunctionData *fdata, const struct KeyEvent *event)
 Handle all the common Menu movements - Implements menu_function_t -.
 
static int menu_search (struct MenuFunctionData *fdata, const struct KeyEvent *event)
 Handle Menu searching - Implements menu_function_t -.
 
static int op_help (struct MenuFunctionData *fdata, const struct KeyEvent *event)
 Show the help screen - Implements menu_function_t -.
 
static int op_jump (struct MenuFunctionData *fdata, const struct KeyEvent *event)
 Jump to an index number - Implements menu_function_t -.
 
int menu_function_dispatcher (struct MuttWindow *win, const struct KeyEvent *event)
 Perform a Menu function - Implements function_dispatcher_t -.
 

Variables

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 47 of file functions.c.

◆ MUTT_SEARCH_DOWN

#define MUTT_SEARCH_DOWN   2

Definition at line 48 of file functions.c.

Function Documentation

◆ search()

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

Search a menu.

Parameters
menuMenu to search
opSearch operation, e.g. OP_SEARCH_NEXT
[out]matchIndex of matching item, or -1 on failure
Return values
FR_SUCCESSMatch found
FR_NO_ACTIONSearch was cancelled
FR_ERRORSearch failed

Definition at line 59 of file functions.c.

60{
62 int reg_rc = 0;
63 int wrap = 0;
64 int search_dir;
65 int rc = FR_ERROR;
66 regex_t re = { 0 };
67 struct Buffer *buf = buf_pool_get();
68
69 *match = -1;
70
71 char *search_buf = (menu->md && (menu->md->id < MENU_MAX)) ?
72 mod_data->search_buffers[menu->md->id] :
73 NULL;
74
75 if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
76 {
77 buf_strcpy(buf, search_buf && (search_buf[0] != '\0') ? search_buf : "");
78 if ((mw_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ? _("Search for: ") : _("Reverse search for: "),
79 buf, MUTT_COMP_CLEAR, HC_OTHER, NULL, NULL) != 0) ||
80 buf_is_empty(buf))
81 {
82 rc = FR_NO_ACTION;
83 goto done;
84 }
85 if (menu->md && (menu->md->id < MENU_MAX))
86 {
87 mutt_str_replace(&mod_data->search_buffers[menu->md->id], buf_string(buf));
88 search_buf = mod_data->search_buffers[menu->md->id];
89 }
90 menu->search_dir = ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
93 }
94
95 search_dir = (menu->search_dir == MUTT_SEARCH_UP) ? -1 : 1;
96 if (op == OP_SEARCH_OPPOSITE)
97 search_dir = -search_dir;
98
99 if (search_buf)
100 {
101 uint16_t flags = mutt_mb_is_lower(search_buf) ? REG_ICASE : 0;
102 reg_rc = REG_COMP(&re, search_buf, REG_NOSUB | flags);
103 }
104
105 if (reg_rc != 0)
106 {
107 regerror(reg_rc, &re, buf->data, buf->dsize);
108 mutt_error("%s", buf_string(buf));
109 goto done;
110 }
111
112 *match = menu->current + search_dir;
113search_next:
114 if (wrap)
115 mutt_message(_("Search wrapped to top"));
116 while ((*match >= 0) && (*match < menu->max))
117 {
118 if (menu->search(menu, &re, *match) == 0)
119 {
120 regfree(&re);
121 rc = FR_SUCCESS;
122 goto done;
123 }
124
125 *match += search_dir;
126 }
127
128 const bool c_wrap_search = cs_subset_bool(menu->sub, "wrap_search");
129 if (c_wrap_search && (wrap++ == 0))
130 {
131 *match = (search_dir == 1) ? 0 : menu->max - 1;
132 goto search_next;
133 }
134 regfree(&re);
135 mutt_error(_("Not found"));
136
137done:
138 buf_pool_release(&buf);
139 return rc;
140}
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
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
@ MUTT_COMP_CLEAR
Clear input if printable character is pressed.
Definition wdata.h: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:502
#define mutt_error(...)
Definition logging2.h:94
#define mutt_message(...)
Definition logging2.h:93
@ HC_OTHER
Miscellaneous strings.
Definition lib.h:61
bool mutt_mb_is_lower(const char *s)
Does a multi-byte string contain only lowercase characters?
Definition mbyte.c:355
#define MUTT_SEARCH_DOWN
Definition functions.c:48
#define MUTT_SEARCH_UP
Definition functions.c:47
@ MODULE_ID_MENU
ModuleMenu, Menu
Definition module_api.h:77
#define _(a)
Definition message.h:28
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:284
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition regex3.h:49
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 id
Menu ID, e.g. MENU_ALIAS.
Definition menu.h:78
Menu private Module data.
Definition module_data.h:32
char * search_buffers[MENU_MAX]
Previous search string, one for each MenuType.
Definition module_data.h:34
int search_dir
Direction of search.
Definition lib.h:100
int current
Current entry.
Definition lib.h:87
int(* search)(struct Menu *menu, regex_t *rx, int line)
Definition lib.h:127
const struct MenuDefinition * md
Menu definition for keymap entries.
Definition lib.h:90
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:95
Container for Accounts, Notifications.
Definition neomutt.h:41
@ MENU_MAX
Definition type.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MenuFunctions

const struct MenuFunction MenuFunctions[]
static
Initial value:
= {
{ OP_BOTTOM_PAGE, menu_movement },
{ OP_CURRENT_BOTTOM, menu_movement },
{ OP_CURRENT_MIDDLE, menu_movement },
{ OP_CURRENT_TOP, menu_movement },
{ OP_FIRST_ENTRY, menu_movement },
{ OP_HALF_DOWN, menu_movement },
{ OP_HALF_UP, menu_movement },
{ OP_HELP, op_help },
{ OP_JUMP, op_jump },
{ OP_LAST_ENTRY, menu_movement },
{ OP_MIDDLE_PAGE, menu_movement },
{ OP_NEXT_ENTRY, menu_movement },
{ OP_NEXT_LINE, menu_movement },
{ OP_NEXT_PAGE, menu_movement },
{ OP_PREV_ENTRY, menu_movement },
{ OP_PREV_LINE, menu_movement },
{ OP_PREV_PAGE, menu_movement },
{ OP_SEARCH, menu_search },
{ OP_SEARCH_NEXT, menu_search },
{ OP_SEARCH_OPPOSITE, menu_search },
{ OP_SEARCH_REVERSE, menu_search },
{ OP_TOP_PAGE, menu_movement },
{ 0, NULL },
}
static int op_jump(struct AliasFunctionData *fdata, const struct KeyEvent *event)
Jump to an index number - Implements alias_function_t -.
Definition functions.c:320
static int op_help(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Display Help - Implements enter_function_t -.
Definition functions.c:476
static int menu_search(struct MenuFunctionData *fdata, const struct KeyEvent *event)
Handle Menu searching - Implements menu_function_t -.
Definition functions.c:265
static int menu_movement(struct MenuFunctionData *fdata, const struct KeyEvent *event)
Handle all the common Menu movements - Implements menu_function_t -.
Definition functions.c:165

All the NeoMutt functions that the Menu supports.

Definition at line 335 of file functions.c.

335 {
336 // clang-format off
337 { OP_BOTTOM_PAGE, menu_movement },
338 { OP_CURRENT_BOTTOM, menu_movement },
339 { OP_CURRENT_MIDDLE, menu_movement },
340 { OP_CURRENT_TOP, menu_movement },
341 { OP_FIRST_ENTRY, menu_movement },
342 { OP_HALF_DOWN, menu_movement },
343 { OP_HALF_UP, menu_movement },
344 { OP_HELP, op_help },
345 { OP_JUMP, op_jump },
346 { OP_LAST_ENTRY, menu_movement },
347 { OP_MIDDLE_PAGE, menu_movement },
348 { OP_NEXT_ENTRY, menu_movement },
349 { OP_NEXT_LINE, menu_movement },
350 { OP_NEXT_PAGE, menu_movement },
351 { OP_PREV_ENTRY, menu_movement },
352 { OP_PREV_LINE, menu_movement },
353 { OP_PREV_PAGE, menu_movement },
354 { OP_SEARCH, menu_search },
355 { OP_SEARCH_NEXT, menu_search },
356 { OP_SEARCH_OPPOSITE, menu_search },
357 { OP_SEARCH_REVERSE, menu_search },
358 { OP_TOP_PAGE, menu_movement },
359 { 0, NULL },
360 // clang-format on
361};