Skip to content

Commit

Permalink
Implement option to start searches at the current position
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Sep 25, 2024
1 parent 6c83c7c commit 52d2ceb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Doc/cmus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,10 @@ rewind_offset (5) [-1-9999]
scroll_offset (2) [0-9999]
Minimal number of screen lines to keep above and below the cursor.

search_start_beginning (true)
Starts searches at the beginning of the current view rather than the
current item.

show_all_tracks (true)
Display all tracks of the artist when the artist is selected in the tree
view. This option is tightly coupled to the auto_expand_albums_\*
Expand Down
17 changes: 17 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ int tree_width_max = 0;
int pause_on_output_change = 0;
int block_key_paste = 1;
int progress_bar = 1;
int search_start_beginning = 1;

int colors[NR_COLORS] = {
-1,
Expand Down Expand Up @@ -1393,6 +1394,21 @@ static void toggle_progress_bar(void *data)
update_statusline();
}

static void get_search_start_beginning(void *data, char *buf, size_t size)
{
strscpy(buf, bool_names[search_start_beginning], size);
}

static void set_search_start_beginning(void *data, const char *buf)
{
parse_bool(buf, &search_start_beginning);
}

static void toggle_search_start_beginning(void *data)
{
search_start_beginning ^= 1;
}

/* }}} */

/* special callbacks (id set) {{{ */
Expand Down Expand Up @@ -1665,6 +1681,7 @@ static const struct {
DN(pl_env_vars)
DT(block_key_paste)
DT(progress_bar)
DT(search_start_beginning)
{ NULL, NULL, NULL, NULL, 0 }
};

Expand Down
1 change: 1 addition & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ extern int tree_width_max;
extern int pause_on_output_change;
extern int block_key_paste;
extern int progress_bar;
extern int search_start_beginning;

extern const char * const aaa_mode_names[];
extern const char * const view_names[NR_VIEWS + 1];
Expand Down
3 changes: 2 additions & 1 deletion search_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "xstrjoin.h"
#include "misc.h"
#include "lib.h"
#include "options.h"
#include "command_mode.h"
#include "keys.h"

Expand Down Expand Up @@ -199,7 +200,7 @@ void search_mode_ch(uchar ch)
return;
} else {
/* start from beginning if this is first char */
int beginning = search_line_empty();
int beginning = search_start_beginning && search_line_empty();

/* save old value
*
Expand Down

0 comments on commit 52d2ceb

Please sign in to comment.