123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829 |
- /* command.c, Ait, BSD 3-Clause, Kevin Bloom, 2023,
- Derived from: Atto January 2017
- Derived from: AnthonyEditor January 93
- */
- #include "header.h"
- #include "termbox.h"
- #include "util.h"
- void quit() { done = 1; }
- void up()
- {
- curbp->b_point = lncolumn(curbp, upup(curbp, curwp, curbp->b_point),curbp->b_pcol - curwp->w_left);
- }
- void down()
- {
- curbp->b_point = lncolumn(curbp, dndn(curbp, curwp, curbp->b_point),curbp->b_pcol - curwp->w_left);
- }
- void lnbegin()
- {
- curbp->b_point = segstart(curbp, curwp, lnstart(curbp, curbp->b_point), curbp->b_point);
- }
- void version() { msg(VERSION); }
- void top() { curbp->b_point = 0; }
- void bottom()
- {
- curbp->b_point = pos(curbp, curbp->b_ebuf);
- if (curbp->b_epage < pos(curbp, curbp->b_ebuf))
- curbp->b_reframe = 1;
- }
- void block() { curbp->b_mark = curbp->b_point; }
- void copy() { copy_cut(FALSE, TRUE, FALSE); }
- void cut() { copy_cut(TRUE, TRUE, FALSE); }
- void resize_terminal()
- {
- LINES = tb_height();
- COLS = tb_width();
- MSGLINE = LINES-1;
- one_window(curwp);
- }
- void print_to_msgline(const char *msg)
- {
- printf_tb(0, MSGLINE, TB_DEFAULT, TB_DEFAULT, msg);
- tb_set_cursor(strlen(msg), MSGLINE);
- }
- void quit_ask()
- {
- if (modified_buffers() > 0) {
- const char *msg = "Modified buffers exist; really exit (y/N) ?";
- print_to_msgline(msg);
- clrtoeol(msg, MSGLINE);
- if (!yesno(FALSE)) {
- clrtoeol("", MSGLINE);
- return;
- }
- }
- quit();
- }
- void redraw()
- {
- window_t *wp;
- int i;
- for (i = 0, wp=windows[i]; wp != NULL && i < number_of_windows; i++, wp=windows[i])
- wp->w_update = TRUE;
- update_display(TRUE);
- }
- void left()
- {
- int n = prev_utf8_char_size();
- while (0 < curbp->b_point && n-- > 0)
- --curbp->b_point;
- }
- void right()
- {
- int n = utf8_size(*ptr(curbp,curbp->b_point));
- while ((curbp->b_point < pos(curbp, curbp->b_ebuf)) && n-- > 0)
- ++curbp->b_point;
- }
- /* work out number of bytes based on first byte */
- int utf8_size(char_t c)
- {
- if (c >= 192 && c < 224) return 2;
- if (c >= 224 && c < 240) return 3;
- if (c >= 240 && c < 248) return 4;
- return 1; /* if in doubt it is 1 */
- }
- int prev_utf8_char_size()
- {
- int n;
- for (n=2;n<5;n++)
- if (-1 < curbp->b_point - n && (utf8_size(*(ptr(curbp, curbp->b_point - n))) == n))
- return n;
- return 1;
- }
- void lnend()
- {
- if (curbp->b_point == pos(curbp, curbp->b_ebuf)) return; /* do nothing if EOF */
- curbp->b_point = dndn(curbp, curwp, curbp->b_point);
- point_t p = curbp->b_point;
- left();
- curbp->b_point = (*ptr(curbp, curbp->b_point) == '\n') ? curbp->b_point : p;
- }
- void wleft()
- {
- char_t *p;
- if ((!isspace(*(p = ptr(curbp, curbp->b_point))) || !is_symbol(*p)) && curbp->b_buf < p)
- --curbp->b_point;
- while ((isspace(*(p = ptr(curbp, curbp->b_point))) || is_symbol(*p)) && curbp->b_buf < p)
- --curbp->b_point;
- while (!isspace(*(p = ptr(curbp, curbp->b_point))) && !is_symbol(*p) && curbp->b_buf < p)
- --curbp->b_point;
- if(isspace(*(p = ptr(curbp, curbp->b_point))) || is_symbol(*p))
- ++curbp->b_point;
- }
- void wleftdelete()
- {
- // undoset();
- iblock();
- wleft();
- copy_cut(TRUE, TRUE, FALSE);
- }
- void pgdown()
- {
- curbp->b_page = curbp->b_point = upup(curbp, curwp, curbp->b_epage);
- while (0 < curbp->b_row--)
- down();
- curbp->b_epage = pos(curbp, curbp->b_ebuf);
- curbp->b_pcol = 0;
- }
- void pgup()
- {
- int i = curwp->w_rows;
- while (0 < --i) {
- curbp->b_page = upup(curbp, curwp, curbp->b_page);
- up();
- }
- curbp->b_pcol = 0;
- }
- void wright()
- {
- char_t *p;
- if ((!isspace(*(p = ptr(curbp, curbp->b_point))) || !is_symbol(*p)) && p < curbp->b_ebuf)
- ++curbp->b_point;
- while ((isspace(*(p = ptr(curbp, curbp->b_point))) || is_symbol(*p)) && p < curbp->b_ebuf)
- ++curbp->b_point;
- while (!isspace(*(p = ptr(curbp, curbp->b_point))) && !is_symbol(*p) && p < curbp->b_ebuf)
- ++curbp->b_point;
- }
- void wrightdelete()
- {
- // undoset();
- iblock();
- wright();
- copy_cut(TRUE, TRUE, FALSE);
- }
- void insert()
- {
- assert(curbp->b_gap <= curbp->b_egap);
- if(lastcommand != KBD_INSERT)
- undoset();
- if (curbp->b_gap == curbp->b_egap && !growgap(curbp, CHUNK))
- return;
- curbp->b_point = movegap(curbp, curbp->b_point);
- if(!undoset_flag)
- undoset();
- /* overwrite if mid line, not EOL or EOF, CR will insert as normal */
- if ((curbp->b_flags & B_OVERWRITE) && *input != '\r' && *(ptr(curbp, curbp->b_point)) != '\n' && curbp->b_point < pos(curbp,curbp->b_ebuf) ) {
- *(ptr(curbp, curbp->b_point)) = *input;
- if (curbp->b_point < pos(curbp, curbp->b_ebuf))
- ++curbp->b_point;
- } else {
- *curbp->b_gap++ = *input == '\r' ? '\n' : *input;
- curbp->b_point = pos(curbp, curbp->b_egap);
- // force reframe if scrolled off bottom of screen and at EOF
- if (curbp->b_point == pos(curbp, curbp->b_ebuf) && curbp->b_point >= curbp->b_epage) curbp->b_reframe = 1;
- }
- curbp->b_flags |= B_MODIFIED;
- undoset_flag = TRUE;
- lastcommand = KBD_INSERT;
- }
- void insert_str()
- {
- int len = strlen((const char *)input);
- assert(curbp->b_gap <= curbp->b_egap);
- undoset();
- if (curbp->b_gap == curbp->b_egap && !growgap(curbp, CHUNK))
- return;
- curbp->b_point = movegap(curbp, curbp->b_point);
- if(!undoset_flag)
- undoset();
- /* overwrite if mid line, not EOL or EOF, CR will insert as normal */
- if ((curbp->b_flags & B_OVERWRITE) && input[0] != '\r' && *(ptr(curbp, curbp->b_point)) != '\n' && curbp->b_point < pos(curbp,curbp->b_ebuf) ) {
- *(ptr(curbp, curbp->b_point)) = *input;
- if (curbp->b_point < pos(curbp, curbp->b_ebuf))
- ++curbp->b_point;
- } else {
- for(int i = 0; i < len; i++) {
- *curbp->b_gap++ = input[i] == '\r' ? '\n' : input[i];
- }
- curbp->b_point = pos(curbp, curbp->b_egap);
- // force reframe if scrolled off bottom of screen and at EOF
- if (curbp->b_point == pos(curbp, curbp->b_ebuf) && curbp->b_point >= curbp->b_epage) curbp->b_reframe = 1;
- }
- curbp->b_flags |= B_MODIFIED;
- undoset_flag = TRUE;
- }
- void insert_unicode()
- {
- int len = strlen((const char *)unicode_buf);
- assert(curbp->b_gap <= curbp->b_egap);
- if(lastcommand != KBD_INSERT)
- undoset();
- if (curbp->b_gap == curbp->b_egap && !growgap(curbp, CHUNK))
- return;
- curbp->b_point = movegap(curbp, curbp->b_point);
- if(!undoset_flag)
- undoset();
- /* overwrite if mid line, not EOL or EOF, CR will insert as normal */
- for(int i = 0; i < len; i++) {
- *curbp->b_gap++ = unicode_buf[i];
- }
- curbp->b_point = pos(curbp, curbp->b_egap);
- // force reframe if scrolled off bottom of screen and at EOF
- if (curbp->b_point == pos(curbp, curbp->b_ebuf) && curbp->b_point >= curbp->b_epage) curbp->b_reframe = 1;
- curbp->b_flags |= B_MODIFIED;
- undoset_flag = TRUE;
- unicode_buf[0] = '\0';
- lastcommand = KBD_INSERT;
- }
- void backsp()
- {
- if(lastcommand != KBD_DELETE_CHAR)
- undoset();
- curbp->b_point = movegap(curbp, curbp->b_point);
- if (curbp->b_buf < curbp->b_gap) {
- curbp->b_gap -= prev_utf8_char_size();
- curbp->b_flags |= B_MODIFIED;
- }
- curbp->b_point = pos(curbp, curbp->b_egap);
- lastcommand = KBD_DELETE_CHAR;
- }
- void delete()
- {
- if(lastcommand != KBD_DELETE_CHAR)
- undoset();
- curbp->b_point = movegap(curbp, curbp->b_point);
- if (curbp->b_egap < curbp->b_ebuf) {
- curbp->b_egap += utf8_size(*curbp->b_egap);
- curbp->b_point = pos(curbp, curbp->b_egap);
- curbp->b_flags |= B_MODIFIED;
- }
- lastcommand = KBD_DELETE_CHAR;
- }
- void gotoline()
- {
- int line;
- point_t p;
- if (getinput("Goto line: ", temp, STRBUF_S, F_CLEAR, FALSE)) {
- line = atoi(temp);
- p = line_to_point(line);
- if (p != -1) {
- curbp->b_point = p;
- curbp->b_pcol = 0;
- if (curbp->b_epage < pos(curbp, curbp->b_ebuf)) curbp->b_reframe = 1;
- msg("Line %d", line);
- } else {
- msg("Line %d, not found", line);
- }
- }
- }
- void get_current_path(char *cur_path)
- {
- int cutoff = 0;
- for(int i = strlen(curbp->b_fname) - 1; i > -1; i--) {
- if(curbp->b_fname[i] == '/') {
- cutoff = i;
- break;
- }
- }
- for(int i = 0; i <= cutoff; i++)
- cur_path[i] = curbp->b_fname[i];
- cur_path[cutoff+1] = '\0';
- }
- void insertfile()
- {
- char cur_path[NAME_MAX] = "\0";
- if(curbp->b_path) {
- get_current_path(cur_path);
- strcpy(temp, cur_path);
- }
- else
- strcpy(temp, editor_dir);
- if (getfilename("Insert file: ", temp, NAME_MAX))
- (void)insert_file(temp, TRUE);
- }
- void readfile()
- {
- buffer_t *bp;
- char cur_path[NAME_MAX];
- if(curbp->b_path) {
- get_current_path(cur_path);
- strcpy(temp, cur_path);
- }
- else
- strcpy(temp, editor_dir);
- int result = getfilename("Find file: ", (char*)temp, NAME_MAX);
- if (result) {
- bp = find_buffer(temp, TRUE);
- disassociate_b(curwp);
- curbp = bp;
- associate_b2w(curbp, curwp);
- /* load the file if not already loaded */
- if (bp != NULL && bp->b_fname[0] == '\0') {
- if (!load_file(temp)) {
- msg("New file %s", temp);
- }
- strncpy(curbp->b_fname, temp, NAME_MAX);
- curbp->b_fname[NAME_MAX] = '\0'; /* truncate if required */
- }
- }
- }
- void savebuffer()
- {
- if(curbp->b_flags & B_MODIFIED) {
- if (curbp->b_fname[0] != '\0') {
- save(curbp->b_fname);
- return;
- } else {
- writefile();
- }
- } else {
- msg("(No changes need to be saved.)");
- }
- }
- void writefile()
- {
- strncpy(temp, curbp->b_fname, NAME_MAX);
- if (getinput("Write file: ", temp, NAME_MAX, F_NONE, FALSE))
- if (save(temp) == TRUE)
- strncpy(curbp->b_fname, temp, NAME_MAX);
- }
- void killbuffer()
- {
- buffer_t *kill_bp = curbp;
- buffer_t *bp;
- int bcount = count_buffers();
- const char *message = "Discard changes (y/N) ?";
- /* do nothing if only buffer left is the scratch buffer */
- if (bcount == 1 && 0 == strcmp(get_buffer_name(curbp), "*scratch*"))
- return;
- if (curbp->b_flags & B_MODIFIED) {
- print_to_msgline(message);
- clrtoeol(message, MSGLINE);
- if (!yesno(FALSE))
- return;
- }
- if (bcount == 1) {
- /* create a scratch buffer */
- bp = find_buffer("*scratch*", TRUE);
- strncpy(bp->b_bname, "*scratch*", STRBUF_S);
- bp->b_path = FALSE;
- }
- next_buffer();
- assert(kill_bp != curbp);
- delete_buffer(kill_bp);
- }
- void iblock()
- {
- block();
- msg("Mark set");
- }
- void unmark()
- {
- curbp->b_pmark = curbp->b_mark;
- curbp->b_mark = NOMARK;
- msg("Mark removed");
- }
- void toggle_overwrite_mode() {
- if (curbp->b_flags & B_OVERWRITE)
- curbp->b_flags &= ~B_OVERWRITE;
- else
- curbp->b_flags |= B_OVERWRITE;
- }
- void killtoeol()
- {
- if (curbp->b_point == pos(curbp, curbp->b_ebuf))
- return; /* do nothing if at end of file */
- if (*(ptr(curbp, curbp->b_point)) == 0xa) {
- delete(); /* delete CR if at start of empty line */
- } else {
- undoset();
- curbp->b_mark = curbp->b_point;
- lnend();
- if (curbp->b_mark != curbp->b_point) copy_cut(TRUE, TRUE, TRUE);
- }
- }
- void copy_cut(int cut, int displaymsg, int internal)
- {
- char_t *p;
- /* if no mark or point == marker, nothing doing */
- if (curbp->b_mark == NOMARK || curbp->b_point == curbp->b_mark)
- return;
- if (scrap != NULL) {
- free(scrap);
- scrap = NULL;
- }
- if(cut && !internal)
- undoset();
- if (curbp->b_point < curbp->b_mark) {
- /* point above marker: move gap under point, region = marker - point */
- (void) movegap(curbp, curbp->b_point);
- p = ptr(curbp, curbp->b_point);
- nscrap = curbp->b_mark - curbp->b_point;
- } else {
- /* if point below marker: move gap under marker, region = point - marker */
- (void) movegap(curbp, curbp->b_mark);
- p = ptr(curbp, curbp->b_mark);
- nscrap = curbp->b_point - curbp->b_mark;
- }
- if ((scrap = (char_t*) malloc(nscrap)) == NULL && displaymsg) {
- msg("No more memory available.");
- } else {
- (void) memcpy(scrap, p, nscrap * sizeof (char_t));
- if (cut) {
- curbp->b_egap += nscrap; /* if cut expand gap down */
- curbp->b_point = pos(curbp, curbp->b_egap); /* set point to after region */
- curbp->b_flags |= B_MODIFIED;
- if(displaymsg)
- msg("%ld bytes cut.", nscrap);
- } else {
- if(displaymsg)
- msg("%ld bytes copied.", nscrap);
- }
- curbp->b_mark = NOMARK; /* unmark */
- }
- }
- void paste_internal(int internal)
- {
- if(curbp->b_flags & B_OVERWRITE)
- return;
- if (nscrap <= 0) {
- msg("Scrap is empty. Nothing to paste.");
- } else if (nscrap < curbp->b_egap - curbp->b_gap || growgap(curbp, nscrap)) {
- if(!internal)
- undoset();
- curbp->b_point = movegap(curbp, curbp->b_point);
- memcpy(curbp->b_gap, scrap, nscrap * sizeof (char_t));
- curbp->b_gap += nscrap;
- curbp->b_point = pos(curbp, curbp->b_egap);
- curbp->b_flags |= B_MODIFIED;
- }
- }
- void paste()
- {
- paste_internal(FALSE);
- }
- void showpos()
- {
- int current, lastln;
- point_t end_p = pos(curbp, curbp->b_ebuf);
- get_line_stats(¤t, &lastln, curbp);
- if (curbp->b_point == end_p) {
- msg("[EOB] Line = %d/%d Point = %d/%d", current, lastln,
- curbp->b_point, ((curbp->b_ebuf - curbp->b_buf) - (curbp->b_egap - curbp->b_gap)));
- } else {
- /* TODO: unctrl(*(ptr(curbp, curbp->b_point)))*/
- msg("Char = %s 0x%x Line = %d/%d Point = %d/%d", "N/A", *(ptr(curbp, curbp->b_point)),
- current, lastln,
- curbp->b_point, ((curbp->b_ebuf - curbp->b_buf) - (curbp->b_egap - curbp->b_gap)));
- }
- }
- /* Delete whitespace between non-whitespace */
- void deletewhitespacebetween()
- {
- char_t *p;
- while (isspace(*(p = ptr(curbp, curbp->b_point - 1))) && curbp->b_buf < p && *p != '\n')
- backsp();
- while (isspace(*(p = ptr(curbp, curbp->b_point))) && curbp->b_buf < p && *p != '\n')
- delete();
- }
- void insertnewlinebelow()
- {
- input = (char_t *)"\n";
- insert();
- up();
- }
- void insertnewline()
- {
- point_t point;
- char_t *p, *space = NULL;
- int spaces = 0, i;
- point = segstart(curbp, curwp, lnstart(curbp, curbp->b_point), curbp->b_point);
- while(isspace(*(p = ptr(curbp, point))) && *p != '\n' && curwp->w_col != 0) {
- if(spaces == 0) {
- space = p;
- }
- if(*p != '\n') {
- spaces++;
- point++;
- }
- }
- input = (char_t *)"\n";
- insert();
- input = (char_t *)space;
- for(i = 0; i < spaces; i++) {
- insert();
- }
- }
- void inserttab()
- {
- input = (char_t *)"\t";
- insert();
- }
- void inserttabasspace()
- {
- input = (char_t *)" ";
- insert_str();
- }
- void suspend()
- {
- tb_shutdown();
- raise(SIGTSTP);
- }
- void transpose()
- {
- char_t cur = *ptr(curbp, curbp->b_point);
- delete();
- left();
- input = &cur;
- insert();
- }
- /* Delete a word but don't display any messages. */
- void deleteword(int dir) {
- block();
- if(dir)
- wright();
- else
- wleft();
- copy_cut(TRUE, FALSE, TRUE);
- }
- /* Transpose words and put scrap back to how it was. */
- /* TODO: Fix the undo for this. */
- void transposeword()
- {
- char_t *current_scrap;
- int n_scrap = nscrap;
- undoset();
- current_scrap = (char_t*) malloc(nscrap);
- (void) memcpy(current_scrap, scrap, nscrap * sizeof (char_t));
- wright();
- deleteword(0);
- wleft();
- paste_internal(TRUE);
- deleteword(1);
- right();
- paste_internal(TRUE);
- if (scrap != NULL) {
- free(scrap);
- scrap = NULL;
- }
- nscrap = n_scrap;
- scrap = (char_t*) malloc(nscrap);
- (void) memcpy(scrap, current_scrap, nscrap * sizeof (char_t));
- }
- void lowercaseword()
- {
- char_t *p;
- char_t c[1];
- while (isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf)
- ++curbp->b_point;
- while (!isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf) {
- c[0] = tolower(*p);
- input = c;
- delete();
- insert();
- }
- }
- void capitalizeword()
- {
- char_t *p;
- while (isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf)
- ++curbp->b_point;
- p = ptr(curbp, curbp->b_point);
- char_t c[1];
- c[0] = toupper(*p);
- input = c;
- delete();
- insert();
- while (!isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf)
- ++curbp->b_point;
- }
- void uppercaseword()
- {
- char_t *p;
- char_t c[1];
- while (isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf)
- ++curbp->b_point;
- while (!isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf) {
- c[0] = toupper(*p);
- input = c;
- delete();
- insert();
- }
- }
- /* type = 0, zap
- type = 1, jump
- */
- /* TODO: Throw error when putting non-char in. */
- void gotochar(int type)
- {
- char_t *p;
- int c;
- struct tb_event ev;
- char *prompt = type == 0 ? "Zap to Char: " : "Jump to Char: ";
- if(character[0] == '\0') {
- display_prompt_and_response(prompt, character);
- tb_present();
- if(tb_poll_event(&ev) != TB_OK) return;
- if(!ev.mod)
- c = ev.ch;
- else
- c = ev.key;
- /* Ignore all control keys other than C-g and ESC*/
- if (c < 32 && c != TB_KEY_CTRL_G && c != TB_KEY_ESC)
- return;
- if(c == TB_KEY_CTRL_G || c == TB_KEY_ESC)
- return;
- else
- character[0] = c;
- display_prompt_and_response(prompt, character);
- tb_present();
- }
- if(negated)
- left();
- if(*ptr(curbp, curbp->b_point) == character[0]) {
- if(type == 0) {
- delete();
- if(negated)
- left();
- } else {
- if(negated)
- left();
- else
- right();
- }
- }
- while (*(p = ptr(curbp, curbp->b_point)) != character[0] && p < curbp->b_ebuf && p > curbp->b_buf) {
- if(type == 0) {
- delete();
- if(negated)
- left();
- } else {
- if(negated)
- left();
- else
- right();
- }
- }
- if(type == 0)
- delete(); // delete the character itself
- negated = FALSE;
- tb_set_cursor(0, MSGLINE);
- clrtoeol("", MSGLINE);
- }
- void zaptochar()
- {
- gotochar(0);
- }
- void negated_zaptochar()
- {
- negated = TRUE;
- gotochar(0);
- }
- void jumptochar()
- {
- gotochar(1);
- }
- void negated_jumptochar()
- {
- negated = TRUE;
- gotochar(1);
- }
- void poptomark()
- {
- if(curbp->b_mark > -1)
- curbp->b_point = curbp->b_mark;
- else
- curbp->b_point = curbp->b_pmark;
- }
- void universal_argument_load()
- {
- universal_argument++;
- msg("C-u %d", universal_argument);
- }
- void numeric_argument_load()
- {
- numeric_argument = (numeric_argument * 10) + atoi((const char *)&input_char);
- msg("C-u %d", numeric_argument);
- }
- void back_to_indentation()
- {
- char_t *p;
- while (isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf)
- ++curbp->b_point;
- }
- void negate()
- {
- negated = !negated;
- msg("C-u -");
- }
- void forward_bracket()
- {
- point_t p;
- if((p = find_matching_bracket(curbp, 1)) >= 0)
- curbp->b_point = curbp->b_mark == NOMARK ? p : p + 1;
- }
- void backward_bracket()
- {
- point_t p;
- if((p = find_matching_bracket(curbp, -1)) >= 0)
- curbp->b_point = p;
- }
- void start_kbd_macro()
- {
- record_input = TRUE;
- for(int i = 0; i < record_buffer_index; i++) {
- memset(&record_buffer[i], 0, sizeof(record_buffer[i]));
- }
- record_buffer_index = 0;
- msg("Started keyboard macro...");
- }
- void end_kbd_macro()
- {
- record_input = FALSE;
- msg("Ended keyboard macro.");
- }
- void run_kbd_macro()
- {
- if(numeric_argument > 0)
- numeric_argument--;
- execute_kbd_macro = TRUE;
- }
- void open_file_from_shell()
- {
- get_popen_data(1);
- }
- void insert_from_shell()
- {
- get_popen_data(0);
- }
|