• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

neomutt / neomutt / 21576993800

02 Feb 2026 01:15AM UTC coverage: 42.169% (+0.2%) from 42.019%
21576993800

push

github

flatcap
build: force all-docs before validation

11846 of 28092 relevant lines covered (42.17%)

447.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pattern/complete.c
1
/**
2
 * @file
3
 * Pattern Auto-Completion
4
 *
5
 * @authors
6
 * Copyright (C) 2023 Richard Russon <rich@flatcap.org>
7
 *
8
 * @copyright
9
 * This program is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU General Public License as published by the Free Software
11
 * Foundation, either version 2 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU General Public License along with
20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22

23
/**
24
 * @page pattern_complete Pattern Auto-Completion
25
 *
26
 * Pattern Auto-Completion
27
 */
28

29
#include "config.h"
30
#include <stddef.h>
31
#include "mutt/lib.h"
32
#include "core/lib.h"
33
#include "gui/lib.h"
34
#include "lib.h"
35
#include "complete/lib.h"
36
#include "editor/lib.h"
37

38
/**
39
 * is_pattern_prefix - Check if a character is a pattern prefix
40
 * @param c Character to check
41
 * @retval true  Character is a pattern prefix (~, %, or =)
42
 * @retval false Character is not a pattern prefix
43
 */
44
static bool is_pattern_prefix(wchar_t c)
45
{
46
  return (c == '~') || (c == '%') || (c == '=');
×
47
}
48

49
/**
50
 * complete_pattern - Complete a NeoMutt Pattern - Implements CompleteOps::complete() - @ingroup compapi_complete
51
 */
52
static enum FunctionRetval complete_pattern(struct EnterWindowData *wdata, int op)
×
53
{
54
  if (!wdata || ((op != OP_EDITOR_COMPLETE) && (op != OP_EDITOR_COMPLETE_QUERY)))
×
55
    return FR_NO_ACTION;
56

57
  size_t i = wdata->state->curpos;
×
58

59
  // Check if cursor is right after a pattern prefix (~, %, or =)
60
  if (i && is_pattern_prefix(wdata->state->wbuf[i - 1]))
×
61
  {
62
    if (dlg_pattern(wdata->buffer))
×
63
      replace_part(wdata->state, i - 1, wdata->buffer->data);
×
64
    buf_fix_dptr(wdata->buffer);
×
65
    return FR_CONTINUE;
×
66
  }
67

68
  // Search backwards for a pattern prefix
69
  for (; (i > 0) && !is_pattern_prefix(wdata->state->wbuf[i - 1]); i--)
×
70
    ; // do nothing
71

72
  if ((i > 0) && (i < wdata->state->curpos) &&
×
73
      (wdata->state->wbuf[i - 1] == '~') && (wdata->state->wbuf[i] == 'y'))
×
74
  {
75
    // Label completion for ~y pattern
76
    i++;
×
77
    buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf + i, wdata->state->curpos - i);
×
78
    int rc = mutt_label_complete(wdata->cd, wdata->buffer, wdata->tabs);
×
79
    replace_part(wdata->state, i, wdata->buffer->data);
×
80
    buf_fix_dptr(wdata->buffer);
×
81
    if (rc != 1)
×
82
    {
83
      return FR_CONTINUE;
84
    }
85
  }
86
  else
87
  {
88
    return FR_NO_ACTION;
89
  }
90

91
  return FR_SUCCESS;
92
}
93

94
/**
95
 * CompletePatternOps - Auto-Completion of Patterns
96
 */
97
const struct CompleteOps CompletePatternOps = {
98
  .complete = complete_pattern,
99
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc