NeoMutt  2025-12-11-694-ga89709
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 dependency graph for functions.c:

Go to the source code of this file.

Functions

void sidebar_init_keys (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 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 SidebarWindowData *wdata, const struct KeyEvent *event)
 Selects the first unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_last (struct SidebarWindowData *wdata, const struct KeyEvent *event)
 Selects the last unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_next (struct SidebarWindowData *wdata, const struct KeyEvent *event)
 Selects the next unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_next_new (struct SidebarWindowData *wdata, const struct KeyEvent *event)
 Selects the next new mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_open (struct SidebarWindowData *wdata, const struct KeyEvent *event)
 Open highlighted mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_page_down (struct SidebarWindowData *wdata, 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 SidebarWindowData *wdata, const struct KeyEvent *event)
 Selects the last entry in the previous page of mailboxes - Implements sidebar_function_t -.
 
static int op_sidebar_prev (struct SidebarWindowData *wdata, const struct KeyEvent *event)
 Selects the previous unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_prev_new (struct SidebarWindowData *wdata, const struct KeyEvent *event)
 Selects the previous new mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_toggle_visible (struct SidebarWindowData *wdata, const struct KeyEvent *event)
 Make the sidebar (in)visible - Implements sidebar_function_t -.
 
static int op_sidebar_toggle_virtual (struct SidebarWindowData *wdata, 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 SidebarWindowData *wdata, const struct KeyEvent *event)
 Close the Sidebar Search - Implements sidebar_function_t -.
 
static int op_sidebar_start_search (struct SidebarWindowData *wdata, 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

struct MenuDefinitionMdSidebar = NULL
 Sidebar Menu Definition.
 
struct SubMenuSmSidebar = NULL
 Sidebar functions.
 
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 SubMenu * sm_generic)

Initialise the Sidebar Keybindings - Implements ::init_keys_api.

Definition at line 87 of file functions.c.

88{
89 struct MenuDefinition *md = NULL;
90 struct SubMenu *sm = NULL;
91
93 md = km_register_menu(MENU_SIDEBAR, "sidebar");
94 km_menu_add_submenu(md, sm);
97
98 MdSidebar = md;
99 SmSidebar = sm;
100}
struct SubMenu * SmEditor
Editor functions.
Definition functions.c:49
void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
Add a SubMenu to a Menu Definition.
Definition init.c:123
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:91
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:107
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:136
struct MenuDefinition * MdSidebar
Sidebar Menu Definition.
Definition functions.c:48
const struct MenuOpSeq SidebarDefaultBindings[]
Key bindings for the Sidebar Window.
Definition functions.c:77
struct SubMenu * SmSidebar
Sidebar functions.
Definition functions.c:51
static const struct MenuFuncOp OpSidebar[]
Functions for the Sidebar Window.
Definition functions.c:57
Functions for a Dialog or Window.
Definition menu.h:80
Collection of related functions.
Definition menu.h:68
@ MENU_SIDEBAR
Sidebar menu.
Definition type.h:49
+ 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{
108 return SmSidebar;
109}
+ 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 116 of file functions.c.

117{
118 struct SbEntry **sbep = NULL;
119 ARRAY_FOREACH_FROM(sbep, &wdata->entries, wdata->hil_index + 1)
120 {
121 if (!(*sbep)->is_hidden)
122 {
123 wdata->hil_index = ARRAY_FOREACH_IDX_sbep;
124 return true;
125 }
126 }
127
128 return false;
129}
#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:42
int hil_index
Highlighted mailbox.
Definition private.h:98
struct SbEntryArray entries
Items to display in the sidebar.
Definition private.h:94
+ 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 139 of file functions.c.

140{
141 struct SbEntry **sbep = NULL;
142 ARRAY_FOREACH_FROM_TO(sbep, &wdata->entries, begin, end)
143 {
144 if ((*sbep)->mailbox->has_new || ((*sbep)->mailbox->msg_unread != 0))
145 return sbep;
146 }
147 return NULL;
148}
#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 155 of file functions.c.

156{
157 struct SbEntry **sbep = NULL, **prev = NULL;
158 ARRAY_FOREACH_TO(sbep, &wdata->entries, wdata->hil_index)
159 {
160 if (!(*sbep)->is_hidden)
161 prev = sbep;
162 }
163
164 if (prev)
165 {
166 wdata->hil_index = ARRAY_IDX(&wdata->entries, prev);
167 return true;
168 }
169
170 return false;
171}
#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 181 of file functions.c.

182{
183 struct SbEntry **sbep = NULL, **prev = NULL;
184 ARRAY_FOREACH_FROM_TO(sbep, &wdata->entries, begin, end)
185 {
186 if ((*sbep)->mailbox->has_new || ((*sbep)->mailbox->msg_unread != 0))
187 prev = sbep;
188 }
189
190 return prev;
191}
+ 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 424 of file functions.c.

425{
426 struct MuttWindow *win = data;
427 struct SidebarWindowData *wdata = win->wdata;
428 wdata->hil_index = -1;
429 wdata->repage = true;
430
431 struct SbEntry **sbep = NULL;
432
433 if (text[0] == '\0')
434 {
435 ARRAY_FOREACH(sbep, &wdata->entries)
436 {
437 struct SbEntry *sbe = *sbep;
438 sbe->mailbox->visible = true;
439 sbe->score = -1;
440 if (wdata->hil_index == -1)
441 wdata->hil_index = ARRAY_FOREACH_IDX_sbep;
442 }
443 wdata->win->actions |= WA_RECALC;
444 return;
445 }
446
447 struct FuzzyOptions opts = { .smart_case = true };
448 struct FuzzyResult result = { 0 };
449 int best_score = -1;
450 int best_index = -1;
451 struct Buffer *buf = buf_pool_get();
452
453 ARRAY_FOREACH(sbep, &wdata->entries)
454 {
455 struct SbEntry *sbe = *sbep;
456 buf_printf(buf, "%s %s", sbe->box, sbe->display);
457 int score = fuzzy_match(text, buf_string(buf), FUZZY_ALGO_SUBSEQ, &opts, &result);
458 if (score > 0)
459 {
460 // Extra 2 points for new (unseen) mail
461 // 1 point for old (seen) mail
462 score += (2 * sbe->mailbox->msg_new);
463 score += (sbe->mailbox->msg_unread - sbe->mailbox->msg_new);
464 }
465 sbe->score = score;
466 if (score >= 0)
467 {
468 if ((best_score == -1) || (score > best_score))
469 {
470 best_score = score;
471 best_index = ARRAY_FOREACH_IDX_sbep;
472 }
473 sbe->mailbox->visible = true;
474 }
475 else
476 {
477 sbe->mailbox->visible = false;
478 }
479 }
480
481 if (best_index != -1)
482 wdata->hil_index = best_index;
483
484 wdata->win->actions |= WA_RECALC;
485 buf_pool_release(&buf);
486}
#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
#define 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:91
bool visible
True if a result of "mailboxes".
Definition mailbox.h:129
int msg_unread
Number of unread messages.
Definition mailbox.h:88
void * wdata
Private data.
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
int score
Fuzzy-match score.
Definition private.h:49
char display[256]
Formatted string to display.
Definition private.h:44
struct Mailbox * mailbox
Mailbox this represents.
Definition private.h:46
char box[256]
Mailbox path (possibly abbreviated)
Definition private.h:43
Sidebar private Window data -.
Definition private.h:91
struct MuttWindow * win
Sidebar Window.
Definition private.h:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MdSidebar

struct MenuDefinition* MdSidebar = NULL

Sidebar Menu Definition.

Definition at line 48 of file functions.c.

◆ SmSidebar

struct SubMenu* SmSidebar = NULL

Sidebar functions.

Definition at line 51 of file functions.c.

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

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

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

77 {
78 { OP_SIDEBAR_NEXT, "<down>" },
79 { OP_SIDEBAR_PREV, "<up>" },
80 { 0, NULL },
81};

◆ 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_start_search(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Selects the last unhidden mailbox - Implements sidebar_function_t -.
Definition functions.c:504
static int op_sidebar_page_down(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Selects the first entry in the next page of mailboxes - Implements sidebar_function_t -.
Definition functions.c:306
static int op_sidebar_page_up(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Selects the last entry in the previous page of mailboxes - Implements sidebar_function_t -.
Definition functions.c:332
static int op_sidebar_last(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Selects the last unhidden mailbox - Implements sidebar_function_t -.
Definition functions.c:223
static int op_sidebar_first(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Selects the first unhidden mailbox - Implements sidebar_function_t -.
Definition functions.c:198
static int op_sidebar_prev(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Selects the previous unhidden mailbox - Implements sidebar_function_t -.
Definition functions.c:358
static int op_sidebar_open(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Open highlighted mailbox - Implements sidebar_function_t -.
Definition functions.c:292
static int op_sidebar_next(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Selects the next unhidden mailbox - Implements sidebar_function_t -.
Definition functions.c:247
static int op_sidebar_toggle_visible(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Make the sidebar (in)visible - Implements sidebar_function_t -.
Definition functions.c:404
static int op_sidebar_toggle_virtual(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Deprecated - Implements sidebar_function_t -.
Definition functions.c:415
static int op_sidebar_next_new(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Selects the next new mailbox - Implements sidebar_function_t -.
Definition functions.c:267
static int op_sidebar_abort_search(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Close the Sidebar Search - Implements sidebar_function_t -.
Definition functions.c:493
static int op_sidebar_prev_new(struct SidebarWindowData *wdata, const struct KeyEvent *event)
Selects the previous new mailbox - Implements sidebar_function_t -.
Definition functions.c:378

All the NeoMutt functions that the Sidebar supports.

Definition at line 583 of file functions.c.

583 {
584 // clang-format off
585 { OP_SIDEBAR_FIRST, op_sidebar_first },
586 { OP_SIDEBAR_LAST, op_sidebar_last },
587 { OP_SIDEBAR_NEXT, op_sidebar_next },
588 { OP_SIDEBAR_NEXT_NEW, op_sidebar_next_new },
589 { OP_SIDEBAR_OPEN, op_sidebar_open },
590 { OP_SIDEBAR_PAGE_DOWN, op_sidebar_page_down },
591 { OP_SIDEBAR_PAGE_UP, op_sidebar_page_up },
592 { OP_SIDEBAR_PREV, op_sidebar_prev },
593 { OP_SIDEBAR_PREV_NEW, op_sidebar_prev_new },
594 { OP_SIDEBAR_TOGGLE_VIRTUAL, op_sidebar_toggle_virtual },
595 { OP_SIDEBAR_TOGGLE_VISIBLE, op_sidebar_toggle_visible },
596 { OP_SIDEBAR_ABORT_SEARCH, op_sidebar_abort_search },
597 { OP_SIDEBAR_START_SEARCH, op_sidebar_start_search },
598 { 0, NULL },
599 // clang-format on
600};