NeoMutt  2025-12-11-949-g4870ee
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
regex4.h File Reference

Regex Colour. More...

#include <stdbool.h>
#include "mutt/lib.h"
#include "attr.h"
#include "color.h"
+ Include dependency graph for regex4.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  RegexColor
 A regular expression and a color to highlight a line. More...
 

Functions

 STAILQ_HEAD (RegexColorList, RegexColor)
 
void regex_colors_init (struct ColorModuleData *mod_data)
 Initialise the Regex colours.
 
void regex_colors_reset (struct ColorModuleData *mod_data)
 Reset the Regex colours.
 
void regex_colors_cleanup (struct ColorModuleData *mod_data)
 Cleanup the Regex colours.
 
void regex_color_clear (struct RegexColor *rcol)
 Free the contents of a Regex colour.
 
void regex_color_free (struct RegexColor **ptr)
 Free a Regex colour.
 
struct RegexColorregex_color_new (void)
 Create a new RegexColor.
 
struct RegexColorList * regex_colors_get_list (enum ColorId cid)
 Return the RegexColorList for a Colour ID.
 
void regex_color_list_clear (struct RegexColorList *rcl)
 Free the contents of a RegexColorList.
 
struct RegexColorList * regex_color_list_new (void)
 Create a new RegexColorList.
 
bool regex_colors_parse_color_list (enum ColorId cid, const char *pat, struct AttrColor *ac, int *rc, struct Buffer *err)
 Parse a Regex 'color' command.
 
int regex_colors_parse_status_list (enum ColorId cid, const char *pat, struct AttrColor *ac, int match, struct Buffer *err)
 Parse a Regex 'color status' command.
 
bool regex_colors_parse_uncolor (enum ColorId cid, const char *pat)
 Parse a Regex 'uncolor' command.
 

Detailed Description

Regex Colour.

Authors
  • 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 regex4.h.

Function Documentation

◆ STAILQ_HEAD()

STAILQ_HEAD ( RegexColorList ,
RegexColor  )

◆ regex_colors_init()

void regex_colors_init ( struct ColorModuleData * mod_data)

Initialise the Regex colours.

Parameters
mod_dataColor module data

Definition at line 52 of file regex.c.

53{
54 color_debug(LL_DEBUG5, "init AttachList, BodyList, etc\n");
55 STAILQ_INIT(&mod_data->attach_list);
56 STAILQ_INIT(&mod_data->body_list);
57 STAILQ_INIT(&mod_data->header_list);
60 STAILQ_INIT(&mod_data->index_date_list);
61 STAILQ_INIT(&mod_data->index_label_list);
63 STAILQ_INIT(&mod_data->index_size_list);
64 STAILQ_INIT(&mod_data->index_tags_list);
65 STAILQ_INIT(&mod_data->index_flags_list);
66 STAILQ_INIT(&mod_data->index_list);
68 STAILQ_INIT(&mod_data->index_tag_list);
69 STAILQ_INIT(&mod_data->status_list);
70}
static int color_debug(enum LogLevel level, const char *format,...)
Definition debug.h:51
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
#define STAILQ_INIT(head)
Definition queue.h:410
struct RegexColorList index_collapsed_list
List of colours applied to a collapsed thread in the index.
Definition module_data.h:47
struct RegexColorList index_subject_list
List of colours applied to the subject in the index.
Definition module_data.h:54
struct RegexColorList attach_list
List of colours applied to the attachment headers.
Definition module_data.h:43
struct RegexColorList body_list
List of colours applied to the email body.
Definition module_data.h:44
struct RegexColorList index_flags_list
List of colours applied to the flags in the index.
Definition module_data.h:49
struct RegexColorList index_label_list
List of colours applied to the label in the index.
Definition module_data.h:50
struct RegexColorList index_tags_list
List of colours applied to the tags in the index.
Definition module_data.h:56
struct RegexColorList index_size_list
List of colours applied to the size in the index.
Definition module_data.h:53
struct RegexColorList index_list
List of default colours applied to the index.
Definition module_data.h:51
struct RegexColorList index_author_list
List of colours applied to the author in the index.
Definition module_data.h:46
struct RegexColorList header_list
List of colours applied to the email headers.
Definition module_data.h:45
struct RegexColorList index_date_list
List of colours applied to the date in the index.
Definition module_data.h:48
struct RegexColorList index_number_list
List of colours applied to the message number in the index.
Definition module_data.h:52
struct RegexColorList status_list
List of colours applied to the status bar.
Definition module_data.h:57
struct RegexColorList index_tag_list
List of colours applied to tags in the index.
Definition module_data.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_colors_reset()

void regex_colors_reset ( struct ColorModuleData * mod_data)

Reset the Regex colours.

Parameters
mod_dataColor module data

Definition at line 76 of file regex.c.

77{
78 color_debug(LL_DEBUG5, "reset regex\n");
94}
void regex_color_list_clear(struct RegexColorList *rcl)
Free the contents of a RegexColorList.
Definition regex.c:173
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_colors_cleanup()

void regex_colors_cleanup ( struct ColorModuleData * mod_data)

Cleanup the Regex colours.

Parameters
mod_dataColor module data

Definition at line 100 of file regex.c.

101{
102 regex_colors_reset(mod_data);
103}
void regex_colors_reset(struct ColorModuleData *mod_data)
Reset the Regex colours.
Definition regex.c:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_color_clear()

void regex_color_clear ( struct RegexColor * rcol)

Free the contents of a Regex colour.

Parameters
rcolRegexColor to empty
Note
The RegexColor object isn't freed

Definition at line 111 of file regex.c.

112{
113 if (!rcol)
114 return;
115
116 rcol->match = 0;
117 rcol->stop_matching = false;
118
120 FREE(&rcol->pattern);
121 regfree(&rcol->regex);
123}
void attr_color_clear(struct AttrColor *ac)
Free the contents of an AttrColor.
Definition attr.c:47
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition compile.c:836
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
regex_t regex
Compiled regex.
Definition regex4.h:40
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition regex4.h:42
struct AttrColor attr_color
Colour and attributes to apply.
Definition regex4.h:38
char * pattern
Pattern to match.
Definition regex4.h:39
bool stop_matching
Used by the pager for body patterns, to prevent the color from being retried once it fails.
Definition regex4.h:44
int match
Substring to match, 0 for old behaviour.
Definition regex4.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_color_free()

void regex_color_free ( struct RegexColor ** ptr)

Free a Regex colour.

Parameters
ptrRegexColor to free

Definition at line 129 of file regex.c.

130{
131 if (!ptr || !*ptr)
132 return;
133
134 struct RegexColor *rcol = *ptr;
135 regex_color_clear(rcol);
136
137 FREE(ptr);
138}
void regex_color_clear(struct RegexColor *rcol)
Free the contents of a Regex colour.
Definition regex.c:111
A regular expression and a color to highlight a line.
Definition regex4.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_color_new()

struct RegexColor * regex_color_new ( void )

Create a new RegexColor.

Return values
ptrNew RegexColor

Definition at line 144 of file regex.c.

145{
146 return MUTT_MEM_CALLOC(1, struct RegexColor);
147}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
+ Here is the caller graph for this function:

◆ regex_colors_get_list()

struct RegexColorList * regex_colors_get_list ( enum ColorId cid)

Return the RegexColorList for a Colour ID.

Parameters
cidColour ID, e.g. MT_COLOR_BODY
Return values
ptrRegexColorList

Definition at line 191 of file regex.c.

192{
194 switch (cid)
195 {
197 return &mod_data->attach_list;
198 case MT_COLOR_BODY:
199 return &mod_data->body_list;
200 case MT_COLOR_HEADER:
201 return &mod_data->header_list;
202 case MT_COLOR_INDEX:
203 return &mod_data->index_list;
205 return &mod_data->index_author_list;
207 return &mod_data->index_collapsed_list;
209 return &mod_data->index_date_list;
211 return &mod_data->index_flags_list;
213 return &mod_data->index_label_list;
215 return &mod_data->index_number_list;
217 return &mod_data->index_size_list;
219 return &mod_data->index_subject_list;
221 return &mod_data->index_tag_list;
223 return &mod_data->index_tags_list;
224 case MT_COLOR_STATUS:
225 return &mod_data->status_list;
226 default:
227 return NULL;
228 }
229}
@ MT_COLOR_INDEX_AUTHOR
Index: author field.
Definition color.h:87
@ MT_COLOR_HEADER
Message headers (takes a pattern)
Definition color.h:48
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition color.h:78
@ MT_COLOR_INDEX_SIZE
Index: size field.
Definition color.h:93
@ MT_COLOR_INDEX_TAGS
Index: tags field (g, J)
Definition color.h:96
@ MT_COLOR_INDEX_SUBJECT
Index: subject field.
Definition color.h:94
@ MT_COLOR_BODY
Pager: highlight body of message (takes a pattern)
Definition color.h:39
@ MT_COLOR_INDEX_DATE
Index: date field.
Definition color.h:89
@ MT_COLOR_INDEX_TAG
Index: tag field (G)
Definition color.h:95
@ MT_COLOR_ATTACH_HEADERS
MIME attachment test (takes a pattern)
Definition color.h:38
@ MT_COLOR_INDEX_LABEL
Index: label field.
Definition color.h:91
@ MT_COLOR_INDEX
Index: default colour.
Definition color.h:86
@ MT_COLOR_INDEX_NUMBER
Index: index number.
Definition color.h:92
@ MT_COLOR_INDEX_FLAGS
Index: flags field.
Definition color.h:90
@ MT_COLOR_INDEX_COLLAPSED
Index: number of messages in collapsed thread.
Definition color.h:88
@ MODULE_ID_COLOR
ModuleColor, Color
Definition module_api.h:53
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:666
Color private Module data.
Definition module_data.h:35
Container for Accounts, Notifications.
Definition neomutt.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_color_list_clear()

void regex_color_list_clear ( struct RegexColorList * rcl)

Free the contents of a RegexColorList.

Parameters
rclList to clear

Free each of the RegexColorList in a list.

Note
The list object isn't freed, only emptied

Definition at line 173 of file regex.c.

174{
175 if (!rcl)
176 return;
177
178 struct RegexColor *np = NULL, *tmp = NULL;
179 STAILQ_FOREACH_SAFE(np, rcl, entries, tmp)
180 {
181 STAILQ_REMOVE(rcl, np, RegexColor, entries);
182 regex_color_free(&np);
183 }
184}
void regex_color_free(struct RegexColor **ptr)
Free a Regex colour.
Definition regex.c:129
#define STAILQ_REMOVE(head, elm, type, field)
Definition queue.h:441
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition queue.h:400
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_color_list_new()

struct RegexColorList * regex_color_list_new ( void )

Create a new RegexColorList.

Return values
ptrNew RegexColorList

Definition at line 153 of file regex.c.

154{
155 struct RegexColorList *rcl = MUTT_MEM_CALLOC(1, struct RegexColorList);
156
157 STAILQ_INIT(rcl);
158
159 struct RegexColor *rcol = regex_color_new();
160 STAILQ_INSERT_TAIL(rcl, rcol, entries);
161
162 return rcl;
163}
struct RegexColor * regex_color_new(void)
Create a new RegexColor.
Definition regex.c:144
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:427
+ Here is the call graph for this function:

◆ regex_colors_parse_color_list()

bool regex_colors_parse_color_list ( enum ColorId cid,
const char * pat,
struct AttrColor * ac,
int * rc,
struct Buffer * err )

Parse a Regex 'color' command.

Parameters
cidColour ID, should be MT_COLOR_STATUS
patRegex pattern
acColour value to use
rcReturn code, e.g. MUTT_CMD_SUCCESS
errBuffer for error messages
Return values
trueColour was parsed

Parse a Regex 'color' command, e.g. "color index green default pattern"

Definition at line 325 of file regex.c.

328{
329 if (cid == MT_COLOR_STATUS)
330 return false;
331
332 struct RegexColorList *rcl = regex_colors_get_list(cid);
333 if (!rcl)
334 return false;
335
336 bool is_index = false;
337 switch (cid)
338 {
340 case MT_COLOR_BODY:
341 break;
342 case MT_COLOR_HEADER:
343 break;
344 case MT_COLOR_INDEX:
355 is_index = true;
356 break;
357 default:
358 return false;
359 }
360
361 *rc = add_pattern(rcl, pat, ac, err, is_index, 0);
362
363 struct Buffer *buf = buf_pool_get();
364 get_colorid_name(cid, buf);
365 color_debug(LL_DEBUG5, "NT_COLOR_SET: %s\n", buf_string(buf));
366 buf_pool_release(&buf);
367
368 if (!is_index) // else it will be logged in add_pattern()
369 {
371 struct EventColor ev_c = { cid, NULL };
373 }
374
375 return true;
376}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
void get_colorid_name(unsigned int cid, struct Buffer *buf)
Get the name of a Colour ID.
Definition commands.c:128
static enum CommandResult add_pattern(struct RegexColorList *rcl, const char *s, struct AttrColor *ac_val, struct Buffer *err, bool is_index, int match)
Associate a colour to a pattern.
Definition regex.c:244
struct RegexColorList * regex_colors_get_list(enum ColorId cid)
Return the RegexColorList for a Colour ID.
Definition regex.c:191
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition notify.c:173
@ NT_COLOR_SET
Color has been set.
Definition notify2.h:40
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition notify_type.h:41
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
struct Notify * colors_notify
Notifications: ColorId, EventColor.
Definition module_data.h:40
An Event that happened to a Colour.
Definition notify2.h:52
enum ColorId cid
Colour ID that has changed.
Definition notify2.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_colors_parse_status_list()

int regex_colors_parse_status_list ( enum ColorId cid,
const char * pat,
struct AttrColor * ac,
int match,
struct Buffer * err )

Parse a Regex 'color status' command.

Parameters
cidColour ID, should be MT_COLOR_STATUS
patRegex pattern
acColour value to use
matchUse the nth regex submatch
errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 387 of file regex.c.

389{
390 if (cid != MT_COLOR_STATUS)
391 return MUTT_CMD_ERROR;
392
394 int rc = add_pattern(&mod_data->status_list, pat, ac, err, false, match);
395 if (rc != MUTT_CMD_SUCCESS)
396 return rc;
397
398 struct Buffer *buf = buf_pool_get();
399 get_colorid_name(cid, buf);
400 color_debug(LL_DEBUG5, "NT_COLOR_SET: %s\n", buf_string(buf));
401 buf_pool_release(&buf);
402
403 struct EventColor ev_c = { cid, NULL };
405
406 return rc;
407}
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition command.h:40
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_colors_parse_uncolor()

bool regex_colors_parse_uncolor ( enum ColorId cid,
const char * pat )

Parse a Regex 'uncolor' command.

Parameters
cidColour ID, e.g. MT_COLOR_STATUS
patPattern to remove (NULL to remove all)
Return values
trueIf colours were unset

Definition at line 415 of file regex.c.

416{
417 struct RegexColorList *cl = regex_colors_get_list(cid);
418 if (!cl)
419 return false;
420
422
423 if (!pat) // Reset all patterns
424 {
425 if (STAILQ_EMPTY(cl))
426 return true;
427
428 mutt_debug(LL_NOTIFY, "NT_COLOR_RESET: [ALL]\n");
429 struct EventColor ev_c = { cid, NULL };
431
433 return true;
434 }
435
436 bool rc = false;
437 struct RegexColor *np = NULL, *prev = NULL;
438 prev = NULL;
439 STAILQ_FOREACH(np, cl, entries)
440 {
441 if (mutt_str_equal(pat, np->pattern))
442 {
443 rc = true;
444
445 color_debug(LL_DEBUG1, "Freeing pattern \"%s\" from XXX\n", pat);
446 if (prev)
447 STAILQ_REMOVE_AFTER(cl, prev, entries);
448 else
449 STAILQ_REMOVE_HEAD(cl, entries);
450
451 mutt_debug(LL_NOTIFY, "NT_COLOR_RESET: XXX\n");
452 struct EventColor ev_c = { cid, &np->attr_color };
454
455 regex_color_free(&np);
456 break;
457 }
458 prev = np;
459 }
460
461 return rc;
462}
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:50
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
@ NT_COLOR_RESET
Color has been reset/removed.
Definition notify2.h:41
#define STAILQ_REMOVE_HEAD(head, field)
Definition queue.h:461
#define STAILQ_REMOVE_AFTER(head, elm, field)
Definition queue.h:455
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
#define STAILQ_EMPTY(head)
Definition queue.h:382
+ Here is the call graph for this function:
+ Here is the caller graph for this function: