NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.c File Reference

Sidebar functions. More...

#include "config.h"
#include <stdbool.h>
#include <string.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "functions.h"
#include "lib.h"
#include "editor/lib.h"
#include "fuzzy/lib.h"
#include "history/lib.h"
#include "index/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "module_data.h"
+ Include dependency graph for functions.c:

Go to the source code of this file.

Functions

void sidebar_init_keys (struct NeoMutt *n, struct SubMenu *sm_generic)
 Initialise the Sidebar Keybindings - Implements ::init_keys_api.
 
struct SubMenusidebar_get_submenu (void)
 Get the Sidebar SubMenu.
 
bool sb_next (struct SidebarWindowData *wdata)
 Find the next unhidden Mailbox.
 
static bool sb_next_n (struct SidebarWindowData *wdata, int count)
 Move down N unhidden Mailboxes, capping at the last.
 
static bool sb_prev_n (struct SidebarWindowData *wdata, int count)
 Move up N unhidden Mailboxes, capping at the first.
 
static struct SbEntry ** sb_next_new (struct SidebarWindowData *wdata, size_t begin, size_t end)
 Return the next mailbox with new messages.
 
bool sb_prev (struct SidebarWindowData *wdata)
 Find the previous unhidden Mailbox.
 
static struct SbEntry ** sb_prev_new (struct SidebarWindowData *wdata, size_t begin, size_t end)
 Return the previous mailbox with new messages.
 
static int op_sidebar_first (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the first unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_last (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the last unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_next (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the next unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_next_new (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the next new mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_open (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Open highlighted mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_page_down (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the first entry in the next page of mailboxes - Implements sidebar_function_t -.
 
static int op_sidebar_page_up (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the last entry in the previous page of mailboxes - Implements sidebar_function_t -.
 
static int op_sidebar_prev (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the previous unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_prev_new (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the previous new mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_toggle_visible (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Make the sidebar (in)visible - Implements sidebar_function_t -.
 
static int op_sidebar_toggle_virtual (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Deprecated - Implements sidebar_function_t -.
 
static void sidebar_matcher_cb (const char *text, void *data)
 React to keys as they are entered - Implements get_field_callback_t.
 
static int op_sidebar_abort_search (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Close the Sidebar Search - Implements sidebar_function_t -.
 
static int op_sidebar_start_search (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the last unhidden mailbox - Implements sidebar_function_t -.
 
int sb_function_dispatcher (struct MuttWindow *win, const struct KeyEvent *event)
 Perform a Sidebar function - Implements function_dispatcher_t -.
 

Variables

static const struct MenuFuncOp OpSidebar []
 Functions for the Sidebar Window.
 
const struct MenuOpSeq SidebarDefaultBindings []
 Key bindings for the Sidebar Window.
 
static const struct SidebarFunction SidebarFunctions []
 All the NeoMutt functions that the Sidebar supports.
 

Detailed Description

Sidebar 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.

Function Documentation

◆ sidebar_init_keys()

void sidebar_init_keys ( struct NeoMutt * n,
struct SubMenu * sm_generic )

Initialise the Sidebar Keybindings - Implements ::init_keys_api.

Definition at line 82 of file functions.c.

83{
85 ASSERT(mod_data);
86
87 struct MenuDefinition *md = NULL;
88 struct SubMenu *sm = NULL;
89 struct SubMenu *sm_editor = editor_get_submenu();
90 ASSERT(sm_editor);
91
93 md = km_register_menu(MENU_SIDEBAR, "sidebar");
94 km_menu_add_submenu(md, sm);
95 km_menu_add_submenu(md, sm_editor);
97
98 mod_data->md_sidebar = md;
99 mod_data->sm_sidebar = sm;
100}
struct SubMenu * editor_get_submenu(void)
Get the Editor SubMenu.
Definition functions.c:587
void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
Add a SubMenu to a Menu Definition.
Definition init.c:121
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:87
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:104
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:134
@ MODULE_ID_SIDEBAR
ModuleSidebar, Sidebar
Definition module_api.h:91
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
const struct MenuOpSeq SidebarDefaultBindings[]
Key bindings for the Sidebar Window.
Definition functions.c:72
static const struct MenuFuncOp OpSidebar[]
Functions for the Sidebar Window.
Definition functions.c:52
#define ASSERT(COND)
Definition signal2.h:59
Functions for a Dialog or Window.
Definition menu.h:77
Sidebar private Module data.
Definition module_data.h:32
struct MenuDefinition * md_sidebar
Sidebar Menu Definition.
Definition module_data.h:34
struct SubMenu * sm_sidebar
Sidebar functions.
Definition module_data.h:35
Collection of related functions.
Definition menu.h:65
@ MENU_SIDEBAR
Sidebar menu.
Definition type.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sidebar_get_submenu()

struct SubMenu * sidebar_get_submenu ( void )

Get the Sidebar SubMenu.

Return values
ptrSidebar SubMenu

Definition at line 106 of file functions.c.

107{
109 ASSERT(mod_data);
110
111 return mod_data->sm_sidebar;
112}
Container for Accounts, Notifications.
Definition neomutt.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_next()

bool sb_next ( struct SidebarWindowData * wdata)

Find the next unhidden Mailbox.

Parameters
wdataSidebar data
Return values
trueMailbox found

Definition at line 119 of file functions.c.

120{
121 struct SbEntry **sbep = NULL;
122 ARRAY_FOREACH_FROM(sbep, &wdata->entries, wdata->hil_index + 1)
123 {
124 if (!(*sbep)->is_hidden)
125 {
126 wdata->hil_index = ARRAY_FOREACH_IDX_sbep;
127 return true;
128 }
129 }
130
131 return false;
132}
#define ARRAY_FOREACH_FROM(elem, head, from)
Iterate from an index to the end.
Definition array.h:235
Info about folders in the sidebar.
Definition private.h:40
int hil_index
Highlighted mailbox.
Definition private.h:96
struct SbEntryArray entries
Items to display in the sidebar.
Definition private.h:92
+ Here is the caller graph for this function:

◆ sb_next_n()

static bool sb_next_n ( struct SidebarWindowData * wdata,
int count )
static

Move down N unhidden Mailboxes, capping at the last.

Parameters
wdataSidebar data
countNumber of entries to move
Return values
trueMoved at least one entry
falseAlready at the last unhidden entry

Definition at line 141 of file functions.c.

142{
143 int orig = wdata->hil_index;
144 for (int i = 0; i < count; i++)
145 {
146 if (!sb_next(wdata))
147 break;
148 }
149 return (wdata->hil_index != orig);
150}
bool sb_next(struct SidebarWindowData *wdata)
Find the next unhidden Mailbox.
Definition functions.c:119
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_prev_n()

static bool sb_prev_n ( struct SidebarWindowData * wdata,
int count )
static

Move up N unhidden Mailboxes, capping at the first.

Parameters
wdataSidebar data
countNumber of entries to move
Return values
trueMoved at least one entry
falseAlready at the first unhidden entry

Definition at line 159 of file functions.c.

160{
161 int orig = wdata->hil_index;
162 for (int i = 0; i < count; i++)
163 {
164 if (!sb_prev(wdata))
165 break;
166 }
167 return (wdata->hil_index != orig);
168}
bool sb_prev(struct SidebarWindowData *wdata)
Find the previous unhidden Mailbox.
Definition functions.c:194
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_next_new()

static struct SbEntry ** sb_next_new ( struct SidebarWindowData * wdata,
size_t begin,
size_t end )
static

Return the next mailbox with new messages.

Parameters
wdataSidebar data
beginStarting index for searching
endEnding index for searching
Return values
ptrPointer to the first entry with new messages
NULLNone could be found

Definition at line 178 of file functions.c.

179{
180 struct SbEntry **sbep = NULL;
181 ARRAY_FOREACH_FROM_TO(sbep, &wdata->entries, begin, end)
182 {
183 if ((*sbep)->mailbox->has_new || ((*sbep)->mailbox->msg_unread != 0))
184 return sbep;
185 }
186 return NULL;
187}
#define ARRAY_FOREACH_FROM_TO(elem, head, from, to)
Iterate between two indexes.
Definition array.h:261
+ Here is the caller graph for this function:

◆ sb_prev()

bool sb_prev ( struct SidebarWindowData * wdata)

Find the previous unhidden Mailbox.

Parameters
wdataSidebar data
Return values
trueMailbox found

Definition at line 194 of file functions.c.

195{
196 struct SbEntry **sbep = NULL, **prev = NULL;
197 ARRAY_FOREACH_TO(sbep, &wdata->entries, wdata->hil_index)
198 {
199 if (!(*sbep)->is_hidden)
200 prev = sbep;
201 }
202
203 if (prev)
204 {
205 wdata->hil_index = ARRAY_IDX(&wdata->entries, prev);
206 return true;
207 }
208
209 return false;
210}
#define ARRAY_IDX(head, elem)
Return the index of an element of the array.
Definition array.h:324
#define ARRAY_FOREACH_TO(elem, head, to)
Iterate from the beginning to an index.
Definition array.h:247
+ Here is the caller graph for this function:

◆ sb_prev_new()

static struct SbEntry ** sb_prev_new ( struct SidebarWindowData * wdata,
size_t begin,
size_t end )
static

Return the previous mailbox with new messages.

Parameters
wdataSidebar data
beginStarting index for searching
endEnding index for searching
Return values
ptrPointer to the first entry with new messages
NULLNone could be found

Definition at line 220 of file functions.c.

221{
222 struct SbEntry **sbep = NULL, **prev = NULL;
223 ARRAY_FOREACH_FROM_TO(sbep, &wdata->entries, begin, end)
224 {
225 if ((*sbep)->mailbox->has_new || ((*sbep)->mailbox->msg_unread != 0))
226 prev = sbep;
227 }
228
229 return prev;
230}
+ Here is the caller graph for this function:

◆ sidebar_matcher_cb()

static void sidebar_matcher_cb ( const char * text,
void * data )
static

React to keys as they are entered - Implements get_field_callback_t.

Definition at line 528 of file functions.c.

529{
530 struct MuttWindow *win = data;
531 struct SidebarWindowData *wdata = win->wdata;
532 wdata->hil_index = -1;
533 wdata->repage = true;
534
535 struct SbEntry **sbep = NULL;
536
537 if (text[0] == '\0')
538 {
539 ARRAY_FOREACH(sbep, &wdata->entries)
540 {
541 struct SbEntry *sbe = *sbep;
542 sbe->mailbox->visible = true;
543 sbe->score = -1;
544 if (wdata->hil_index == -1)
545 wdata->hil_index = ARRAY_FOREACH_IDX_sbep;
546 }
547 wdata->win->actions |= WA_RECALC;
548 return;
549 }
550
551 struct FuzzyOptions opts = { .smart_case = true };
552 struct FuzzyResult result = { 0 };
553 int best_score = -1;
554 int best_index = -1;
555 struct Buffer *buf = buf_pool_get();
556
557 ARRAY_FOREACH(sbep, &wdata->entries)
558 {
559 struct SbEntry *sbe = *sbep;
560 buf_printf(buf, "%s %s", sbe->box, sbe->display);
561 int score = fuzzy_match(text, buf_string(buf), FUZZY_ALGO_SUBSEQ, &opts, &result);
562 if (score > 0)
563 {
564 // Extra 2 points for new (unseen) mail
565 // 1 point for old (seen) mail
566 score += (2 * sbe->mailbox->msg_new);
567 score += (sbe->mailbox->msg_unread - sbe->mailbox->msg_new);
568 }
569 sbe->score = score;
570 if (score >= 0)
571 {
572 if ((best_score == -1) || (score > best_score))
573 {
574 best_score = score;
575 best_index = ARRAY_FOREACH_IDX_sbep;
576 }
577 sbe->mailbox->visible = true;
578 }
579 else
580 {
581 sbe->mailbox->visible = false;
582 }
583 }
584
585 if (best_index != -1)
586 wdata->hil_index = best_index;
587
588 wdata->win->actions |= WA_RECALC;
589 buf_pool_release(&buf);
590}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
@ FUZZY_ALGO_SUBSEQ
Subsequence matching algorithm.
Definition lib.h:77
int fuzzy_match(const char *pattern, const char *candidate, enum FuzzyAlgo algo, const struct FuzzyOptions *opts, struct FuzzyResult *out)
Perform fuzzy matching.
Definition fuzzy.c:58
@ WA_RECALC
Recalculate the contents of the Window.
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
String manipulation buffer.
Definition buffer.h:36
Options for fuzzy matching.
Definition lib.h:87
Result of a fuzzy match.
Definition lib.h:98
int msg_new
Number of new messages.
Definition mailbox.h:94
bool visible
True if a result of "mailboxes".
Definition mailbox.h:132
int msg_unread
Number of unread messages.
Definition mailbox.h:91
void * wdata
Private data.
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
int score
Fuzzy-match score.
Definition private.h:47
char display[256]
Formatted string to display.
Definition private.h:42
struct Mailbox * mailbox
Mailbox this represents.
Definition private.h:44
char box[256]
Mailbox path (possibly abbreviated)
Definition private.h:41
Sidebar private Window data -.
Definition private.h:89
struct MuttWindow * win
Sidebar Window.
Definition private.h:90
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ OpSidebar

const struct MenuFuncOp OpSidebar[]
static
Initial value:
= {
{ "sidebar-first", OP_SIDEBAR_FIRST },
{ "sidebar-last", OP_SIDEBAR_LAST },
{ "sidebar-next", OP_SIDEBAR_NEXT },
{ "sidebar-next-new", OP_SIDEBAR_NEXT_NEW },
{ "sidebar-open", OP_SIDEBAR_OPEN },
{ "sidebar-page-down", OP_SIDEBAR_PAGE_DOWN },
{ "sidebar-page-up", OP_SIDEBAR_PAGE_UP },
{ "sidebar-prev", OP_SIDEBAR_PREV },
{ "sidebar-prev-new", OP_SIDEBAR_PREV_NEW },
{ "sidebar-abort-search", OP_SIDEBAR_ABORT_SEARCH },
{ "sidebar-start-search", OP_SIDEBAR_START_SEARCH },
{ "sidebar-toggle-virtual", OP_SIDEBAR_TOGGLE_VIRTUAL },
{ "sidebar-toggle-visible", OP_SIDEBAR_TOGGLE_VISIBLE },
{ NULL, 0 },
}

Functions for the Sidebar Window.

Definition at line 52 of file functions.c.

52 { /* map: sidebar */
53 { "sidebar-first", OP_SIDEBAR_FIRST },
54 { "sidebar-last", OP_SIDEBAR_LAST },
55 { "sidebar-next", OP_SIDEBAR_NEXT },
56 { "sidebar-next-new", OP_SIDEBAR_NEXT_NEW },
57 { "sidebar-open", OP_SIDEBAR_OPEN },
58 { "sidebar-page-down", OP_SIDEBAR_PAGE_DOWN },
59 { "sidebar-page-up", OP_SIDEBAR_PAGE_UP },
60 { "sidebar-prev", OP_SIDEBAR_PREV },
61 { "sidebar-prev-new", OP_SIDEBAR_PREV_NEW },
62 { "sidebar-abort-search", OP_SIDEBAR_ABORT_SEARCH },
63 { "sidebar-start-search", OP_SIDEBAR_START_SEARCH },
64 { "sidebar-toggle-virtual", OP_SIDEBAR_TOGGLE_VIRTUAL },
65 { "sidebar-toggle-visible", OP_SIDEBAR_TOGGLE_VISIBLE },
66 { NULL, 0 },
67};

◆ SidebarDefaultBindings

const struct MenuOpSeq SidebarDefaultBindings[]
Initial value:
= {
{ OP_SIDEBAR_NEXT, "<down>" },
{ OP_SIDEBAR_PREV, "<up>" },
{ 0, NULL },
}

Key bindings for the Sidebar Window.

Definition at line 72 of file functions.c.

72 {
73 { OP_SIDEBAR_NEXT, "<down>" },
74 { OP_SIDEBAR_PREV, "<up>" },
75 { 0, NULL },
76};

◆ SidebarFunctions

const struct SidebarFunction SidebarFunctions[]
static
Initial value:
= {
{ OP_SIDEBAR_FIRST, op_sidebar_first },
{ OP_SIDEBAR_LAST, op_sidebar_last },
{ OP_SIDEBAR_NEXT, op_sidebar_next },
{ OP_SIDEBAR_NEXT_NEW, op_sidebar_next_new },
{ OP_SIDEBAR_OPEN, op_sidebar_open },
{ OP_SIDEBAR_PAGE_DOWN, op_sidebar_page_down },
{ OP_SIDEBAR_PAGE_UP, op_sidebar_page_up },
{ OP_SIDEBAR_PREV, op_sidebar_prev },
{ OP_SIDEBAR_PREV_NEW, op_sidebar_prev_new },
{ OP_SIDEBAR_TOGGLE_VIRTUAL, op_sidebar_toggle_virtual },
{ OP_SIDEBAR_TOGGLE_VISIBLE, op_sidebar_toggle_visible },
{ OP_SIDEBAR_ABORT_SEARCH, op_sidebar_abort_search },
{ OP_SIDEBAR_START_SEARCH, op_sidebar_start_search },
{ 0, NULL },
}
static int op_sidebar_next(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Selects the next unhidden mailbox - Implements sidebar_function_t -.
Definition functions.c:288
static int op_sidebar_start_search(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Selects the last unhidden mailbox - Implements sidebar_function_t -.
Definition functions.c:610
static int op_sidebar_toggle_visible(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Make the sidebar (in)visible - Implements sidebar_function_t -.
Definition functions.c:508
static int op_sidebar_page_up(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Selects the last entry in the previous page of mailboxes - Implements sidebar_function_t -.
Definition functions.c:405
static int op_sidebar_toggle_virtual(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Deprecated - Implements sidebar_function_t -.
Definition functions.c:519
static int op_sidebar_abort_search(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Close the Sidebar Search - Implements sidebar_function_t -.
Definition functions.c:597
static int op_sidebar_prev(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Selects the previous unhidden mailbox - Implements sidebar_function_t -.
Definition functions.c:436
static int op_sidebar_page_down(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Selects the first entry in the next page of mailboxes - Implements sidebar_function_t -.
Definition functions.c:374
static int op_sidebar_last(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Selects the last unhidden mailbox - Implements sidebar_function_t -.
Definition functions.c:263
static int op_sidebar_first(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Selects the first unhidden mailbox - Implements sidebar_function_t -.
Definition functions.c:237
static int op_sidebar_open(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Open highlighted mailbox - Implements sidebar_function_t -.
Definition functions.c:359
static int op_sidebar_next_new(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Selects the next new mailbox - Implements sidebar_function_t -.
Definition functions.c:321
static int op_sidebar_prev_new(struct SidebarFunctionData *fdata, const struct KeyEvent *event)
Selects the previous new mailbox - Implements sidebar_function_t -.
Definition functions.c:469

All the NeoMutt functions that the Sidebar supports.

Definition at line 692 of file functions.c.

692 {
693 // clang-format off
694 { OP_SIDEBAR_FIRST, op_sidebar_first },
695 { OP_SIDEBAR_LAST, op_sidebar_last },
696 { OP_SIDEBAR_NEXT, op_sidebar_next },
697 { OP_SIDEBAR_NEXT_NEW, op_sidebar_next_new },
698 { OP_SIDEBAR_OPEN, op_sidebar_open },
699 { OP_SIDEBAR_PAGE_DOWN, op_sidebar_page_down },
700 { OP_SIDEBAR_PAGE_UP, op_sidebar_page_up },
701 { OP_SIDEBAR_PREV, op_sidebar_prev },
702 { OP_SIDEBAR_PREV_NEW, op_sidebar_prev_new },
703 { OP_SIDEBAR_TOGGLE_VIRTUAL, op_sidebar_toggle_virtual },
704 { OP_SIDEBAR_TOGGLE_VISIBLE, op_sidebar_toggle_visible },
705 { OP_SIDEBAR_ABORT_SEARCH, op_sidebar_abort_search },
706 { OP_SIDEBAR_START_SEARCH, op_sidebar_start_search },
707 { 0, NULL },
708 // clang-format on
709};