Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added supporting code that appends to registers if capitals are used #773

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,8 @@ static VbCmdResult ex_register(Client *c, const ExArg *arg)
for (idx = 0; idx < REG_SIZE; idx++) {
/* show only filled registers */
if (c->state.reg[idx]) {
/* replace all newlines */
reg = util_str_replace("\n", "^J", c->state.reg[idx]);
/* replace all newlines with enough spaces to align nicely */
reg = util_str_replace("\n", "\n ", c->state.reg[idx]);
g_string_append_printf(str, "\n\"%c %s", regchars[idx], reg);
g_free(reg);
}
Expand Down
15 changes: 14 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,17 +527,30 @@ void vb_register_add(Client *c, char buf, const char *value)
{
char *mark;
int idx;
bool shouldAppend = false;

if (!c->state.enable_register || !buf) {
return;
}

/* check if its capital letter, if yes - append, don't overwrite */
if(buf >= 'A' && buf <= 'Z') {
shouldAppend = true;
// 32 is the magic number - ASCII offset from start of uppercase
// to lowercase letters
buf = buf + 32;
}

/* make sure the mark is a valid mark char */
if ((mark = strchr(REG_CHARS, buf))) {
/* get the index of the mark char */
idx = mark - REG_CHARS;

OVERWRITE_STRING(c->state.reg[idx], value);
gchar* newcontents = value;
if(shouldAppend && c->state.reg[idx])
newcontents = g_strjoin("\n", c->state.reg[idx], value, NULL);

OVERWRITE_STRING(c->state.reg[idx], newcontents);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

#define GLOBAL_MARK_CHARS "'ABCDEFGHIJKLMNOPQRSTUVWXYZ"

#define USER_REG "abcdefghijklmnopqrstuvwxyz"
#define USER_REG "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
/* registers in order displayed for :register command */
#define REG_CHARS "\"" USER_REG ":%/;"
#define REG_SIZE (sizeof(REG_CHARS) - 1)
Expand Down