To: vim_dev@googlegroups.com Subject: Patch 8.1.2392 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2392 Problem: Using old C style comments. Solution: Use // comments where appropriate. Files: src/nbdebug.c, src/netbeans.c, src/normal.c, src/ops.c, src/option.c *** ../vim-8.1.2391/src/nbdebug.c 2019-05-10 21:28:35.184612974 +0200 --- src/nbdebug.c 2019-12-05 19:59:01.410710213 +0100 *************** *** 30,36 **** #include "vim.h" FILE *nb_debug = NULL; ! u_int nb_dlevel = 0; /* nb_debug verbosity level */ void nbdb(char *, ...); --- 30,36 ---- #include "vim.h" FILE *nb_debug = NULL; ! u_int nb_dlevel = 0; // nb_debug verbosity level void nbdb(char *, ...); *************** *** 46,64 **** * from a background process this is the only way to debug * startup problems. */ ! ! void nbdebug_wait( ! u_int wait_flags, /* tells what to do */ ! char *wait_var, /* wait environment variable */ ! u_int wait_secs) /* how many seconds to wait */ { ! init_homedir(); /* not inited yet */ #ifdef USE_WDDUMP WDDump(0, 0, 0); #endif ! /* for debugging purposes only */ if (wait_flags & WT_ENV && wait_var && getenv(wait_var) != NULL) { sleep(atoi(getenv(wait_var))); } else if (wait_flags & WT_WAIT && lookup("~/.gvimwait")) { --- 46,64 ---- * from a background process this is the only way to debug * startup problems. */ ! void ! nbdebug_wait( ! u_int wait_flags, // tells what to do ! char *wait_var, // wait environment variable ! u_int wait_secs) // how many seconds to wait { ! init_homedir(); // not inited yet #ifdef USE_WDDUMP WDDump(0, 0, 0); #endif ! // for debugging purposes only if (wait_flags & WT_ENV && wait_var && getenv(wait_var) != NULL) { sleep(atoi(getenv(wait_var))); } else if (wait_flags & WT_WAIT && lookup("~/.gvimwait")) { *************** *** 69,84 **** ; } } ! } /* end nbdebug_wait */ ! ! void nbdebug_log_init( ! char *log_var, /* env var with log file */ ! char *level_var) /* env var with nb_debug level */ { ! char *file; /* possible nb_debug output file */ ! char *cp; /* nb_dlevel pointer */ if (log_var && (file = getenv(log_var)) != NULL) { --- 69,83 ---- ; } } ! } ! void nbdebug_log_init( ! char *log_var, // env var with log file ! char *level_var) // env var with nb_debug level { ! char *file; // possible nb_debug output file ! char *cp; // nb_dlevel pointer if (log_var && (file = getenv(log_var)) != NULL) { *************** *** 90,109 **** if (level_var && (cp = getenv(level_var)) != NULL) { nb_dlevel = strtoul(cp, NULL, 0); } else { ! nb_dlevel = NB_TRACE; /* default level */ } #ifdef USE_NB_ERRORHANDLER XSetErrorHandler(errorHandler); #endif } ! } /* end nbdebug_log_init */ ! ! void ! nbdbg( ! char *fmt, ! ...) { va_list ap; --- 89,105 ---- if (level_var && (cp = getenv(level_var)) != NULL) { nb_dlevel = strtoul(cp, NULL, 0); } else { ! nb_dlevel = NB_TRACE; // default level } #ifdef USE_NB_ERRORHANDLER XSetErrorHandler(errorHandler); #endif } ! } ! void ! nbdbg(char *fmt, ...) { va_list ap; *************** *** 114,125 **** fflush(nb_debug); } ! } /* end nbdbg */ ! ! static int ! lookup( ! char *file) { char buf[BUFSIZ]; --- 110,119 ---- fflush(nb_debug); } ! } ! static int ! lookup(char *file) { char buf[BUFSIZ]; *************** *** 131,140 **** (access(buf, 0) == 0); #endif ! } /* end lookup */ #ifdef USE_NB_ERRORHANDLER ! static int errorHandler( Display *dpy, XErrorEvent *err) --- 125,134 ---- (access(buf, 0) == 0); #endif ! } #ifdef USE_NB_ERRORHANDLER ! static int errorHandler( Display *dpy, XErrorEvent *err) *************** *** 160,163 **** #endif ! #endif /* NBDEBUG */ --- 154,157 ---- #endif ! #endif // NBDEBUG *** ../vim-8.1.2391/src/netbeans.c 2019-10-24 14:59:58.035079639 +0200 --- src/netbeans.c 2019-12-05 20:01:26.850243218 +0100 *************** *** 36,47 **** #include "version.h" ! #define GUARDED 10000 /* typenr for "guarded" annotation */ ! #define GUARDEDOFFSET 1000000 /* base for "guarded" sign id's */ ! #define MAX_COLOR_LENGTH 32 /* max length of color name in defineAnnoType */ ! /* The first implementation (working only with Netbeans) returned "1.1". The ! * protocol implemented here also supports A-A-P. */ static char *ExtEdProtocolVersion = "2.5"; static long pos2off(buf_T *, pos_T *); --- 36,47 ---- #include "version.h" ! #define GUARDED 10000 // typenr for "guarded" annotation ! #define GUARDEDOFFSET 1000000 // base for "guarded" sign id's ! #define MAX_COLOR_LENGTH 32 // max length of color name in defineAnnoType ! // The first implementation (working only with Netbeans) returned "1.1". The ! // protocol implemented here also supports A-A-P. static char *ExtEdProtocolVersion = "2.5"; static long pos2off(buf_T *, pos_T *); *************** *** 64,70 **** #define NETBEANS_OPEN (channel_can_write_to(nb_channel)) static channel_T *nb_channel = NULL; ! static int r_cmdno; /* current command number for reply */ static int dosetvisible = FALSE; /* --- 64,70 ---- #define NETBEANS_OPEN (channel_can_write_to(nb_channel)) static channel_T *nb_channel = NULL; ! static int r_cmdno; // current command number for reply static int dosetvisible = FALSE; /* *************** *** 98,104 **** netbeans_send_disconnect(); if (nb_channel != NULL) { ! /* Close the socket and remove the input handlers. */ channel_close(nb_channel, TRUE); channel_clear(nb_channel); } --- 98,104 ---- netbeans_send_disconnect(); if (nb_channel != NULL) { ! // Close the socket and remove the input handlers. channel_close(nb_channel, TRUE); channel_clear(nb_channel); } *************** *** 113,119 **** inAtomic = 0; nb_free(); ! /* remove all signs and update the screen after gutter removal */ coloncmd(":sign unplace *"); changed_window_setting(); update_screen(CLEAR); --- 113,119 ---- inAtomic = 0; nb_free(); ! // remove all signs and update the screen after gutter removal coloncmd(":sign unplace *"); changed_window_setting(); update_screen(CLEAR); *************** *** 139,156 **** if (*params == '=') { ! /* "=fname": Read info from specified file. */ if (getConnInfo(params + 1, &hostname, &address, &password) == FAIL) return FAIL; } else { if (*params == ':') ! /* ":::": get info from argument */ arg = params + 1; if (arg == NULL && (fname = getenv("__NETBEANS_CONINFO")) != NULL) { ! /* "": get info from file specified in environment */ if (getConnInfo(fname, &hostname, &address, &password) == FAIL) return FAIL; } --- 139,156 ---- if (*params == '=') { ! // "=fname": Read info from specified file. if (getConnInfo(params + 1, &hostname, &address, &password) == FAIL) return FAIL; } else { if (*params == ':') ! // ":::": get info from argument arg = params + 1; if (arg == NULL && (fname = getenv("__NETBEANS_CONINFO")) != NULL) { ! // "": get info from file specified in environment if (getConnInfo(fname, &hostname, &address, &password) == FAIL) return FAIL; } *************** *** 158,164 **** { if (arg != NULL) { ! /* ":::": get info from argument */ hostname = arg; address = strchr(hostname, ':'); if (address != NULL) --- 158,164 ---- { if (arg != NULL) { ! // ":::": get info from argument hostname = arg; address = strchr(hostname, ':'); if (address != NULL) *************** *** 170,176 **** } } ! /* Get the missing values from the environment. */ if (hostname == NULL || *hostname == '\0') hostname = getenv("__NETBEANS_HOST"); if (address == NULL) --- 170,176 ---- } } ! // Get the missing values from the environment. if (hostname == NULL || *hostname == '\0') hostname = getenv("__NETBEANS_HOST"); if (address == NULL) *************** *** 178,184 **** if (password == NULL) password = getenv("__NETBEANS_VIM_PASSWORD"); ! /* Move values to allocated memory. */ if (hostname != NULL) hostname = (char *)vim_strsave((char_u *)hostname); if (address != NULL) --- 178,184 ---- if (password == NULL) password = getenv("__NETBEANS_VIM_PASSWORD"); ! // Move values to allocated memory. if (hostname != NULL) hostname = (char *)vim_strsave((char_u *)hostname); if (address != NULL) *************** *** 188,194 **** } } ! /* Use the default when a value is missing. */ if (hostname == NULL || *hostname == '\0') { vim_free(hostname); --- 188,194 ---- } } ! // Use the default when a value is missing. if (hostname == NULL || *hostname == '\0') { vim_free(hostname); *************** *** 210,221 **** nb_channel = channel_open(hostname, port, 3000, nb_channel_closed); if (nb_channel != NULL) { ! /* success */ # ifdef FEAT_BEVAL_GUI bevalServers |= BEVAL_NETBEANS; # endif ! /* success, login */ vim_snprintf(buf, sizeof(buf), "AUTH %s\n", password); nb_send(buf, "netbeans_connect"); --- 210,221 ---- nb_channel = channel_open(hostname, port, 3000, nb_channel_closed); if (nb_channel != NULL) { ! // success # ifdef FEAT_BEVAL_GUI bevalServers |= BEVAL_NETBEANS; # endif ! // success, login vim_snprintf(buf, sizeof(buf), "AUTH %s\n", password); nb_send(buf, "netbeans_connect"); *************** *** 271,281 **** return FAIL; } ! /* Read the file. There should be one of each parameter */ while ((lp = (char_u *)fgets((char *)buf, BUFSIZ, fp)) != NULL) { if ((nlp = vim_strchr(lp, '\n')) != NULL) ! *nlp = 0; /* strip off the trailing newline */ if (STRNCMP(lp, "host=", 5) == 0) { --- 271,281 ---- return FAIL; } ! // Read the file. There should be one of each parameter while ((lp = (char_u *)fgets((char *)buf, BUFSIZ, fp)) != NULL) { if ((nlp = vim_strchr(lp, '\n')) != NULL) ! *nlp = 0; // strip off the trailing newline if (STRNCMP(lp, "host=", 5) == 0) { *************** *** 308,314 **** typedef struct keyqueue keyQ_T; ! static keyQ_T keyHead; /* dummy node, header for circular queue */ /* --- 308,314 ---- typedef struct keyqueue keyQ_T; ! static keyQ_T keyHead; // dummy node, header for circular queue /* *************** *** 323,337 **** node = ALLOC_ONE(keyQ_T); if (node == NULL) ! return; /* out of memory, drop the key */ ! if (keyHead.next == NULL) /* initialize circular queue */ { keyHead.next = &keyHead; keyHead.prev = &keyHead; } ! /* insert node at tail of queue */ node->next = &keyHead; node->prev = keyHead.prev; keyHead.prev->next = node; --- 323,337 ---- node = ALLOC_ONE(keyQ_T); if (node == NULL) ! return; // out of memory, drop the key ! if (keyHead.next == NULL) // initialize circular queue { keyHead.next = &keyHead; keyHead.prev = &keyHead; } ! // insert node at tail of queue node->next = &keyHead; node->prev = keyHead.prev; keyHead.prev->next = node; *************** *** 350,367 **** while (!postponed && keyHead.next && keyHead.next != &keyHead) { ! /* first, unlink the node */ keyQ_T *node = keyHead.next; keyHead.next = node->next; node->next->prev = node->prev; ! /* Now, send the keycommand. This may cause it to be postponed again ! * and change keyHead. */ if (node->keystr != NULL) postponed = !netbeans_keystring(node->keystr); vim_free(node->keystr); ! /* Finally, dispose of the node */ vim_free(node); } } --- 350,367 ---- while (!postponed && keyHead.next && keyHead.next != &keyHead) { ! // first, unlink the node keyQ_T *node = keyHead.next; keyHead.next = node->next; node->next->prev = node->prev; ! // Now, send the keycommand. This may cause it to be postponed again ! // and change keyHead. if (node->keystr != NULL) postponed = !netbeans_keystring(node->keystr); vim_free(node->keystr); ! // Finally, dispose of the node vim_free(node); } } *************** *** 382,411 **** { node = channel_peek(nb_channel, PART_SOCK); if (node == NULL) ! break; /* nothing to read */ ! /* Locate the end of the first line in the first buffer. */ p = channel_first_nl(node); if (p == NULL) { ! /* Command isn't complete. If there is no following buffer, ! * return (wait for more). If there is another buffer following, ! * prepend the text to that buffer and delete this one. */ if (channel_collapse(nb_channel, PART_SOCK, TRUE) == FAIL) return; continue; } ! /* There is a complete command at the start of the buffer. ! * Terminate it with a NUL. When no more text is following unlink ! * the buffer. Do this before executing, because new buffers can ! * be added while busy handling the command. */ *p++ = NUL; if (*p == NUL) { own_node = TRUE; buffer = channel_get(nb_channel, PART_SOCK, NULL); ! /* "node" is now invalid! */ } else { --- 382,411 ---- { node = channel_peek(nb_channel, PART_SOCK); if (node == NULL) ! break; // nothing to read ! // Locate the end of the first line in the first buffer. p = channel_first_nl(node); if (p == NULL) { ! // Command isn't complete. If there is no following buffer, ! // return (wait for more). If there is another buffer following, ! // prepend the text to that buffer and delete this one. if (channel_collapse(nb_channel, PART_SOCK, TRUE) == FAIL) return; continue; } ! // There is a complete command at the start of the buffer. ! // Terminate it with a NUL. When no more text is following unlink ! // the buffer. Do this before executing, because new buffers can ! // be added while busy handling the command. *p++ = NUL; if (*p == NUL) { own_node = TRUE; buffer = channel_get(nb_channel, PART_SOCK, NULL); ! // "node" is now invalid! } else { *************** *** 413,427 **** buffer = node->rq_buffer; } ! /* Now, parse and execute the commands. This may set nb_channel to ! * NULL if the channel is closed. */ nb_parse_cmd(buffer); if (own_node) ! /* buffer finished, dispose of it */ vim_free(buffer); else if (nb_channel != NULL) ! /* more follows, move it to the start */ channel_consume(nb_channel, PART_SOCK, (int)(p - buffer)); } } --- 413,427 ---- buffer = node->rq_buffer; } ! // Now, parse and execute the commands. This may set nb_channel to ! // NULL if the channel is closed. nb_parse_cmd(buffer); if (own_node) ! // buffer finished, dispose of it vim_free(buffer); else if (nb_channel != NULL) ! // more follows, move it to the start channel_consume(nb_channel, PART_SOCK, (int)(p - buffer)); } } *************** *** 452,463 **** if (STRCMP(cmd, "DISCONNECT") == 0) { ! /* We assume the server knows that we can safely exit! */ ! /* Disconnect before exiting, Motif hangs in a Select error ! * message otherwise. */ netbeans_close(); getout(0); ! /* NOTREACHED */ } if (STRCMP(cmd, "DETACH") == 0) --- 452,463 ---- if (STRCMP(cmd, "DISCONNECT") == 0) { ! // We assume the server knows that we can safely exit! ! // Disconnect before exiting, Motif hangs in a Select error ! // message otherwise. netbeans_close(); getout(0); ! // NOTREACHED } if (STRCMP(cmd, "DETACH") == 0) *************** *** 467,473 **** FOR_ALL_BUFFERS(buf) buf->b_has_sign_column = FALSE; ! /* The IDE is breaking the connection. */ netbeans_close(); return; } --- 467,473 ---- FOR_ALL_BUFFERS(buf) buf->b_has_sign_column = FALSE; ! // The IDE is breaking the connection. netbeans_close(); return; } *************** *** 480,486 **** semsg("E627: missing colon: %s", cmd); return; } ! ++verb; /* skip colon */ for (q = verb; *q; q++) { --- 480,486 ---- semsg("E627: missing colon: %s", cmd); return; } ! ++verb; // skip colon for (q = verb; *q; q++) { *************** *** 540,547 **** typedef struct nbbuf_struct nbbuf_T; static nbbuf_T *buf_list = NULL; ! static int buf_list_size = 0; /* size of buf_list */ ! static int buf_list_used = 0; /* nr of entries in buf_list actually in use */ static char **globalsignmap = NULL; static int globalsignmaplen = 0; --- 540,547 ---- typedef struct nbbuf_struct nbbuf_T; static nbbuf_T *buf_list = NULL; ! static int buf_list_size = 0; // size of buf_list ! static int buf_list_used = 0; // nr of entries in buf_list actually in use static char **globalsignmap = NULL; static int globalsignmaplen = 0; *************** *** 566,572 **** nbbuf_T buf; int i; ! /* free the netbeans buffer list */ for (i = 0; i < buf_list_used; i++) { buf = buf_list[i]; --- 566,572 ---- nbbuf_T buf; int i; ! // free the netbeans buffer list for (i = 0; i < buf_list_used; i++) { buf = buf_list[i]; *************** *** 582,588 **** buf_list_size = 0; buf_list_used = 0; ! /* free the queued key commands */ while (key_node != NULL && key_node != &keyHead) { keyQ_T *next = key_node->next; --- 582,588 ---- buf_list_size = 0; buf_list_used = 0; ! // free the queued key commands while (key_node != NULL && key_node != &keyHead) { keyQ_T *next = key_node->next; *************** *** 597,603 **** key_node = next; } ! /* free the queued netbeans commands */ if (nb_channel != NULL) channel_clear(nb_channel); } --- 597,603 ---- key_node = next; } ! // free the queued netbeans commands if (nb_channel != NULL) channel_clear(nb_channel); } *************** *** 658,664 **** static nbbuf_T * nb_get_buf(int bufno) { ! /* find or create a buffer with the given number */ int incr; if (bufno <= 0) --- 658,664 ---- static nbbuf_T * nb_get_buf(int bufno) { ! // find or create a buffer with the given number int incr; if (bufno <= 0) *************** *** 666,678 **** if (!buf_list) { ! /* initialize */ buf_list = alloc_clear(100 * sizeof(nbbuf_T)); buf_list_size = 100; } ! if (bufno >= buf_list_used) /* new */ { ! if (bufno >= buf_list_size) /* grow list */ { nbbuf_T *t_buf_list = buf_list; --- 666,678 ---- if (!buf_list) { ! // initialize buf_list = alloc_clear(100 * sizeof(nbbuf_T)); buf_list_size = 100; } ! if (bufno >= buf_list_used) // new { ! if (bufno >= buf_list_size) // grow list { nbbuf_T *t_buf_list = buf_list; *************** *** 691,697 **** while (buf_list_used <= bufno) { ! /* Default is to fire text changes. */ buf_list[buf_list_used].fireChanges = 1; ++buf_list_used; } --- 691,697 ---- while (buf_list_used <= bufno) { ! // Default is to fire text changes. buf_list[buf_list_used].fireChanges = 1; ++buf_list_used; } *************** *** 734,747 **** continue; if (netbeansForcedQuit) { ! /* mark as unmodified so NetBeans won't put up dialog on "killed" */ sprintf(buf, "%d:unmodified=%d\n", i, r_cmdno); nbdebug(("EVT: %s", buf)); nb_send(buf, "netbeans_end"); } sprintf(buf, "%d:killed=%d\n", i, r_cmdno); nbdebug(("EVT: %s", buf)); ! /* nb_send(buf, "netbeans_end"); avoid "write failed" messages */ nb_send(buf, NULL); } } --- 734,747 ---- continue; if (netbeansForcedQuit) { ! // mark as unmodified so NetBeans won't put up dialog on "killed" sprintf(buf, "%d:unmodified=%d\n", i, r_cmdno); nbdebug(("EVT: %s", buf)); nb_send(buf, "netbeans_end"); } sprintf(buf, "%d:killed=%d\n", i, r_cmdno); nbdebug(("EVT: %s", buf)); ! // nb_send(buf, "netbeans_end"); avoid "write failed" messages nb_send(buf, NULL); } } *************** *** 769,775 **** nbdebug(("REP %d: \n", cmdno)); ! /* Avoid printing an annoying error message. */ if (!NETBEANS_OPEN) return; --- 769,775 ---- nbdebug(("REP %d: \n", cmdno)); ! // Avoid printing an annoying error message. if (!NETBEANS_OPEN) return; *************** *** 831,838 **** case '\"': case '\\': *q++ = '\\'; *q++ = *p; break; ! /* case '\t': */ ! /* *q++ = '\\'; *q++ = 't'; break; */ case '\n': *q++ = '\\'; *q++ = 'n'; break; case '\r': --- 831,838 ---- case '\"': case '\\': *q++ = '\\'; *q++ = *p; break; ! // case '\t': ! // *q++ = '\\'; *q++ = 't'; break; case '\n': *q++ = '\\'; *q++ = 'n'; break; case '\r': *************** *** 861,867 **** char *q; int done = 0; ! /* result is never longer than input */ result = alloc_clear(STRLEN(p) + 1); if (result == NULL) return NULL; --- 861,867 ---- char *q; int done = 0; ! // result is never longer than input result = alloc_clear(STRLEN(p) + 1); if (result == NULL) return NULL; *************** *** 895,901 **** case 'r': *q++ = '\r'; break; case '"': *q++ = '"'; break; case NUL: --p; break; ! /* default: skip over illegal chars */ } ++p; break; --- 895,901 ---- case 'r': *q++ = '\r'; break; case '"': *q++ = '"'; break; case NUL: --p; break; ! // default: skip over illegal chars } ++p; break; *************** *** 924,930 **** oldtext = ml_get(lnum); oldlen = (int)STRLEN(oldtext); ! if (first >= (colnr_T)oldlen || oldlen == 0) /* just in case */ return; if (lastbyte >= oldlen) lastbyte = oldlen - 1; --- 924,930 ---- oldtext = ml_get(lnum); oldlen = (int)STRLEN(oldtext); ! if (first >= (colnr_T)oldlen || oldlen == 0) // just in case return; if (lastbyte >= oldlen) lastbyte = oldlen - 1; *************** *** 974,1028 **** char_u *cmd, int func, int cmdno, ! char_u *args) /* points to space before arguments or NUL */ { int do_update = 0; long off = 0; nbbuf_T *buf = nb_get_buf(bufno); static int skip = 0; int retval = OK; ! char *cp; /* for when a char pointer is needed */ nbdebug(("%s %d: (%d) %s %s\n", (func) ? "FUN" : "CMD", cmdno, bufno, cmd, STRCMP(cmd, "insert") == 0 ? "" : (char *)args)); if (func) { ! /* =====================================================================*/ if (streq((char *)cmd, "getModified")) { if (buf == NULL || buf->bufp == NULL) ! /* Return the number of buffers that are modified. */ nb_reply_nr(cmdno, (long)count_changed_buffers()); else ! /* Return whether the buffer is modified. */ nb_reply_nr(cmdno, (long)(buf->bufp->b_changed || isNetbeansModified(buf->bufp))); ! /* =====================================================================*/ } else if (streq((char *)cmd, "saveAndExit")) { ! /* Note: this will exit Vim if successful. */ coloncmd(":confirm qall"); ! /* We didn't exit: return the number of changed buffers. */ nb_reply_nr(cmdno, (long)count_changed_buffers()); ! /* =====================================================================*/ } else if (streq((char *)cmd, "getCursor")) { char_u text[200]; ! /* Note: nb_getbufno() may return -1. This indicates the IDE ! * didn't assign a number to the current buffer in response to a ! * fileOpened event. */ sprintf((char *)text, "%d %ld %d %ld", nb_getbufno(curbuf), (long)curwin->w_cursor.lnum, (int)curwin->w_cursor.col, pos2off(curbuf, &curwin->w_cursor)); nb_reply_text(cmdno, text); ! /* =====================================================================*/ } else if (streq((char *)cmd, "getAnno")) { --- 974,1028 ---- char_u *cmd, int func, int cmdno, ! char_u *args) // points to space before arguments or NUL { int do_update = 0; long off = 0; nbbuf_T *buf = nb_get_buf(bufno); static int skip = 0; int retval = OK; ! char *cp; // for when a char pointer is needed nbdebug(("%s %d: (%d) %s %s\n", (func) ? "FUN" : "CMD", cmdno, bufno, cmd, STRCMP(cmd, "insert") == 0 ? "" : (char *)args)); if (func) { ! // ===================================================================== if (streq((char *)cmd, "getModified")) { if (buf == NULL || buf->bufp == NULL) ! // Return the number of buffers that are modified. nb_reply_nr(cmdno, (long)count_changed_buffers()); else ! // Return whether the buffer is modified. nb_reply_nr(cmdno, (long)(buf->bufp->b_changed || isNetbeansModified(buf->bufp))); ! // ===================================================================== } else if (streq((char *)cmd, "saveAndExit")) { ! // Note: this will exit Vim if successful. coloncmd(":confirm qall"); ! // We didn't exit: return the number of changed buffers. nb_reply_nr(cmdno, (long)count_changed_buffers()); ! // ===================================================================== } else if (streq((char *)cmd, "getCursor")) { char_u text[200]; ! // Note: nb_getbufno() may return -1. This indicates the IDE ! // didn't assign a number to the current buffer in response to a ! // fileOpened event. sprintf((char *)text, "%d %ld %d %ld", nb_getbufno(curbuf), (long)curwin->w_cursor.lnum, (int)curwin->w_cursor.col, pos2off(curbuf, &curwin->w_cursor)); nb_reply_text(cmdno, text); ! // ===================================================================== } else if (streq((char *)cmd, "getAnno")) { *************** *** 1040,1051 **** cp = (char *)args; serNum = strtol(cp, &cp, 10); ! /* If the sign isn't found linenum will be zero. */ linenum = (long)buf_findsign(buf->bufp, serNum, NULL); } #endif nb_reply_nr(cmdno, linenum); ! /* =====================================================================*/ } else if (streq((char *)cmd, "getLength")) { --- 1040,1051 ---- cp = (char *)args; serNum = strtol(cp, &cp, 10); ! // If the sign isn't found linenum will be zero. linenum = (long)buf_findsign(buf->bufp, serNum, NULL); } #endif nb_reply_nr(cmdno, linenum); ! // ===================================================================== } else if (streq((char *)cmd, "getLength")) { *************** *** 1062,1068 **** len = get_buf_size(buf->bufp); } nb_reply_nr(cmdno, len); ! /* =====================================================================*/ } else if (streq((char *)cmd, "getText")) { --- 1062,1068 ---- len = get_buf_size(buf->bufp); } nb_reply_nr(cmdno, len); ! // ===================================================================== } else if (streq((char *)cmd, "getText")) { *************** *** 1116,1122 **** nb_reply_text(cmdno, text); vim_free(text); } ! /* =====================================================================*/ } else if (streq((char *)cmd, "remove")) { --- 1116,1122 ---- nb_reply_text(cmdno, text); vim_free(text); } ! // ===================================================================== } else if (streq((char *)cmd, "remove")) { *************** *** 1124,1130 **** pos_T first, last; pos_T *pos; pos_T *next; ! linenr_T del_from_lnum, del_to_lnum; /* lines to be deleted as a whole */ int oldFire = netbeansFireChanges; int oldSuppress = netbeansSuppressNoLines; int wasChanged; --- 1124,1130 ---- pos_T first, last; pos_T *pos; pos_T *next; ! linenr_T del_from_lnum, del_to_lnum; // lines to be deleted as a whole int oldFire = netbeansFireChanges; int oldSuppress = netbeansSuppressNoLines; int wasChanged; *************** *** 1153,1159 **** off = strtol(cp, &cp, 10); count = strtol(cp, &cp, 10); args = (char_u *)cp; ! /* delete "count" chars, starting at "off" */ pos = off2pos(buf->bufp, off); if (!pos) { --- 1153,1159 ---- off = strtol(cp, &cp, 10); count = strtol(cp, &cp, 10); args = (char_u *)cp; ! // delete "count" chars, starting at "off" pos = off2pos(buf->bufp, off); if (!pos) { *************** *** 1182,1239 **** del_to_lnum = last.lnum; do_update = 1; ! /* Get the position of the first byte after the deleted ! * section. "next" is NULL when deleting to the end of the ! * file. */ next = off2pos(buf->bufp, off + count); ! /* Remove part of the first line. */ if (first.col != 0 || (next != NULL && first.lnum == next->lnum)) { if (first.lnum != last.lnum || (next != NULL && first.lnum != next->lnum)) { ! /* remove to the end of the first line */ nb_partialremove(first.lnum, first.col, (colnr_T)MAXCOL); if (first.lnum == last.lnum) { ! /* Partial line to remove includes the end of ! * line. Join the line with the next one, have ! * the next line deleted below. */ nb_joinlines(first.lnum, next->lnum); del_to_lnum = next->lnum; } } else { ! /* remove within one line */ nb_partialremove(first.lnum, first.col, last.col); } ! ++del_from_lnum; /* don't delete the first line */ } ! /* Remove part of the last line. */ if (first.lnum != last.lnum && next != NULL && next->col != 0 && last.lnum == next->lnum) { nb_partialremove(last.lnum, 0, last.col); if (del_from_lnum > first.lnum) { ! /* Join end of last line to start of first line; last ! * line is deleted below. */ nb_joinlines(first.lnum, last.lnum); } else ! /* First line is deleted as a whole, keep the last ! * line. */ --del_to_lnum; } ! /* First is partial line; last line to remove includes ! * the end of line; join first line to line following last ! * line; line following last line is deleted below. */ if (first.lnum != last.lnum && del_from_lnum > first.lnum && next != NULL && last.lnum != next->lnum) { --- 1182,1239 ---- del_to_lnum = last.lnum; do_update = 1; ! // Get the position of the first byte after the deleted ! // section. "next" is NULL when deleting to the end of the ! // file. next = off2pos(buf->bufp, off + count); ! // Remove part of the first line. if (first.col != 0 || (next != NULL && first.lnum == next->lnum)) { if (first.lnum != last.lnum || (next != NULL && first.lnum != next->lnum)) { ! // remove to the end of the first line nb_partialremove(first.lnum, first.col, (colnr_T)MAXCOL); if (first.lnum == last.lnum) { ! // Partial line to remove includes the end of ! // line. Join the line with the next one, have ! // the next line deleted below. nb_joinlines(first.lnum, next->lnum); del_to_lnum = next->lnum; } } else { ! // remove within one line nb_partialremove(first.lnum, first.col, last.col); } ! ++del_from_lnum; // don't delete the first line } ! // Remove part of the last line. if (first.lnum != last.lnum && next != NULL && next->col != 0 && last.lnum == next->lnum) { nb_partialremove(last.lnum, 0, last.col); if (del_from_lnum > first.lnum) { ! // Join end of last line to start of first line; last ! // line is deleted below. nb_joinlines(first.lnum, last.lnum); } else ! // First line is deleted as a whole, keep the last ! // line. --del_to_lnum; } ! // First is partial line; last line to remove includes ! // the end of line; join first line to line following last ! // line; line following last line is deleted below. if (first.lnum != last.lnum && del_from_lnum > first.lnum && next != NULL && last.lnum != next->lnum) { *************** *** 1241,1252 **** del_to_lnum = next->lnum; } ! /* Delete whole lines if there are any. */ if (del_to_lnum >= del_from_lnum) { int i; ! /* delete signs from the lines being deleted */ for (i = del_from_lnum; i <= del_to_lnum; i++) { int id = buf_findsign_id(buf->bufp, (linenr_T)i, NULL); --- 1241,1252 ---- del_to_lnum = next->lnum; } ! // Delete whole lines if there are any. if (del_to_lnum >= del_from_lnum) { int i; ! // delete signs from the lines being deleted for (i = del_from_lnum; i <= del_to_lnum; i++) { int id = buf_findsign_id(buf->bufp, (linenr_T)i, NULL); *************** *** 1269,1278 **** del_lines(del_to_lnum - del_from_lnum + 1, FALSE); } ! /* Leave cursor at first deleted byte. */ curwin->w_cursor = first; check_cursor_lnum(); ! buf->bufp->b_changed = wasChanged; /* logically unchanged */ netbeansFireChanges = oldFire; netbeansSuppressNoLines = oldSuppress; --- 1269,1278 ---- del_lines(del_to_lnum - del_from_lnum + 1, FALSE); } ! // Leave cursor at first deleted byte. curwin->w_cursor = first; check_cursor_lnum(); ! buf->bufp->b_changed = wasChanged; // logically unchanged netbeansFireChanges = oldFire; netbeansSuppressNoLines = oldSuppress; *************** *** 1280,1286 **** u_clearall(buf->bufp); } nb_reply_nil(cmdno); ! /* =====================================================================*/ } else if (streq((char *)cmd, "insert")) { --- 1280,1286 ---- u_clearall(buf->bufp); } nb_reply_nil(cmdno); ! // ===================================================================== } else if (streq((char *)cmd, "insert")) { *************** *** 1293,1304 **** return OK; } ! /* get offset */ cp = (char *)args; off = strtol(cp, &cp, 10); args = (char_u *)cp; ! /* get text to be inserted */ args = skipwhite(args); args = to_free = (char_u *)nb_unquote(args, NULL); /* --- 1293,1304 ---- return OK; } ! // get offset cp = (char *)args; off = strtol(cp, &cp, 10); args = (char_u *)cp; ! // get text to be inserted args = skipwhite(args); args = to_free = (char_u *)nb_unquote(args, NULL); /* *************** *** 1327,1339 **** netbeansFireChanges = 0; ! /* Jump to the buffer where we insert. After this "curbuf" ! * can be used. */ nb_set_curbuf(buf->bufp); old_b_changed = curbuf->b_changed; ! /* Convert the specified character offset into a lnum/col ! * position. */ pos = off2pos(curbuf, off); if (pos != NULL) { --- 1327,1339 ---- netbeansFireChanges = 0; ! // Jump to the buffer where we insert. After this "curbuf" ! // can be used. nb_set_curbuf(buf->bufp); old_b_changed = curbuf->b_changed; ! // Convert the specified character offset into a lnum/col ! // position. pos = off2pos(curbuf, off); if (pos != NULL) { *************** *** 1344,1370 **** } else { ! /* If the given position is not found, assume we want ! * the end of the file. See setLocAndSize HACK. */ if (buf_was_empty) ! lnum_start = 1; /* above empty line */ else lnum_start = curbuf->b_ml.ml_line_count + 1; } ! /* "lnum" is the line where we insert: either append to it or ! * insert a new line above it. */ lnum = lnum_start; ! /* Loop over the "\n" separated lines of the argument. */ do_update = 1; while (*args != NUL) { nlp = vim_strchr(args, '\n'); if (nlp == NULL) { ! /* Incomplete line, probably truncated. Next "insert" ! * command should append to this one. */ len = STRLEN(args); } else --- 1344,1370 ---- } else { ! // If the given position is not found, assume we want ! // the end of the file. See setLocAndSize HACK. if (buf_was_empty) ! lnum_start = 1; // above empty line else lnum_start = curbuf->b_ml.ml_line_count + 1; } ! // "lnum" is the line where we insert: either append to it or ! // insert a new line above it. lnum = lnum_start; ! // Loop over the "\n" separated lines of the argument. do_update = 1; while (*args != NUL) { nlp = vim_strchr(args, '\n'); if (nlp == NULL) { ! // Incomplete line, probably truncated. Next "insert" ! // command should append to this one. len = STRLEN(args); } else *************** *** 1393,1399 **** char_u *newline; int col = pos == NULL ? 0 : pos->col; ! /* Insert halfway a line. */ newline = alloc(STRLEN(oldline) + len + 1); if (newline != NULL) { --- 1393,1399 ---- char_u *newline; int col = pos == NULL ? 0 : pos->col; ! // Insert halfway a line. newline = alloc(STRLEN(oldline) + len + 1); if (newline != NULL) { *************** *** 1406,1413 **** } else { ! /* Append a new line. Not that we always do this, ! * also when the text doesn't end in a "\n". */ ml_append((linenr_T)(lnum - 1), args, (colnr_T)(len + 1), FALSE); ++added; --- 1406,1413 ---- } else { ! // Append a new line. Not that we always do this, ! // also when the text doesn't end in a "\n". ml_append((linenr_T)(lnum - 1), args, (colnr_T)(len + 1), FALSE); ++added; *************** *** 1419,1425 **** args = nlp + 1; } ! /* Adjust the marks below the inserted lines. */ appended_lines_mark(lnum_start - 1, (long)added); /* --- 1419,1425 ---- args = nlp + 1; } ! // Adjust the marks below the inserted lines. appended_lines_mark(lnum_start - 1, (long)added); /* *************** *** 1443,1457 **** * text the buffer has been updated but not written. Will * netbeans guarantee to write it? Even if I do a :q! ? */ ! curbuf->b_changed = old_b_changed; /* logically unchanged */ netbeansFireChanges = oldFire; ! /* Undo info is invalid now... */ u_blockfree(curbuf); u_clearall(curbuf); } vim_free(to_free); ! nb_reply_nil(cmdno); /* or !error */ } else { --- 1443,1457 ---- * text the buffer has been updated but not written. Will * netbeans guarantee to write it? Even if I do a :q! ? */ ! curbuf->b_changed = old_b_changed; // logically unchanged netbeansFireChanges = oldFire; ! // Undo info is invalid now... u_blockfree(curbuf); u_clearall(curbuf); } vim_free(to_free); ! nb_reply_nil(cmdno); // or !error } else { *************** *** 1460,1471 **** retval = FAIL; } } ! else /* Not a function; no reply required. */ { ! /* =====================================================================*/ if (streq((char *)cmd, "create")) { ! /* Create a buffer without a name. */ if (buf == NULL) { nbdebug((" invalid buffer identifier in create\n")); --- 1460,1471 ---- retval = FAIL; } } ! else // Not a function; no reply required. { ! // ===================================================================== if (streq((char *)cmd, "create")) { ! // Create a buffer without a name. if (buf == NULL) { nbdebug((" invalid buffer identifier in create\n")); *************** *** 1474,1480 **** } VIM_CLEAR(buf->displayname); ! netbeansReadFile = 0; /* don't try to open disk file */ do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF, curwin); netbeansReadFile = 1; buf->bufp = curbuf; --- 1474,1480 ---- } VIM_CLEAR(buf->displayname); ! netbeansReadFile = 0; // don't try to open disk file do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF, curwin); netbeansReadFile = 1; buf->bufp = curbuf; *************** *** 1484,1490 **** if (gui.in_use) gui_update_menus(0); #endif ! /* =====================================================================*/ } else if (streq((char *)cmd, "insertDone")) { --- 1484,1490 ---- if (gui.in_use) gui_update_menus(0); #endif ! // ===================================================================== } else if (streq((char *)cmd, "insertDone")) { *************** *** 1500,1506 **** buf->bufp->b_p_ro = *args == 'T'; print_read_msg(buf); } ! /* =====================================================================*/ } else if (streq((char *)cmd, "saveDone")) { --- 1500,1506 ---- buf->bufp->b_p_ro = *args == 'T'; print_read_msg(buf); } ! // ===================================================================== } else if (streq((char *)cmd, "saveDone")) { *************** *** 1510,1516 **** nbdebug((" invalid buffer identifier in saveDone\n")); else print_save_msg(buf, savedChars); ! /* =====================================================================*/ } else if (streq((char *)cmd, "startDocumentListen")) { --- 1510,1516 ---- nbdebug((" invalid buffer identifier in saveDone\n")); else print_save_msg(buf, savedChars); ! // ===================================================================== } else if (streq((char *)cmd, "startDocumentListen")) { *************** *** 1521,1527 **** return FAIL; } buf->fireChanges = 1; ! /* =====================================================================*/ } else if (streq((char *)cmd, "stopDocumentListen")) { --- 1521,1527 ---- return FAIL; } buf->fireChanges = 1; ! // ===================================================================== } else if (streq((char *)cmd, "stopDocumentListen")) { *************** *** 1542,1556 **** } else { ! /* NetBeans uses stopDocumentListen when it stops editing ! * a file. It then expects the buffer in Vim to ! * disappear. */ do_bufdel(DOBUF_DEL, (char_u *)"", 1, buf->bufp->b_fnum, buf->bufp->b_fnum, TRUE); vim_memset(buf, 0, sizeof(nbbuf_T)); } } ! /* =====================================================================*/ } else if (streq((char *)cmd, "setTitle")) { --- 1542,1556 ---- } else { ! // NetBeans uses stopDocumentListen when it stops editing ! // a file. It then expects the buffer in Vim to ! // disappear. do_bufdel(DOBUF_DEL, (char_u *)"", 1, buf->bufp->b_fnum, buf->bufp->b_fnum, TRUE); vim_memset(buf, 0, sizeof(nbbuf_T)); } } ! // ===================================================================== } else if (streq((char *)cmd, "setTitle")) { *************** *** 1562,1568 **** } vim_free(buf->displayname); buf->displayname = nb_unquote(args, NULL); ! /* =====================================================================*/ } else if (streq((char *)cmd, "initDone")) { --- 1562,1568 ---- } vim_free(buf->displayname); buf->displayname = nb_unquote(args, NULL); ! // ===================================================================== } else if (streq((char *)cmd, "initDone")) { *************** *** 1577,1585 **** nb_set_curbuf(buf->bufp); apply_autocmds(EVENT_BUFREADPOST, 0, 0, FALSE, buf->bufp); ! /* handle any postponed key commands */ handle_key_queue(); ! /* =====================================================================*/ } else if (streq((char *)cmd, "setBufferNumber") || streq((char *)cmd, "putBufferNumber")) --- 1577,1585 ---- nb_set_curbuf(buf->bufp); apply_autocmds(EVENT_BUFREADPOST, 0, 0, FALSE, buf->bufp); ! // handle any postponed key commands handle_key_queue(); ! // ===================================================================== } else if (streq((char *)cmd, "setBufferNumber") || streq((char *)cmd, "putBufferNumber")) *************** *** 1607,1625 **** buf->bufp = bufp; buf->nbbuf_number = bufp->b_fnum; ! /* "setBufferNumber" has the side effect of jumping to the buffer ! * (don't know why!). Don't do that for "putBufferNumber". */ if (*cmd != 'p') coloncmd(":buffer %d", bufp->b_fnum); else { buf->initDone = TRUE; ! /* handle any postponed key commands */ handle_key_queue(); } ! /* =====================================================================*/ } else if (streq((char *)cmd, "setFullName")) { --- 1607,1625 ---- buf->bufp = bufp; buf->nbbuf_number = bufp->b_fnum; ! // "setBufferNumber" has the side effect of jumping to the buffer ! // (don't know why!). Don't do that for "putBufferNumber". if (*cmd != 'p') coloncmd(":buffer %d", bufp->b_fnum); else { buf->initDone = TRUE; ! // handle any postponed key commands handle_key_queue(); } ! // ===================================================================== } else if (streq((char *)cmd, "setFullName")) { *************** *** 1632,1638 **** vim_free(buf->displayname); buf->displayname = nb_unquote(args, NULL); ! netbeansReadFile = 0; /* don't try to open disk file */ do_ecmd(0, (char_u *)buf->displayname, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF, curwin); netbeansReadFile = 1; --- 1632,1638 ---- vim_free(buf->displayname); buf->displayname = nb_unquote(args, NULL); ! netbeansReadFile = 0; // don't try to open disk file do_ecmd(0, (char_u *)buf->displayname, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF, curwin); netbeansReadFile = 1; *************** *** 1642,1648 **** if (gui.in_use) gui_update_menus(0); #endif ! /* =====================================================================*/ } else if (streq((char *)cmd, "editFile")) { --- 1642,1648 ---- if (gui.in_use) gui_update_menus(0); #endif ! // ===================================================================== } else if (streq((char *)cmd, "editFile")) { *************** *** 1652,1658 **** emsg("E644: invalid buffer identifier in editFile"); return FAIL; } ! /* Edit a file: like create + setFullName + read the file. */ vim_free(buf->displayname); buf->displayname = nb_unquote(args, NULL); do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE, --- 1652,1658 ---- emsg("E644: invalid buffer identifier in editFile"); return FAIL; } ! // Edit a file: like create + setFullName + read the file. vim_free(buf->displayname); buf->displayname = nb_unquote(args, NULL); do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE, *************** *** 1667,1681 **** if (gui.in_use) gui_update_menus(0); #endif ! /* =====================================================================*/ } else if (streq((char *)cmd, "setVisible")) { if (buf == NULL || buf->bufp == NULL) { nbdebug((" invalid buffer identifier in setVisible\n")); ! /* This message was commented out, probably because it can ! * happen when shutting down. */ if (p_verbose > 0) emsg("E645: invalid buffer identifier in setVisible"); return FAIL; --- 1667,1681 ---- if (gui.in_use) gui_update_menus(0); #endif ! // ===================================================================== } else if (streq((char *)cmd, "setVisible")) { if (buf == NULL || buf->bufp == NULL) { nbdebug((" invalid buffer identifier in setVisible\n")); ! // This message was commented out, probably because it can ! // happen when shutting down. if (p_verbose > 0) emsg("E645: invalid buffer identifier in setVisible"); return FAIL; *************** *** 1691,1711 **** dosetvisible = FALSE; #ifdef FEAT_GUI ! /* Side effect!!!. */ if (gui.in_use) gui_mch_set_foreground(); #endif } ! /* =====================================================================*/ } else if (streq((char *)cmd, "raise")) { #ifdef FEAT_GUI ! /* Bring gvim to the foreground. */ if (gui.in_use) gui_mch_set_foreground(); #endif ! /* =====================================================================*/ } else if (streq((char *)cmd, "setModified")) { --- 1691,1711 ---- dosetvisible = FALSE; #ifdef FEAT_GUI ! // Side effect!!!. if (gui.in_use) gui_mch_set_foreground(); #endif } ! // ===================================================================== } else if (streq((char *)cmd, "raise")) { #ifdef FEAT_GUI ! // Bring gvim to the foreground. if (gui.in_use) gui_mch_set_foreground(); #endif ! // ===================================================================== } else if (streq((char *)cmd, "setModified")) { *************** *** 1714,1721 **** if (buf == NULL || buf->bufp == NULL) { nbdebug((" invalid buffer identifier in setModified\n")); ! /* This message was commented out, probably because it can ! * happen when shutting down. */ if (p_verbose > 0) emsg("E646: invalid buffer identifier in setModified"); return FAIL; --- 1714,1721 ---- if (buf == NULL || buf->bufp == NULL) { nbdebug((" invalid buffer identifier in setModified\n")); ! // This message was commented out, probably because it can ! // happen when shutting down. if (p_verbose > 0) emsg("E646: invalid buffer identifier in setModified"); return FAIL; *************** *** 1727,1734 **** { stat_T st; ! /* Assume NetBeans stored the file. Reset the timestamp to ! * avoid "file changed" warnings. */ if (buf->bufp->b_ffname != NULL && mch_stat((char *)buf->bufp->b_ffname, &st) >= 0) buf_store_time(buf->bufp, &st, buf->bufp->b_ffname); --- 1727,1734 ---- { stat_T st; ! // Assume NetBeans stored the file. Reset the timestamp to ! // avoid "file changed" warnings. if (buf->bufp->b_ffname != NULL && mch_stat((char *)buf->bufp->b_ffname, &st) >= 0) buf_store_time(buf->bufp, &st, buf->bufp->b_ffname); *************** *** 1744,1750 **** #endif update_screen(0); } ! /* =====================================================================*/ } else if (streq((char *)cmd, "setModtime")) { --- 1744,1750 ---- #endif update_screen(0); } ! // ===================================================================== } else if (streq((char *)cmd, "setModtime")) { *************** *** 1752,1758 **** nbdebug((" invalid buffer identifier in setModtime\n")); else buf->bufp->b_mtime = atoi((char *)args); ! /* =====================================================================*/ } else if (streq((char *)cmd, "setReadOnly")) { --- 1752,1758 ---- nbdebug((" invalid buffer identifier in setModtime\n")); else buf->bufp->b_mtime = atoi((char *)args); ! // ===================================================================== } else if (streq((char *)cmd, "setReadOnly")) { *************** *** 1762,1773 **** buf->bufp->b_p_ro = TRUE; else buf->bufp->b_p_ro = FALSE; ! /* =====================================================================*/ } else if (streq((char *)cmd, "setMark")) { ! /* not yet */ ! /* =====================================================================*/ } else if (streq((char *)cmd, "showBalloon")) { --- 1762,1773 ---- buf->bufp->b_p_ro = TRUE; else buf->bufp->b_p_ro = FALSE; ! // ===================================================================== } else if (streq((char *)cmd, "setMark")) { ! // not yet ! // ===================================================================== } else if (streq((char *)cmd, "showBalloon")) { *************** *** 1787,1793 **** gui_mch_post_balloon(balloonEval, (char_u *)text); } #endif ! /* =====================================================================*/ } else if (streq((char *)cmd, "setDot")) { --- 1787,1793 ---- gui_mch_post_balloon(balloonEval, (char_u *)text); } #endif ! // ===================================================================== } else if (streq((char *)cmd, "setDot")) { *************** *** 1805,1811 **** nb_set_curbuf(buf->bufp); ! /* Don't want Visual mode now. */ if (VIsual_active) end_visual_mode(); #ifdef NBDEBUG --- 1805,1811 ---- nb_set_curbuf(buf->bufp); ! // Don't want Visual mode now. if (VIsual_active) end_visual_mode(); #ifdef NBDEBUG *************** *** 1825,1839 **** nbdebug((" BAD POSITION in setDot: %s\n", s)); } ! /* gui_update_cursor(TRUE, FALSE); */ ! /* update_curbuf(NOT_VALID); */ ! update_topline(); /* scroll to show the line */ update_screen(VALID); setcursor(); cursor_on(); out_flush_cursor(TRUE, FALSE); ! /* Quit a hit-return or more prompt. */ if (State == HITRETURN || State == ASKMORE) { #ifdef FEAT_GUI_GTK --- 1825,1839 ---- nbdebug((" BAD POSITION in setDot: %s\n", s)); } ! // gui_update_cursor(TRUE, FALSE); ! // update_curbuf(NOT_VALID); ! update_topline(); // scroll to show the line update_screen(VALID); setcursor(); cursor_on(); out_flush_cursor(TRUE, FALSE); ! // Quit a hit-return or more prompt. if (State == HITRETURN || State == ASKMORE) { #ifdef FEAT_GUI_GTK *************** *** 1841,1847 **** gtk_main_quit(); #endif } ! /* =====================================================================*/ } else if (streq((char *)cmd, "close")) { --- 1841,1847 ---- gtk_main_quit(); #endif } ! // ===================================================================== } else if (streq((char *)cmd, "close")) { *************** *** 1863,1870 **** if (buf->bufp == NULL) { nbdebug((" invalid buffer identifier in close\n")); ! /* This message was commented out, probably because it can ! * happen when shutting down. */ if (p_verbose > 0) emsg("E649: invalid buffer identifier in close"); } --- 1863,1870 ---- if (buf->bufp == NULL) { nbdebug((" invalid buffer identifier in close\n")); ! // This message was commented out, probably because it can ! // happen when shutting down. if (p_verbose > 0) emsg("E649: invalid buffer identifier in close"); } *************** *** 1878,1894 **** buf->bufp = NULL; buf->initDone = FALSE; do_update = 1; ! /* =====================================================================*/ } ! else if (streq((char *)cmd, "setStyle")) /* obsolete... */ { nbdebug((" setStyle is obsolete!\n")); ! /* =====================================================================*/ } else if (streq((char *)cmd, "setExitDelay")) { ! /* Only used in version 2.1. */ ! /* =====================================================================*/ } else if (streq((char *)cmd, "defineAnnoType")) { --- 1878,1894 ---- buf->bufp = NULL; buf->initDone = FALSE; do_update = 1; ! // ===================================================================== } ! else if (streq((char *)cmd, "setStyle")) // obsolete... { nbdebug((" setStyle is obsolete!\n")); ! // ===================================================================== } else if (streq((char *)cmd, "setExitDelay")) { ! // Only used in version 2.1. ! // ===================================================================== } else if (streq((char *)cmd, "defineAnnoType")) { *************** *** 1942,1948 **** else vim_free(typeName); ! /* don't free typeName; it's used directly in addsigntype() */ vim_free(fg); vim_free(bg); vim_free(tooltip); --- 1942,1948 ---- else vim_free(typeName); ! // don't free typeName; it's used directly in addsigntype() vim_free(fg); vim_free(bg); vim_free(tooltip); *************** *** 1951,1957 **** return FAIL; #endif ! /* =====================================================================*/ } else if (streq((char *)cmd, "addAnno")) { --- 1951,1957 ---- return FAIL; #endif ! // ===================================================================== } else if (streq((char *)cmd, "addAnno")) { *************** *** 1973,1980 **** cp = (char *)args; serNum = strtol(cp, &cp, 10); ! /* Get the typenr specific for this buffer and convert it to ! * the global typenumber, as used for the sign name. */ localTypeNum = strtol(cp, &cp, 10); args = (char_u *)cp; typeNum = mapsigntype(buf, localTypeNum); --- 1973,1980 ---- cp = (char *)args; serNum = strtol(cp, &cp, 10); ! // Get the typenr specific for this buffer and convert it to ! // the global typenumber, as used for the sign name. localTypeNum = strtol(cp, &cp, 10); args = (char_u *)cp; typeNum = mapsigntype(buf, localTypeNum); *************** *** 2002,2008 **** buf->bufp->b_fnum); } #endif ! /* =====================================================================*/ } else if (streq((char *)cmd, "removeAnno")) { --- 2002,2008 ---- buf->bufp->b_fnum); } #endif ! // ===================================================================== } else if (streq((char *)cmd, "removeAnno")) { *************** *** 2022,2035 **** serNum, buf->bufp->b_fnum); redraw_buf_later(buf->bufp, NOT_VALID); #endif ! /* =====================================================================*/ } else if (streq((char *)cmd, "moveAnnoToFront")) { #ifdef FEAT_SIGNS nbdebug((" moveAnnoToFront: Not Yet Implemented!\n")); #endif ! /* =====================================================================*/ } else if (streq((char *)cmd, "guard") || streq((char *)cmd, "unguard")) { --- 2022,2035 ---- serNum, buf->bufp->b_fnum); redraw_buf_later(buf->bufp, NOT_VALID); #endif ! // ===================================================================== } else if (streq((char *)cmd, "moveAnnoToFront")) { #ifdef FEAT_SIGNS nbdebug((" moveAnnoToFront: Not Yet Implemented!\n")); #endif ! // ===================================================================== } else if (streq((char *)cmd, "guard") || streq((char *)cmd, "unguard")) { *************** *** 2082,2088 **** { long lnum; last = *pos; ! /* set highlight for region */ nbdebug((" %sGUARD %ld,%d to %ld,%d\n", (un) ? "UN" : "", first.lnum, first.col, last.lnum, last.col)); --- 2082,2088 ---- { long lnum; last = *pos; ! // set highlight for region nbdebug((" %sGUARD %ld,%d to %ld,%d\n", (un) ? "UN" : "", first.lnum, first.col, last.lnum, last.col)); *************** *** 2091,2097 **** { if (un) { ! /* never used */ } else { --- 2091,2097 ---- { if (un) { ! // never used } else { *************** *** 2109,2120 **** redraw_buf_later(buf->bufp, NOT_VALID); } } ! /* =====================================================================*/ } else if (streq((char *)cmd, "startAtomic")) { inAtomic = 1; ! /* =====================================================================*/ } else if (streq((char *)cmd, "endAtomic")) { --- 2109,2120 ---- redraw_buf_later(buf->bufp, NOT_VALID); } } ! // ===================================================================== } else if (streq((char *)cmd, "startAtomic")) { inAtomic = 1; ! // ===================================================================== } else if (streq((char *)cmd, "endAtomic")) { *************** *** 2124,2130 **** do_update = 1; needupdate = 0; } ! /* =====================================================================*/ } else if (streq((char *)cmd, "save")) { --- 2124,2130 ---- do_update = 1; needupdate = 0; } ! // ===================================================================== } else if (streq((char *)cmd, "save")) { *************** *** 2138,2147 **** return FAIL; } ! /* the following is taken from ex_cmds.c (do_wqall function) */ if (bufIsChanged(buf->bufp)) { ! /* Only write if the buffer can be written. */ if (p_write && !buf->bufp->b_p_ro && buf->bufp->b_ffname != NULL --- 2138,2147 ---- return FAIL; } ! // the following is taken from ex_cmds.c (do_wqall function) if (bufIsChanged(buf->bufp)) { ! // Only write if the buffer can be written. if (p_write && !buf->bufp->b_p_ro && buf->bufp->b_ffname != NULL *************** *** 2154,2160 **** set_bufref(&bufref, buf->bufp); buf_write_all(buf->bufp, FALSE); ! /* an autocommand may have deleted the buffer */ if (!bufref_valid(&bufref)) buf->bufp = NULL; } --- 2154,2160 ---- set_bufref(&bufref, buf->bufp); buf_write_all(buf->bufp, FALSE); ! // an autocommand may have deleted the buffer if (!bufref_valid(&bufref)) buf->bufp = NULL; } *************** *** 2163,2169 **** { nbdebug((" Buffer has no changes!\n")); } ! /* =====================================================================*/ } else if (streq((char *)cmd, "netbeansBuffer")) { --- 2163,2169 ---- { nbdebug((" Buffer has no changes!\n")); } ! // ===================================================================== } else if (streq((char *)cmd, "netbeansBuffer")) { *************** *** 2179,2199 **** } else buf->bufp->b_netbeans_file = FALSE; ! /* =====================================================================*/ } else if (streq((char *)cmd, "specialKeys")) { special_keys(args); ! /* =====================================================================*/ } else if (streq((char *)cmd, "actionMenuItem")) { ! /* not used yet */ ! /* =====================================================================*/ } else if (streq((char *)cmd, "version")) { ! /* not used yet */ } else { --- 2179,2199 ---- } else buf->bufp->b_netbeans_file = FALSE; ! // ===================================================================== } else if (streq((char *)cmd, "specialKeys")) { special_keys(args); ! // ===================================================================== } else if (streq((char *)cmd, "actionMenuItem")) { ! // not used yet ! // ===================================================================== } else if (streq((char *)cmd, "version")) { ! // not used yet } else { *************** *** 2221,2227 **** cursor_on(); out_flush_cursor(TRUE, FALSE); ! /* Quit a hit-return or more prompt. */ if (State == HITRETURN || State == ASKMORE) { #ifdef FEAT_GUI_GTK --- 2221,2227 ---- cursor_on(); out_flush_cursor(TRUE, FALSE); ! // Quit a hit-return or more prompt. if (State == HITRETURN || State == ASKMORE) { #ifdef FEAT_GUI_GTK *************** *** 2269,2275 **** do_cmdline((char_u *)buf, NULL, NULL, DOCMD_NOWAIT | DOCMD_KEYTYPED); ! setcursor(); /* restore the cursor position */ out_flush_cursor(TRUE, FALSE); } --- 2269,2275 ---- do_cmdline((char_u *)buf, NULL, NULL, DOCMD_NOWAIT | DOCMD_KEYTYPED); ! setcursor(); // restore the cursor position out_flush_cursor(TRUE, FALSE); } *************** *** 2419,2425 **** default: if (key >= ' ' && key <= '~') { ! /* Allow ASCII characters. */ name = namebuf; namebuf[0] = key; namebuf[1] = NUL; --- 2419,2425 ---- default: if (key >= ' ' && key <= '~') { ! // Allow ASCII characters. name = namebuf; namebuf[0] = key; namebuf[1] = NUL; *************** *** 2435,2441 **** if (shift) strcat(buf, "S"); if (alt) ! strcat(buf, "M"); /* META */ if (ctrl || shift || alt) strcat(buf, "-"); strcat(buf, name); --- 2435,2441 ---- if (shift) strcat(buf, "S"); if (alt) ! strcat(buf, "M"); // META if (ctrl || shift || alt) strcat(buf, "-"); strcat(buf, name); *************** *** 2459,2473 **** char *buf; char_u *p; ! /* Don't do anything when 'ballooneval' is off, messages scrolled the ! * windows up or we have no connection. */ if (!can_use_beval() || !NETBEANS_OPEN) return; if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK) { ! /* Send debugger request. Only when the text is of reasonable ! * length. */ if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL) { buf = alloc(MAXPATHL * 2 + 25); --- 2459,2473 ---- char *buf; char_u *p; ! // Don't do anything when 'ballooneval' is off, messages scrolled the ! // windows up or we have no connection. if (!can_use_beval() || !NETBEANS_OPEN) return; if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK) { ! // Send debugger request. Only when the text is of reasonable ! // length. if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL) { buf = alloc(MAXPATHL * 2 + 25); *************** *** 2519,2525 **** nbdebug(("EVT: %s", cmd)); nb_send(cmd, "netbeans_startup_done"); ! /* update the screen after having added the gutter */ changed_window_setting(); update_screen(CLEAR); setcursor(); --- 2519,2525 ---- nbdebug(("EVT: %s", cmd)); nb_send(cmd, "netbeans_startup_done"); ! // update the screen after having added the gutter changed_window_setting(); update_screen(CLEAR); setcursor(); *************** *** 2575,2581 **** sprintf(buf, "0:geometry=%d %d %d %d %d\n", r_cmdno, (int)Columns, (int)Rows, new_x, new_y); ! /*nbdebug(("EVT: %s", buf)); happens too many times during a move */ nb_send(buf, "netbeans_frame_moved"); } #endif --- 2575,2581 ---- sprintf(buf, "0:geometry=%d %d %d %d %d\n", r_cmdno, (int)Columns, (int)Rows, new_x, new_y); ! // nbdebug(("EVT: %s", buf)); happens too many times during a move nb_send(buf, "netbeans_frame_moved"); } #endif *************** *** 2602,2609 **** bufno, bufno, (char *)q, ! "T", /* open in NetBeans */ ! "F"); /* modified */ vim_free(q); nbdebug(("EVT: %s", buffer)); --- 2602,2609 ---- bufno, bufno, (char *)q, ! "T", // open in NetBeans ! "F"); // modified vim_free(q); nbdebug(("EVT: %s", buffer)); *************** *** 2638,2645 **** bnum, 0, (char *)q, ! "T", /* open in NetBeans */ ! "F"); /* modified */ vim_free(q); nbdebug(("EVT: %s", buffer)); --- 2638,2645 ---- bnum, 0, (char *)q, ! "T", // open in NetBeans ! "F"); // modified vim_free(q); nbdebug(("EVT: %s", buffer)); *************** *** 2687,2701 **** nbbuf_T *nbbuf; if (!NETBEANS_OPEN || !netbeansFireChanges) ! return NULL; /* changes are not reported at all */ bufno = nb_getbufno(bufp); if (bufno <= 0) ! return NULL; /* file is not known to NetBeans */ nbbuf = nb_get_buf(bufno); if (nbbuf != NULL && !nbbuf->fireChanges) ! return NULL; /* changes in this buffer are not reported */ *bufnop = bufno; return nbbuf; --- 2687,2701 ---- nbbuf_T *nbbuf; if (!NETBEANS_OPEN || !netbeansFireChanges) ! return NULL; // changes are not reported at all bufno = nb_getbufno(bufp); if (bufno <= 0) ! return NULL; // file is not known to NetBeans nbbuf = nb_get_buf(bufno); if (nbbuf != NULL && !nbbuf->fireChanges) ! return NULL; // changes in this buffer are not reported *bufnop = bufno; return nbbuf; *************** *** 2727,2733 **** if (nbbuf == NULL) return; ! /* Don't mark as modified for initial read */ if (nbbuf->insertDone) nbbuf->modified = 1; --- 2727,2733 ---- if (nbbuf == NULL) return; ! // Don't mark as modified for initial read if (nbbuf->insertDone) nbbuf->modified = 1; *************** *** 2735,2741 **** pos.col = col; off = pos2off(bufp, &pos); ! /* send the "insert" EVT */ newtxt = alloc(newlen + 1); vim_strncpy(newtxt, txt, newlen); p = nb_quote(newtxt); --- 2735,2741 ---- pos.col = col; off = pos2off(bufp, &pos); ! // send the "insert" EVT newtxt = alloc(newlen + 1); vim_strncpy(newtxt, txt, newlen); p = nb_quote(newtxt); *************** *** 2799,2806 **** void netbeans_unmodified(buf_T *bufp UNUSED) { ! /* This is a no-op, because NetBeans considers a buffer modified ! * even when all changes have been undone. */ } /* --- 2799,2806 ---- void netbeans_unmodified(buf_T *bufp UNUSED) { ! // This is a no-op, because NetBeans considers a buffer modified ! // even when all changes have been undone. } /* *************** *** 2824,2830 **** - ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1); long off = pos2off(curbuf, &curwin->w_cursor); ! /* sync the cursor position */ sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off); nbdebug(("EVT: %s", buf)); nb_send(buf, "netbeans_button_release[newDotAndMark]"); --- 2824,2830 ---- - ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1); long off = pos2off(curbuf, &curwin->w_cursor); ! // sync the cursor position sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off); nbdebug(("EVT: %s", buf)); nb_send(buf, "netbeans_button_release[newDotAndMark]"); *************** *** 2879,2886 **** return TRUE; vim_snprintf(buf, sizeof(buf), "0:fileOpened=%d \"%s\" %s %s\n", 0, q, ! "T", /* open in NetBeans */ ! "F"); /* modified */ if (curbuf->b_ffname != NULL) vim_free(q); nbdebug(("EVT: %s", buf)); --- 2879,2886 ---- return TRUE; vim_snprintf(buf, sizeof(buf), "0:fileOpened=%d \"%s\" %s %s\n", 0, q, ! "T", // open in NetBeans ! "F"); // modified if (curbuf->b_ffname != NULL) vim_free(q); nbdebug(("EVT: %s", buf)); *************** *** 2890,2913 **** return FALSE; } ! /* sync the cursor position */ off = pos2off(curbuf, &curwin->w_cursor); sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off); nbdebug(("EVT: %s", buf)); nb_send(buf, "netbeans_keycommand"); ! /* To work on Win32 you must apply patch to ExtEditor module ! * from ExtEdCaret.java.diff - make EVT_newDotAndMark handler ! * more synchronous ! */ ! /* now send keyCommand event */ vim_snprintf(buf, sizeof(buf), "%d:keyCommand=%d \"%s\"\n", bufno, r_cmdno, keyName); nbdebug(("EVT: %s", buf)); nb_send(buf, "netbeans_keycommand"); ! /* New: do both at once and include the lnum/col. */ vim_snprintf(buf, sizeof(buf), "%d:keyAtPos=%d \"%s\" %ld %ld/%ld\n", bufno, r_cmdno, keyName, off, (long)curwin->w_cursor.lnum, (long)curwin->w_cursor.col); --- 2890,2912 ---- return FALSE; } ! // sync the cursor position off = pos2off(curbuf, &curwin->w_cursor); sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off); nbdebug(("EVT: %s", buf)); nb_send(buf, "netbeans_keycommand"); ! // To work on Win32 you must apply patch to ExtEditor module ! // from ExtEdCaret.java.diff - make EVT_newDotAndMark handler ! // more synchronous ! // now send keyCommand event vim_snprintf(buf, sizeof(buf), "%d:keyCommand=%d \"%s\"\n", bufno, r_cmdno, keyName); nbdebug(("EVT: %s", buf)); nb_send(buf, "netbeans_keycommand"); ! // New: do both at once and include the lnum/col. vim_snprintf(buf, sizeof(buf), "%d:keyAtPos=%d \"%s\" %ld %ld/%ld\n", bufno, r_cmdno, keyName, off, (long)curwin->w_cursor.lnum, (long)curwin->w_cursor.col); *************** *** 2959,2971 **** if (nbbuf == NULL) return; ! /* Don't mark as modified for initial read */ if (nbbuf->insertDone) nbbuf->modified = 1; sprintf((char *)buf, "%d:remove=%d 0 -1\n", bufno, r_cmdno); nbdebug(("EVT(suppressed): %s", buf)); ! /* nb_send(buf, "netbeans_deleted_all_lines"); */ } --- 2958,2970 ---- if (nbbuf == NULL) return; ! // Don't mark as modified for initial read if (nbbuf->insertDone) nbbuf->modified = 1; sprintf((char *)buf, "%d:remove=%d 0 -1\n", bufno, r_cmdno); nbdebug(("EVT(suppressed): %s", buf)); ! // nb_send(buf, "netbeans_deleted_all_lines"); } *************** *** 3021,3027 **** XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+3, y++); XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y); } ! #endif /* FEAT_GUI_X11 */ #if defined(FEAT_GUI_GTK) && !defined(PROTO) /* --- 3020,3026 ---- XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+3, y++); XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y); } ! #endif // FEAT_GUI_X11 #if defined(FEAT_GUI_GTK) && !defined(PROTO) /* *************** *** 3082,3088 **** cairo_destroy(cr); #endif } ! #endif /* FEAT_GUI_GTK */ /* * If the mouse is clicked in the gutter of a line with multiple --- 3081,3087 ---- cairo_destroy(cr); #endif } ! #endif // FEAT_GUI_GTK /* * If the mouse is clicked in the gutter of a line with multiple *************** *** 3102,3121 **** { sign_entry_T *tail; ! /* remove "p" from list, reinsert it at the tail of the sublist */ if (p->se_prev) p->se_prev->se_next = p->se_next; else curbuf->b_signlist = p->se_next; p->se_next->se_prev = p->se_prev; ! /* now find end of sublist and insert p */ for (tail = p->se_next; tail->se_next && tail->se_next->se_lnum == lnum && tail->se_next->se_id < GUARDEDOFFSET; tail = tail->se_next) ; ! /* tail now points to last entry with same lnum (except ! * that "guarded" annotations are always last) */ p->se_next = tail->se_next; if (tail->se_next) tail->se_next->se_prev = p; --- 3101,3120 ---- { sign_entry_T *tail; ! // remove "p" from list, reinsert it at the tail of the sublist if (p->se_prev) p->se_prev->se_next = p->se_next; else curbuf->b_signlist = p->se_next; p->se_next->se_prev = p->se_prev; ! // now find end of sublist and insert p for (tail = p->se_next; tail->se_next && tail->se_next->se_lnum == lnum && tail->se_next->se_id < GUARDEDOFFSET; tail = tail->se_next) ; ! // tail now points to last entry with same lnum (except ! // that "guarded" annotations are always last) p->se_next = tail->se_next; if (tail->se_next) tail->se_next->se_prev = p; *************** *** 3160,3166 **** if (STRCMP(typeName, globalsignmap[i]) == 0) break; ! if (i == globalsignmapused) /* not found; add it to global map */ { nbdebug(("DEFINEANNOTYPE(%d,%s,%s,%s,%s,%s)\n", typeNum, typeName, tooltip, glyphFile, fg, bg)); --- 3159,3165 ---- if (STRCMP(typeName, globalsignmap[i]) == 0) break; ! if (i == globalsignmapused) // not found; add it to global map { nbdebug(("DEFINEANNOTYPE(%d,%s,%s,%s,%s,%s)\n", typeNum, typeName, tooltip, glyphFile, fg, bg)); *************** *** 3186,3205 **** coloncmd(":highlight NB_%s %s %s", typeName, (use_fg) ? fgbuf : "", (use_bg) ? bgbuf : ""); if (*glyphFile == NUL) ! /* no glyph, line highlighting only */ coloncmd(":sign define %d linehl=NB_%s", i + 1, typeName); else if (vim_strsize(glyphFile) <= 2) ! /* one- or two-character glyph name, use as text glyph with ! * texthl */ coloncmd(":sign define %d text=%s texthl=NB_%s", i + 1, glyphFile, typeName); else ! /* glyph, line highlighting */ coloncmd(":sign define %d icon=%s linehl=NB_%s", i + 1, glyphFile, typeName); } else ! /* glyph, no line highlighting */ coloncmd(":sign define %d icon=%s", i + 1, glyphFile); if (STRCMP(typeName,"CurrentPC") == 0) --- 3185,3204 ---- coloncmd(":highlight NB_%s %s %s", typeName, (use_fg) ? fgbuf : "", (use_bg) ? bgbuf : ""); if (*glyphFile == NUL) ! // no glyph, line highlighting only coloncmd(":sign define %d linehl=NB_%s", i + 1, typeName); else if (vim_strsize(glyphFile) <= 2) ! // one- or two-character glyph name, use as text glyph with ! // texthl coloncmd(":sign define %d text=%s texthl=NB_%s", i + 1, glyphFile, typeName); else ! // glyph, line highlighting coloncmd(":sign define %d icon=%s linehl=NB_%s", i + 1, glyphFile, typeName); } else ! // glyph, no line highlighting coloncmd(":sign define %d icon=%s", i + 1, glyphFile); if (STRCMP(typeName,"CurrentPC") == 0) *************** *** 3207,3218 **** if (globalsignmapused == globalsignmaplen) { ! if (globalsignmaplen == 0) /* first allocation */ { globalsignmaplen = 20; globalsignmap = ALLOC_CLEAR_MULT(char *, globalsignmaplen); } ! else /* grow it */ { int incr; int oldlen = globalsignmaplen; --- 3206,3217 ---- if (globalsignmapused == globalsignmaplen) { ! if (globalsignmaplen == 0) // first allocation { globalsignmaplen = 20; globalsignmap = ALLOC_CLEAR_MULT(char *, globalsignmaplen); } ! else // grow it { int incr; int oldlen = globalsignmaplen; *************** *** 3236,3255 **** globalsignmapused = i + 1; } ! /* check local map; should *not* be found! */ for (j = 0; j < buf->signmapused; j++) if (buf->signmap[j] == i + 1) return; ! /* add to local map */ if (buf->signmapused == buf->signmaplen) { ! if (buf->signmaplen == 0) /* first allocation */ { buf->signmaplen = 5; buf->signmap = ALLOC_CLEAR_MULT(int, buf->signmaplen); } ! else /* grow it */ { int incr; int oldlen = buf->signmaplen; --- 3235,3254 ---- globalsignmapused = i + 1; } ! // check local map; should *not* be found! for (j = 0; j < buf->signmapused; j++) if (buf->signmap[j] == i + 1) return; ! // add to local map if (buf->signmapused == buf->signmaplen) { ! if (buf->signmaplen == 0) // first allocation { buf->signmaplen = 5; buf->signmap = ALLOC_CLEAR_MULT(int, buf->signmaplen); } ! else // grow it { int incr; int oldlen = buf->signmaplen; *************** *** 3310,3316 **** { char_count += (long)STRLEN(ml_get_buf(bufp, lnum, FALSE)) + eol_size; ! /* Check for a CTRL-C every 100000 characters */ if (char_count > last_check) { ui_breakcheck(); --- 3309,3315 ---- { char_count += (long)STRLEN(ml_get_buf(bufp, lnum, FALSE)) + eol_size; ! // Check for a CTRL-C every 100000 characters if (char_count > last_check) { ui_breakcheck(); *************** *** 3319,3325 **** last_check = char_count + 100000L; } } ! /* Correction for when last line doesn't have an EOL. */ if (!bufp->b_p_eol && (bufp->b_p_bin || !bufp->b_p_fixeol)) char_count -= eol_size; } --- 3318,3324 ---- last_check = char_count + 100000L; } } ! // Correction for when last line doesn't have an EOL. if (!bufp->b_p_eol && (bufp->b_p_bin || !bufp->b_p_fixeol)) char_count -= eol_size; } *************** *** 3424,3430 **** } msg_add_lines(c, (long)lnum, nchars); ! /* Now display it */ VIM_CLEAR(keep_msg); msg_scrolled_ign = TRUE; msg_trunc_attr((char *)IObuff, FALSE, 0); --- 3423,3429 ---- } msg_add_lines(c, (long)lnum, nchars); ! // Now display it VIM_CLEAR(keep_msg); msg_scrolled_ign = TRUE; msg_trunc_attr((char *)IObuff, FALSE, 0); *************** *** 3445,3451 **** if (nchars >= 0) { ! /* put fname in IObuff with quotes */ msg_add_fname(buf->bufp, buf->bufp->b_ffname); c = FALSE; --- 3444,3450 ---- if (nchars >= 0) { ! // put fname in IObuff with quotes msg_add_fname(buf->bufp, buf->bufp->b_ffname); c = FALSE; *************** *** 3457,3472 **** p = (char_u *)msg_trunc_attr((char *)IObuff, FALSE, 0); if ((msg_scrolled && !need_wait_return) || !buf->initDone) { ! /* Need to repeat the message after redrawing when: ! * - When reading from stdin (the screen will be cleared next). ! * - When restart_edit is set (otherwise there will be a delay ! * before redrawing). ! * - When the screen was scrolled but there is no wait-return ! * prompt. */ set_keep_msg(p, 0); } msg_scrolled_ign = FALSE; ! /* add_to_input_buf((char_u *)"\f", 1); */ } else { --- 3456,3471 ---- p = (char_u *)msg_trunc_attr((char *)IObuff, FALSE, 0); if ((msg_scrolled && !need_wait_return) || !buf->initDone) { ! // Need to repeat the message after redrawing when: ! // - When reading from stdin (the screen will be cleared next). ! // - When restart_edit is set (otherwise there will be a delay ! // before redrawing). ! // - When the screen was scrolled but there is no wait-return ! // prompt. set_keep_msg(p, 0); } msg_scrolled_ign = FALSE; ! // add_to_input_buf((char_u *)"\f", 1); } else { *************** *** 3479,3482 **** } } ! #endif /* defined(FEAT_NETBEANS_INTG) */ --- 3478,3481 ---- } } ! #endif // defined(FEAT_NETBEANS_INTG) *** ../vim-8.1.2391/src/normal.c 2019-12-01 19:37:03.468332588 +0100 --- src/normal.c 2019-12-05 20:05:26.989439189 +0100 *************** *** 137,154 **** */ typedef void (*nv_func_T)(cmdarg_T *cap); ! /* Values for cmd_flags. */ ! #define NV_NCH 0x01 /* may need to get a second char */ ! #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */ ! #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */ ! #define NV_LANG 0x08 /* second char needs language adjustment */ ! ! #define NV_SS 0x10 /* may start selection */ ! #define NV_SSS 0x20 /* may start selection with shift modifier */ ! #define NV_STS 0x40 /* may stop selection without shift modif. */ ! #define NV_RL 0x80 /* 'rightleft' modifies command */ ! #define NV_KEEPREG 0x100 /* don't clear regname */ ! #define NV_NCW 0x200 /* not allowed in command-line window */ /* * Generally speaking, every Normal mode command should either clear any --- 137,154 ---- */ typedef void (*nv_func_T)(cmdarg_T *cap); ! // Values for cmd_flags. ! #define NV_NCH 0x01 // may need to get a second char ! #define NV_NCH_NOP (0x02|NV_NCH) // get second char when no operator pending ! #define NV_NCH_ALW (0x04|NV_NCH) // always get a second char ! #define NV_LANG 0x08 // second char needs language adjustment ! ! #define NV_SS 0x10 // may start selection ! #define NV_SSS 0x20 // may start selection with shift modifier ! #define NV_STS 0x40 // may stop selection without shift modif. ! #define NV_RL 0x80 // 'rightleft' modifies command ! #define NV_KEEPREG 0x100 // don't clear regname ! #define NV_NCW 0x200 // not allowed in command-line window /* * Generally speaking, every Normal mode command should either clear any *************** *** 167,176 **** */ static const struct nv_cmd { ! int cmd_char; /* (first) command character */ ! nv_func_T cmd_func; /* function for this command */ ! short_u cmd_flags; /* NV_ flags */ ! short cmd_arg; /* value for ca.arg */ } nv_cmds[] = { {NUL, nv_error, 0, 0}, --- 167,176 ---- */ static const struct nv_cmd { ! int cmd_char; // (first) command character ! nv_func_T cmd_func; // function for this command ! short_u cmd_flags; // NV_ flags ! short cmd_arg; // value for ca.arg } nv_cmds[] = { {NUL, nv_error, 0, 0}, *************** *** 301,307 **** {'}', nv_findpar, 0, FORWARD}, {'~', nv_tilde, 0, 0}, ! /* pound sign */ {POUND, nv_ident, 0, 0}, {K_MOUSEUP, nv_mousescroll, 0, MSCR_UP}, {K_MOUSEDOWN, nv_mousescroll, 0, MSCR_DOWN}, --- 301,307 ---- {'}', nv_findpar, 0, FORWARD}, {'~', nv_tilde, 0, 0}, ! // pound sign {POUND, nv_ident, 0, 0}, {K_MOUSEUP, nv_mousescroll, 0, MSCR_UP}, {K_MOUSEDOWN, nv_mousescroll, 0, MSCR_DOWN}, *************** *** 377,390 **** {K_PS, nv_edit, 0, 0}, }; ! /* Number of commands in nv_cmds[]. */ #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) ! /* Sorted index of commands in nv_cmds[]. */ static short nv_cmd_idx[NV_CMDS_SIZE]; ! /* The highest index for which ! * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ static int nv_max_linear; /* --- 377,390 ---- {K_PS, nv_edit, 0, 0}, }; ! // Number of commands in nv_cmds[]. #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) ! // Sorted index of commands in nv_cmds[]. static short nv_cmd_idx[NV_CMDS_SIZE]; ! // The highest index for which ! // nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] static int nv_max_linear; /* *************** *** 396,402 **** { int c1, c2; ! /* The commands are sorted on absolute value. */ c1 = nv_cmds[*(const short *)s1].cmd_char; c2 = nv_cmds[*(const short *)s2].cmd_char; if (c1 < 0) --- 396,402 ---- { int c1, c2; ! // The commands are sorted on absolute value. c1 = nv_cmds[*(const short *)s1].cmd_char; c2 = nv_cmds[*(const short *)s2].cmd_char; if (c1 < 0) *************** *** 414,427 **** { int i; ! /* Fill the index table with a one to one relation. */ for (i = 0; i < (int)NV_CMDS_SIZE; ++i) nv_cmd_idx[i] = i; ! /* Sort the commands by the command character. */ qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); ! /* Find the first entry that can't be indexed by the command character. */ for (i = 0; i < (int)NV_CMDS_SIZE; ++i) if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) break; --- 414,427 ---- { int i; ! // Fill the index table with a one to one relation. for (i = 0; i < (int)NV_CMDS_SIZE; ++i) nv_cmd_idx[i] = i; ! // Sort the commands by the command character. qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); ! // Find the first entry that can't be indexed by the command character. for (i = 0; i < (int)NV_CMDS_SIZE; ++i) if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) break; *************** *** 440,460 **** int top, bot; int c; ! /* A multi-byte character is never a command. */ if (cmdchar >= 0x100) return -1; ! /* We use the absolute value of the character. Special keys have a ! * negative value, but are sorted on their absolute value. */ if (cmdchar < 0) cmdchar = -cmdchar; ! /* If the character is in the first part: The character is the index into ! * nv_cmd_idx[]. */ if (cmdchar <= nv_max_linear) return nv_cmd_idx[cmdchar]; ! /* Perform a binary search. */ bot = nv_max_linear + 1; top = NV_CMDS_SIZE - 1; idx = -1; --- 440,460 ---- int top, bot; int c; ! // A multi-byte character is never a command. if (cmdchar >= 0x100) return -1; ! // We use the absolute value of the character. Special keys have a ! // negative value, but are sorted on their absolute value. if (cmdchar < 0) cmdchar = -cmdchar; ! // If the character is in the first part: The character is the index into ! // nv_cmd_idx[]. if (cmdchar <= nv_max_linear) return nv_cmd_idx[cmdchar]; ! // Perform a binary search. bot = nv_max_linear + 1; top = NV_CMDS_SIZE - 1; idx = -1; *************** *** 483,498 **** void normal_cmd( oparg_T *oap, ! int toplevel UNUSED) /* TRUE when called from main() */ { ! cmdarg_T ca; /* command arguments */ int c; ! int ctrl_w = FALSE; /* got CTRL-W command */ int old_col = curwin->w_curswant; #ifdef FEAT_CMDL_INFO ! int need_flushbuf; /* need to call out_flush() */ #endif ! pos_T old_pos; /* cursor position before command */ int mapped_len; static int old_mapped_len = 0; int idx; --- 483,498 ---- void normal_cmd( oparg_T *oap, ! int toplevel UNUSED) // TRUE when called from main() { ! cmdarg_T ca; // command arguments int c; ! int ctrl_w = FALSE; // got CTRL-W command int old_col = curwin->w_curswant; #ifdef FEAT_CMDL_INFO ! int need_flushbuf; // need to call out_flush() #endif ! pos_T old_pos; // cursor position before command int mapped_len; static int old_mapped_len = 0; int idx; *************** *** 500,511 **** int set_prevcount = FALSE; #endif ! vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ ca.oap = oap; ! /* Use a count remembered from before entering an operator. After typing ! * "3d" we return from normal_cmd() and come back here, the "3" is ! * remembered in "opcount". */ ca.opcount = opcount; /* --- 500,511 ---- int set_prevcount = FALSE; #endif ! vim_memset(&ca, 0, sizeof(ca)); // also resets ca.retval ca.oap = oap; ! // Use a count remembered from before entering an operator. After typing ! // "3d" we return from normal_cmd() and come back here, the "3" is ! // remembered in "opcount". ca.opcount = opcount; /* *************** *** 520,534 **** #ifdef CURSOR_SHAPE if (finish_op != c) { ! ui_cursor_shape(); /* may show different cursor shape */ # ifdef FEAT_MOUSESHAPE update_mouseshape(-1); # endif } #endif ! /* When not finishing an operator and no register name typed, reset the ! * count. */ if (!finish_op && !oap->regname) { ca.opcount = 0; --- 520,534 ---- #ifdef CURSOR_SHAPE if (finish_op != c) { ! ui_cursor_shape(); // may show different cursor shape # ifdef FEAT_MOUSESHAPE update_mouseshape(-1); # endif } #endif ! // When not finishing an operator and no register name typed, reset the ! // count. if (!finish_op && !oap->regname) { ca.opcount = 0; *************** *** 537,545 **** #endif } ! /* Restore counts from before receiving K_CURSORHOLD. This means after ! * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not ! * "3 * 2". */ if (oap->prev_opcount > 0 || oap->prev_count0 > 0) { ca.opcount = oap->prev_opcount; --- 537,545 ---- #endif } ! // Restore counts from before receiving K_CURSORHOLD. This means after ! // typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not ! // "3 * 2". if (oap->prev_opcount > 0 || oap->prev_count0 > 0) { ca.opcount = oap->prev_opcount; *************** *** 552,564 **** State = NORMAL_BUSY; #ifdef USE_ON_FLY_SCROLL ! dont_scroll = FALSE; /* allow scrolling here */ #endif #ifdef FEAT_EVAL ! /* Set v:count here, when called from main() and not a stuffed ! * command, so that v:count can be used in an expression mapping ! * when there is no count. Do set it for redo. */ if (toplevel && readbuf1_empty()) set_vcount_ca(&ca, &set_prevcount); #endif --- 552,564 ---- State = NORMAL_BUSY; #ifdef USE_ON_FLY_SCROLL ! dont_scroll = FALSE; // allow scrolling here #endif #ifdef FEAT_EVAL ! // Set v:count here, when called from main() and not a stuffed ! // command, so that v:count can be used in an expression mapping ! // when there is no count. Do set it for redo. if (toplevel && readbuf1_empty()) set_vcount_ca(&ca, &set_prevcount); #endif *************** *** 590,607 **** && VIsual_select && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) { ! /* Fake a "c"hange command. When "restart_edit" is set (e.g., because ! * 'insertmode' is set) fake a "d"elete command, Insert mode will ! * restart automatically. ! * Insert the typed character in the typeahead buffer, so that it can ! * be mapped in Insert mode. Required for ":lmap" to work. */ ins_char_typebuf(c); if (restart_edit != 0) c = 'd'; else c = 'c'; ! msg_nowait = TRUE; /* don't delay going to insert mode */ ! old_mapped_len = 0; /* do go to Insert mode */ } #ifdef FEAT_CMDL_INFO --- 590,607 ---- && VIsual_select && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) { ! // Fake a "c"hange command. When "restart_edit" is set (e.g., because ! // 'insertmode' is set) fake a "d"elete command, Insert mode will ! // restart automatically. ! // Insert the typed character in the typeahead buffer, so that it can ! // be mapped in Insert mode. Required for ":lmap" to work. ins_char_typebuf(c); if (restart_edit != 0) c = 'd'; else c = 'c'; ! msg_nowait = TRUE; // don't delay going to insert mode ! old_mapped_len = 0; // do go to Insert mode } #ifdef FEAT_CMDL_INFO *************** *** 623,648 **** { ca.count0 /= 10; #ifdef FEAT_CMDL_INFO ! del_from_showcmd(4); /* delete the digit and ~@% */ #endif } else ca.count0 = ca.count0 * 10 + (c - '0'); ! if (ca.count0 < 0) /* got too large! */ ca.count0 = 999999999L; #ifdef FEAT_EVAL ! /* Set v:count here, when called from main() and not a stuffed ! * command, so that v:count can be used in an expression mapping ! * right after the count. Do set it for redo. */ if (toplevel && readbuf1_empty()) set_vcount_ca(&ca, &set_prevcount); #endif if (ctrl_w) { ++no_mapping; ! ++allow_keys; /* no mapping for nchar, but keys */ } ! ++no_zero_mapping; /* don't map zero here */ c = plain_vgetc(); LANGMAP_ADJUST(c, TRUE); --no_zero_mapping; --- 623,648 ---- { ca.count0 /= 10; #ifdef FEAT_CMDL_INFO ! del_from_showcmd(4); // delete the digit and ~@% #endif } else ca.count0 = ca.count0 * 10 + (c - '0'); ! if (ca.count0 < 0) // got too large! ca.count0 = 999999999L; #ifdef FEAT_EVAL ! // Set v:count here, when called from main() and not a stuffed ! // command, so that v:count can be used in an expression mapping ! // right after the count. Do set it for redo. if (toplevel && readbuf1_empty()) set_vcount_ca(&ca, &set_prevcount); #endif if (ctrl_w) { ++no_mapping; ! ++allow_keys; // no mapping for nchar, but keys } ! ++no_zero_mapping; // don't map zero here c = plain_vgetc(); LANGMAP_ADJUST(c, TRUE); --no_zero_mapping; *************** *** 662,686 **** if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) { ctrl_w = TRUE; ! ca.opcount = ca.count0; /* remember first count */ ca.count0 = 0; ++no_mapping; ! ++allow_keys; /* no mapping for nchar, but keys */ ! c = plain_vgetc(); /* get next character */ LANGMAP_ADJUST(c, TRUE); --no_mapping; --allow_keys; #ifdef FEAT_CMDL_INFO need_flushbuf |= add_to_showcmd(c); #endif ! goto getcount; /* jump back */ } } if (c == K_CURSORHOLD) { ! /* Save the count values so that ca.opcount and ca.count0 are exactly ! * the same when coming back here after handling K_CURSORHOLD. */ oap->prev_opcount = ca.opcount; oap->prev_count0 = ca.count0; } --- 662,686 ---- if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) { ctrl_w = TRUE; ! ca.opcount = ca.count0; // remember first count ca.count0 = 0; ++no_mapping; ! ++allow_keys; // no mapping for nchar, but keys ! c = plain_vgetc(); // get next character LANGMAP_ADJUST(c, TRUE); --no_mapping; --allow_keys; #ifdef FEAT_CMDL_INFO need_flushbuf |= add_to_showcmd(c); #endif ! goto getcount; // jump back } } if (c == K_CURSORHOLD) { ! // Save the count values so that ca.opcount and ca.count0 are exactly ! // the same when coming back here after handling K_CURSORHOLD. oap->prev_opcount = ca.opcount; oap->prev_count0 = ca.count0; } *************** *** 733,746 **** idx = find_command(ca.cmdchar); if (idx < 0) { ! /* Not a known command: beep. */ clearopbeep(oap); goto normal_end; } if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) { ! /* This command is not allowed while editing a cmdline: beep. */ clearopbeep(oap); text_locked_msg(); goto normal_end; --- 733,746 ---- idx = find_command(ca.cmdchar); if (idx < 0) { ! // Not a known command: beep. clearopbeep(oap); goto normal_end; } if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) { ! // This command is not allowed while editing a cmdline: beep. clearopbeep(oap); text_locked_msg(); goto normal_end; *************** *** 753,759 **** */ if (VIsual_active) { ! /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ if (km_stopsel && (nv_cmds[idx].cmd_flags & NV_STS) && !(mod_mask & MOD_MASK_SHIFT)) --- 753,759 ---- */ if (VIsual_active) { ! // when 'keymodel' contains "stopsel" may stop Select/Visual mode if (km_stopsel && (nv_cmds[idx].cmd_flags & NV_STS) && !(mod_mask & MOD_MASK_SHIFT)) *************** *** 762,768 **** redraw_curbuf_later(INVERTED); } ! /* Keys that work different when 'keymodel' contains "startsel" */ if (km_startsel) { if (nv_cmds[idx].cmd_flags & NV_SS) --- 762,768 ---- redraw_curbuf_later(INVERTED); } ! // Keys that work different when 'keymodel' contains "startsel" if (km_startsel) { if (nv_cmds[idx].cmd_flags & NV_SS) *************** *** 771,777 **** idx = find_command(ca.cmdchar); if (idx < 0) { ! /* Just in case */ clearopbeep(oap); goto normal_end; } --- 771,777 ---- idx = find_command(ca.cmdchar); if (idx < 0) { ! // Just in case clearopbeep(oap); goto normal_end; } *************** *** 786,794 **** if (curwin->w_p_rl && KeyTyped && !KeyStuffed && (nv_cmds[idx].cmd_flags & NV_RL)) { ! /* Invert horizontal movements and operations. Only when typed by the ! * user directly, not when the result of a mapping or "x" translated ! * to "dl". */ switch (ca.cmdchar) { case 'l': ca.cmdchar = 'h'; break; --- 786,794 ---- if (curwin->w_p_rl && KeyTyped && !KeyStuffed && (nv_cmds[idx].cmd_flags & NV_RL)) { ! // Invert horizontal movements and operations. Only when typed by the ! // user directly, not when the result of a mapping or "x" translated ! // to "dl". switch (ca.cmdchar) { case 'l': ca.cmdchar = 'h'; break; *************** *** 821,838 **** && (oap->op_type != OP_NOP || VIsual_active)))) { int *cp; ! int repl = FALSE; /* get character for replace mode */ ! int lit = FALSE; /* get extra character literally */ ! int langmap_active = FALSE; /* using :lmap mappings */ ! int lang; /* getting a text character */ #ifdef HAVE_INPUT_METHOD ! int save_smd; /* saved value of p_smd */ #endif ++no_mapping; ! ++allow_keys; /* no mapping for nchar, but allow key codes */ ! /* Don't generate a CursorHold event here, most commands can't handle ! * it, e.g., nv_replace(), nv_csearch(). */ did_cursorhold = TRUE; if (ca.cmdchar == 'g') { --- 821,838 ---- && (oap->op_type != OP_NOP || VIsual_active)))) { int *cp; ! int repl = FALSE; // get character for replace mode ! int lit = FALSE; // get extra character literally ! int langmap_active = FALSE; // using :lmap mappings ! int lang; // getting a text character #ifdef HAVE_INPUT_METHOD ! int save_smd; // saved value of p_smd #endif ++no_mapping; ! ++allow_keys; // no mapping for nchar, but allow key codes ! // Don't generate a CursorHold event here, most commands can't handle ! // it, e.g., nv_replace(), nv_csearch(). did_cursorhold = TRUE; if (ca.cmdchar == 'g') { *************** *** 848,865 **** if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' || ca.nchar == Ctrl_BSL) { ! cp = &ca.extra_char; /* need to get a third character */ if (ca.nchar != 'r') ! lit = TRUE; /* get it literally */ else ! repl = TRUE; /* get it in replace mode */ } else ! cp = NULL; /* no third character needed */ } else { ! if (ca.cmdchar == 'r') /* get it in replace mode */ repl = TRUE; cp = &ca.nchar; } --- 848,865 ---- if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' || ca.nchar == Ctrl_BSL) { ! cp = &ca.extra_char; // need to get a third character if (ca.nchar != 'r') ! lit = TRUE; // get it literally else ! repl = TRUE; // get it in replace mode } else ! cp = NULL; // no third character needed } else { ! if (ca.cmdchar == 'r') // get it in replace mode repl = TRUE; cp = &ca.nchar; } *************** *** 872,885 **** { if (repl) { ! State = REPLACE; /* pretend Replace mode */ #ifdef CURSOR_SHAPE ! ui_cursor_shape(); /* show different cursor shape */ #endif } if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) { ! /* Allow mappings defined with ":lmap". */ --no_mapping; --allow_keys; if (repl) --- 872,885 ---- { if (repl) { ! State = REPLACE; // pretend Replace mode #ifdef CURSOR_SHAPE ! ui_cursor_shape(); // show different cursor shape #endif } if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) { ! // Allow mappings defined with ":lmap". --no_mapping; --allow_keys; if (repl) *************** *** 890,896 **** } #ifdef HAVE_INPUT_METHOD save_smd = p_smd; ! p_smd = FALSE; /* Don't let the IM code show the mode here */ if (lang && curbuf->b_p_iminsert == B_IMODE_IM) im_set_active(TRUE); #endif --- 890,896 ---- } #ifdef HAVE_INPUT_METHOD save_smd = p_smd; ! p_smd = FALSE; // Don't let the IM code show the mode here if (lang && curbuf->b_p_iminsert == B_IMODE_IM) im_set_active(TRUE); #endif *************** *** 899,905 **** if (langmap_active) { ! /* Undo the decrement done above */ ++no_mapping; ++allow_keys; State = NORMAL_BUSY; --- 899,905 ---- if (langmap_active) { ! // Undo the decrement done above ++no_mapping; ++allow_keys; State = NORMAL_BUSY; *************** *** 921,927 **** if (!lit) { #ifdef FEAT_DIGRAPHS ! /* Typing CTRL-K gets a digraph. */ if (*cp == Ctrl_K && ((nv_cmds[idx].cmd_flags & NV_LANG) || cp == &ca.extra_char) --- 921,927 ---- if (!lit) { #ifdef FEAT_DIGRAPHS ! // Typing CTRL-K gets a digraph. if (*cp == Ctrl_K && ((nv_cmds[idx].cmd_flags & NV_LANG) || cp == &ca.extra_char) *************** *** 932,938 **** { *cp = c; # ifdef FEAT_CMDL_INFO ! /* Guessing how to update showcmd here... */ del_from_showcmd(3); need_flushbuf |= add_to_showcmd(*cp); # endif --- 932,938 ---- { *cp = c; # ifdef FEAT_CMDL_INFO ! // Guessing how to update showcmd here... del_from_showcmd(3); need_flushbuf |= add_to_showcmd(*cp); # endif *************** *** 940,949 **** } #endif ! /* adjust chars > 127, except after "tTfFr" commands */ LANGMAP_ADJUST(*cp, !lang); #ifdef FEAT_RIGHTLEFT ! /* adjust Hebrew mapped char */ if (p_hkmap && lang && KeyTyped) *cp = hkmap(*cp); #endif --- 940,949 ---- } #endif ! // adjust chars > 127, except after "tTfFr" commands LANGMAP_ADJUST(*cp, !lang); #ifdef FEAT_RIGHTLEFT ! // adjust Hebrew mapped char if (p_hkmap && lang && KeyTyped) *cp = hkmap(*cp); #endif *************** *** 967,974 **** { long towait = (p_ttm >= 0 ? p_ttm : p_tm); ! /* There is a busy wait here when typing "f" and then ! * something different from CTRL-N. Can't be avoided. */ while ((c = vpeekc()) <= 0 && towait > 0L) { do_sleep(towait > 50L ? 50L : towait); --- 967,974 ---- { long towait = (p_ttm >= 0 ? p_ttm : p_tm); ! // There is a busy wait here when typing "f" and then ! // something different from CTRL-N. Can't be avoided. while ((c = vpeekc()) <= 0 && towait > 0L) { do_sleep(towait > 50L ? 50L : towait); *************** *** 988,998 **** } } ! /* When getting a text character and the next character is a ! * multi-byte character, it could be a composing character. ! * However, don't wait for it to arrive. Also, do enable mapping, ! * because if it's put back with vungetc() it's too late to apply ! * mapping. */ --no_mapping; while (enc_utf8 && lang && (c = vpeekc()) > 0 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) --- 988,998 ---- } } ! // When getting a text character and the next character is a ! // multi-byte character, it could be a composing character. ! // However, don't wait for it to arrive. Also, do enable mapping, ! // because if it's put back with vungetc() it's too late to apply ! // mapping. --no_mapping; while (enc_utf8 && lang && (c = vpeekc()) > 0 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) *************** *** 1000,1006 **** c = plain_vgetc(); if (!utf_iscomposing(c)) { ! vungetc(c); /* it wasn't, put it back */ break; } else if (ca.ncharC1 == 0) --- 1000,1006 ---- c = plain_vgetc(); if (!utf_iscomposing(c)) { ! vungetc(c); // it wasn't, put it back break; } else if (ca.ncharC1 == 0) *************** *** 1039,1052 **** if (ca.cmdchar != K_IGNORE) { ! msg_didout = FALSE; /* don't scroll screen up for normal command */ msg_col = 0; } ! old_pos = curwin->w_cursor; /* remember where cursor was */ ! /* When 'keymodel' contains "startsel" some keys start Select/Visual ! * mode. */ if (!VIsual_active && km_startsel) { if (nv_cmds[idx].cmd_flags & NV_SS) --- 1039,1052 ---- if (ca.cmdchar != K_IGNORE) { ! msg_didout = FALSE; // don't scroll screen up for normal command msg_col = 0; } ! old_pos = curwin->w_cursor; // remember where cursor was ! // When 'keymodel' contains "startsel" some keys start Select/Visual ! // mode. if (!VIsual_active && km_startsel) { if (nv_cmds[idx].cmd_flags & NV_SS) *************** *** 1083,1090 **** { int regname = 0; ! /* Adjust the register according to 'clipboard', so that when ! * "unnamed" is present it becomes '*' or '+' instead of '"'. */ # ifdef FEAT_CLIPBOARD adjust_clip_reg(®name); # endif --- 1083,1090 ---- { int regname = 0; ! // Adjust the register according to 'clipboard', so that when ! // "unnamed" is present it becomes '*' or '+' instead of '"'. # ifdef FEAT_CLIPBOARD adjust_clip_reg(®name); # endif *************** *** 1093,1100 **** #endif } ! /* Get the length of mapped chars again after typing a count, second ! * character or "z333". */ if (old_mapped_len > 0) old_mapped_len = typebuf_maplen(); --- 1093,1100 ---- #endif } ! // Get the length of mapped chars again after typing a count, second ! // character or "z333". if (old_mapped_len > 0) old_mapped_len = typebuf_maplen(); *************** *** 1142,1153 **** { int save_State = State; ! /* Draw the cursor with the right shape here */ if (restart_edit != 0) State = INSERT; ! /* If need to redraw, and there is a "keep_msg", redraw before the ! * delay */ if (must_redraw && keep_msg != NULL && !emsg_on_display) { char_u *kmsg; --- 1142,1153 ---- { int save_State = State; ! // Draw the cursor with the right shape here if (restart_edit != 0) State = INSERT; ! // If need to redraw, and there is a "keep_msg", redraw before the ! // delay if (must_redraw && keep_msg != NULL && !emsg_on_display) { char_u *kmsg; *************** *** 1170,1177 **** cursor_on(); out_flush(); if (msg_scroll || emsg_on_display) ! ui_delay(1003L, TRUE); /* wait at least one second */ ! ui_delay(3003L, FALSE); /* wait up to three seconds */ State = save_State; msg_scroll = FALSE; --- 1170,1177 ---- cursor_on(); out_flush(); if (msg_scroll || emsg_on_display) ! ui_delay(1003L, TRUE); // wait at least one second ! ui_delay(3003L, FALSE); // wait up to three seconds State = save_State; msg_scroll = FALSE; *************** *** 1185,1201 **** msg_nowait = FALSE; ! /* Reset finish_op, in case it was set */ #ifdef CURSOR_SHAPE c = finish_op; #endif finish_op = FALSE; #ifdef CURSOR_SHAPE ! /* Redraw the cursor with another shape, if we were in Operator-pending ! * mode or did a replace command. */ if (c || ca.cmdchar == 'r') { ! ui_cursor_shape(); /* may show different cursor shape */ # ifdef FEAT_MOUSESHAPE update_mouseshape(-1); # endif --- 1185,1201 ---- msg_nowait = FALSE; ! // Reset finish_op, in case it was set #ifdef CURSOR_SHAPE c = finish_op; #endif finish_op = FALSE; #ifdef CURSOR_SHAPE ! // Redraw the cursor with another shape, if we were in Operator-pending ! // mode or did a replace command. if (c || ca.cmdchar == 'r') { ! ui_cursor_shape(); // may show different cursor shape # ifdef FEAT_MOUSESHAPE update_mouseshape(-1); # endif *************** *** 1208,1214 **** clear_showcmd(); #endif ! checkpcmark(); /* check if we moved since setting pcmark */ vim_free(ca.searchbuf); if (has_mbyte) --- 1208,1214 ---- clear_showcmd(); #endif ! checkpcmark(); // check if we moved since setting pcmark vim_free(ca.searchbuf); if (has_mbyte) *************** *** 1216,1233 **** if (curwin->w_p_scb && toplevel) { ! validate_cursor(); /* may need to update w_leftcol */ do_check_scrollbind(TRUE); } if (curwin->w_p_crb && toplevel) { ! validate_cursor(); /* may need to update w_leftcol */ do_check_cursorbind(); } #ifdef FEAT_TERMINAL ! /* don't go to Insert mode if a terminal has a running job */ if (term_job_running(curbuf->b_term)) restart_edit = 0; #endif --- 1216,1233 ---- if (curwin->w_p_scb && toplevel) { ! validate_cursor(); // may need to update w_leftcol do_check_scrollbind(TRUE); } if (curwin->w_p_crb && toplevel) { ! validate_cursor(); // may need to update w_leftcol do_check_cursorbind(); } #ifdef FEAT_TERMINAL ! // don't go to Insert mode if a terminal has a running job if (term_job_running(curbuf->b_term)) restart_edit = 0; #endif *************** *** 1257,1263 **** if (restart_VIsual_select == 2) restart_VIsual_select = 1; ! /* Save count before an operator for next time. */ opcount = ca.opcount; } --- 1257,1263 ---- if (restart_VIsual_select == 2) restart_VIsual_select = 1; ! // Save count before an operator for next time. opcount = ca.opcount; } *************** *** 1271,1281 **** { long count = cap->count0; ! /* multiply with cap->opcount the same way as above */ if (cap->opcount != 0) count = cap->opcount * (count == 0 ? 1 : count); set_vcount(count, count == 0 ? 1 : count, *set_prevcount); ! *set_prevcount = FALSE; /* only set v:prevcount once */ } #endif --- 1271,1281 ---- { long count = cap->count0; ! // multiply with cap->opcount the same way as above if (cap->opcount != 0) count = cap->opcount * (count == 0 ? 1 : count); set_vcount(count, count == 0 ? 1 : count, *set_prevcount); ! *set_prevcount = FALSE; // only set v:prevcount once } #endif *************** *** 1319,1325 **** setmouse(); mouse_dragging = 0; ! /* Save the current VIsual area for '< and '> marks, and "gv" */ curbuf->b_visual.vi_mode = VIsual_mode; curbuf->b_visual.vi_start = VIsual; curbuf->b_visual.vi_end = curwin->w_cursor; --- 1319,1325 ---- setmouse(); mouse_dragging = 0; ! // Save the current VIsual area for '< and '> marks, and "gv" curbuf->b_visual.vi_mode = VIsual_mode; curbuf->b_visual.vi_start = VIsual; curbuf->b_visual.vi_end = curwin->w_cursor; *************** *** 1343,1349 **** if (VIsual_active) { end_visual_mode(); ! redraw_curbuf_later(INVERTED); /* delete the inversion later */ } VIsual_reselect = FALSE; } --- 1343,1349 ---- if (VIsual_active) { end_visual_mode(); ! redraw_curbuf_later(INVERTED); // delete the inversion later } VIsual_reselect = FALSE; } *************** *** 1357,1363 **** if (VIsual_active) { end_visual_mode(); ! redraw_curbuf_later(INVERTED); /* delete the inversion later */ VIsual_reselect = FALSE; } } --- 1357,1363 ---- if (VIsual_active) { end_visual_mode(); ! redraw_curbuf_later(INVERTED); // delete the inversion later VIsual_reselect = FALSE; } } *************** *** 1387,1393 **** int *bnp, int dir) { ! /* Accept everything inside []. */ if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) ++*bnp; if (*bnp > 0) --- 1387,1393 ---- int *bnp, int dir) { ! // Accept everything inside []. if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) ++*bnp; if (*bnp > 0) *************** *** 1397,1407 **** return TRUE; } ! /* skip over "s.var" */ if (*ptr == '.') return TRUE; ! /* two-character item: s->var */ if (ptr[dir == BACKWARD ? 0 : 1] == '>' && ptr[dir == BACKWARD ? -1 : 0] == '-') { --- 1397,1407 ---- return TRUE; } ! // skip over "s.var" if (*ptr == '.') return TRUE; ! // two-character item: s->var if (ptr[dir == BACKWARD ? 0 : 1] == '>' && ptr[dir == BACKWARD ? -1 : 0] == '-') { *************** *** 1499,1505 **** */ if (has_mbyte) { ! /* Remember class of character under cursor. */ if ((find_type & FIND_EVAL) && ptr[col] == ']') this_class = mb_get_class((char_u *)"a"); else --- 1499,1505 ---- */ if (has_mbyte) { ! // Remember class of character under cursor. if ((find_type & FIND_EVAL) && ptr[col] == ']') this_class = mb_get_class((char_u *)"a"); else *************** *** 1624,1630 **** int cmd5) { ResetRedobuff(); ! if (regname != 0) /* yank from specified buffer */ { AppendCharToRedobuff('"'); AppendCharToRedobuff(regname); --- 1624,1630 ---- int cmd5) { ResetRedobuff(); ! if (regname != 0) // yank from specified buffer { AppendCharToRedobuff('"'); AppendCharToRedobuff(regname); *************** *** 1714,1720 **** may_clear_cmdline(void) { if (mode_displayed) ! clear_cmdline = TRUE; /* unshow visual mode later */ #ifdef FEAT_CMDL_INFO else clear_showcmd(); --- 1714,1720 ---- may_clear_cmdline(void) { if (mode_displayed) ! clear_cmdline = TRUE; // unshow visual mode later #ifdef FEAT_CMDL_INFO else clear_showcmd(); *************** *** 1728,1734 **** #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 static char_u showcmd_buf[SHOWCMD_BUFLEN]; ! static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ static int showcmd_is_clear = TRUE; static int showcmd_visual = FALSE; --- 1728,1734 ---- #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 static char_u showcmd_buf[SHOWCMD_BUFLEN]; ! static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; // For push_showcmd() static int showcmd_is_clear = TRUE; static int showcmd_visual = FALSE; *************** *** 1747,1753 **** colnr_T leftcol, rightcol; linenr_T top, bot; ! /* Show the size of the Visual area. */ if (cursor_bot) { top = VIsual.lnum; --- 1747,1753 ---- colnr_T leftcol, rightcol; linenr_T top, bot; ! // Show the size of the Visual area. if (cursor_bot) { top = VIsual.lnum; *************** *** 1759,1765 **** bot = VIsual.lnum; } # ifdef FEAT_FOLDING ! /* Include closed folds as a whole. */ (void)hasFolding(top, &top, NULL); (void)hasFolding(bot, NULL, &bot); # endif --- 1759,1765 ---- bot = VIsual.lnum; } # ifdef FEAT_FOLDING ! // Include closed folds as a whole. (void)hasFolding(top, &top, NULL); (void)hasFolding(bot, NULL, &bot); # endif *************** *** 1771,1777 **** char_u *saved_sbr = p_sbr; char_u *saved_w_sbr = curwin->w_p_sbr; ! /* Make 'sbr' empty for a moment to get the correct size. */ p_sbr = empty_option; curwin->w_p_sbr = empty_option; # endif --- 1771,1777 ---- char_u *saved_sbr = p_sbr; char_u *saved_w_sbr = curwin->w_p_sbr; ! // Make 'sbr' empty for a moment to get the correct size. p_sbr = empty_option; curwin->w_p_sbr = empty_option; # endif *************** *** 1809,1815 **** { ++bytes; ++chars; ! break; /* end of line */ } bytes += l; ++chars; --- 1809,1815 ---- { ++bytes; ++chars; ! break; // end of line } bytes += l; ++chars; *************** *** 1820,1826 **** else sprintf((char *)showcmd_buf, "%d-%d", chars, bytes); } ! showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ showcmd_visual = TRUE; } else --- 1820,1826 ---- else sprintf((char *)showcmd_buf, "%d-%d", chars, bytes); } ! showcmd_buf[SHOWCMD_COLS] = NUL; // truncate showcmd_visual = TRUE; } else *************** *** 1828,1834 **** showcmd_buf[0] = NUL; showcmd_visual = FALSE; ! /* Don't actually display something if there is nothing to clear. */ if (showcmd_is_clear) return; } --- 1828,1834 ---- showcmd_buf[0] = NUL; showcmd_visual = FALSE; ! // Don't actually display something if there is nothing to clear. if (showcmd_is_clear) return; } *************** *** 1873,1879 **** showcmd_visual = FALSE; } ! /* Ignore keys that are scrollbar updates and mouse clicks */ if (IS_SPECIAL(c)) for (i = 0; ignore[i] != 0; ++i) if (ignore[i] == c) --- 1873,1879 ---- showcmd_visual = FALSE; } ! // Ignore keys that are scrollbar updates and mouse clicks if (IS_SPECIAL(c)) for (i = 0; ignore[i] != 0; ++i) if (ignore[i] == c) *************** *** 1969,1975 **** */ screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); ! setcursor(); /* put cursor back where it belongs */ } #endif --- 1969,1975 ---- */ screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); ! setcursor(); // put cursor back where it belongs } #endif *************** *** 1991,1998 **** if (check && curwin->w_p_scb) { ! /* If a ":syncbind" command was just used, don't scroll, only reset ! * the values. */ if (did_syncbind) did_syncbind = FALSE; else if (curwin == old_curwin) --- 1991,1998 ---- if (check && curwin->w_p_scb) { ! // If a ":syncbind" command was just used, don't scroll, only reset ! // the values. if (did_syncbind) did_syncbind = FALSE; else if (curwin == old_curwin) *************** *** 2017,2023 **** (long)(curwin->w_leftcol - old_leftcol)); } } ! else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ { /* * When switching between windows, make sure that the relative --- 2017,2023 ---- (long)(curwin->w_leftcol - old_leftcol)); } } ! else if (vim_strchr(p_sbo, 'j')) // jump flag set in 'scrollopt' { /* * When switching between windows, make sure that the relative *************** *** 2077,2083 **** FOR_ALL_WINDOWS(curwin) { curbuf = curwin->w_buffer; ! /* skip original window and windows with 'noscrollbind' */ if (curwin != old_curwin && curwin->w_p_scb) { /* --- 2077,2083 ---- FOR_ALL_WINDOWS(curwin) { curbuf = curwin->w_buffer; ! // skip original window and windows with 'noscrollbind' if (curwin != old_curwin && curwin->w_p_scb) { /* *************** *** 2140,2146 **** static void nv_ignore(cmdarg_T *cap) { ! cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ } /* --- 2140,2146 ---- static void nv_ignore(cmdarg_T *cap) { ! cap->retval |= CA_COMMAND_BUSY; // don't call edit() now } /* *************** *** 2205,2211 **** { if (mod_mask & MOD_MASK_CTRL) { ! /* : tab page back; : tab page forward */ if (cap->arg == BACKWARD) goto_tabpage(-(int)cap->count1); else --- 2205,2211 ---- { if (mod_mask & MOD_MASK_CTRL) { ! // : tab page back; : tab page forward if (cap->arg == BACKWARD) goto_tabpage(-(int)cap->count1); else *************** *** 2223,2229 **** nv_gd( oparg_T *oap, int nchar, ! int thisblock) /* 1 for "1gd" and "1gD" */ { int len; char_u *ptr; --- 2223,2229 ---- nv_gd( oparg_T *oap, int nchar, ! int thisblock) // 1 for "1gd" and "1gD" { int len; char_u *ptr; *************** *** 2297,2303 **** int len, int locally, int thisblock, ! int flags_arg) /* flags passed to searchit() */ { char_u *pat; pos_T old_pos; --- 2297,2303 ---- int len, int locally, int thisblock, ! int flags_arg) // flags passed to searchit() { char_u *pat; pos_T old_pos; *************** *** 2314,2328 **** if ((pat = alloc(len + 7)) == NULL) return FAIL; ! /* Put "\V" before the pattern to avoid that the special meaning of "." ! * and "~" causes trouble. */ sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", len, ptr); old_pos = curwin->w_cursor; save_p_ws = p_ws; save_p_scs = p_scs; ! p_ws = FALSE; /* don't wrap around end of file now */ ! p_scs = FALSE; /* don't switch ignorecase off now */ /* * With "gD" go to line 1. --- 2314,2328 ---- if ((pat = alloc(len + 7)) == NULL) return FAIL; ! // Put "\V" before the pattern to avoid that the special meaning of "." ! // and "~" causes trouble. sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", len, ptr); old_pos = curwin->w_cursor; save_p_ws = p_ws; save_p_scs = p_scs; ! p_ws = FALSE; // don't wrap around end of file now ! p_scs = FALSE; // don't switch ignorecase off now /* * With "gD" go to line 1. *************** *** 2331,2337 **** */ if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) { ! setpcmark(); /* Set in findpar() otherwise */ curwin->w_cursor.lnum = 1; par_pos = curwin->w_cursor; } --- 2331,2337 ---- */ if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) { ! setpcmark(); // Set in findpar() otherwise curwin->w_cursor.lnum = 1; par_pos = curwin->w_cursor; } *************** *** 2343,2369 **** } curwin->w_cursor.col = 0; ! /* Search forward for the identifier, ignore comment lines. */ CLEAR_POS(&found_pos); for (;;) { t = searchit(curwin, curbuf, &curwin->w_cursor, NULL, FORWARD, pat, 1L, searchflags, RE_LAST, NULL); if (curwin->w_cursor.lnum >= old_pos.lnum) ! t = FAIL; /* match after start is failure too */ if (thisblock && t != FAIL) { pos_T *pos; ! /* Check that the block the match is in doesn't end before the ! * position where we started the search from. */ if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL && pos->lnum < old_pos.lnum) { ! /* There can't be a useful match before the end of this block. ! * Skip to the end. */ curwin->w_cursor = *pos; continue; } --- 2343,2369 ---- } curwin->w_cursor.col = 0; ! // Search forward for the identifier, ignore comment lines. CLEAR_POS(&found_pos); for (;;) { t = searchit(curwin, curbuf, &curwin->w_cursor, NULL, FORWARD, pat, 1L, searchflags, RE_LAST, NULL); if (curwin->w_cursor.lnum >= old_pos.lnum) ! t = FAIL; // match after start is failure too if (thisblock && t != FAIL) { pos_T *pos; ! // Check that the block the match is in doesn't end before the ! // position where we started the search from. if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL && pos->lnum < old_pos.lnum) { ! // There can't be a useful match before the end of this block. ! // Skip to the end. curwin->w_cursor = *pos; continue; } *************** *** 2371,2377 **** if (t == FAIL) { ! /* If we previously found a valid position, use it. */ if (found_pos.lnum != 0) { curwin->w_cursor = found_pos; --- 2371,2377 ---- if (t == FAIL) { ! // If we previously found a valid position, use it. if (found_pos.lnum != 0) { curwin->w_cursor = found_pos; *************** *** 2381,2421 **** } if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) { ! /* Ignore this line, continue at start of next line. */ ++curwin->w_cursor.lnum; curwin->w_cursor.col = 0; continue; } valid = is_ident(ml_get_curline(), curwin->w_cursor.col); ! /* If the current position is not a valid identifier and a previous ! * match is present, favor that one instead. */ if (!valid && found_pos.lnum != 0) { curwin->w_cursor = found_pos; break; } ! /* Global search: use first valid match found */ if (valid && !locally) break; if (valid && curwin->w_cursor.lnum >= par_pos.lnum) { ! /* If we previously found a valid position, use it. */ if (found_pos.lnum != 0) curwin->w_cursor = found_pos; break; } ! /* For finding a local variable and the match is before the "{" or ! * inside a comment, continue searching. For K&R style function ! * declarations this skips the function header without types. */ if (!valid) CLEAR_POS(&found_pos); else found_pos = curwin->w_cursor; ! /* Remove SEARCH_START from flags to avoid getting stuck at one ! * position. */ searchflags &= ~SEARCH_START; } --- 2381,2421 ---- } if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) { ! // Ignore this line, continue at start of next line. ++curwin->w_cursor.lnum; curwin->w_cursor.col = 0; continue; } valid = is_ident(ml_get_curline(), curwin->w_cursor.col); ! // If the current position is not a valid identifier and a previous ! // match is present, favor that one instead. if (!valid && found_pos.lnum != 0) { curwin->w_cursor = found_pos; break; } ! // Global search: use first valid match found if (valid && !locally) break; if (valid && curwin->w_cursor.lnum >= par_pos.lnum) { ! // If we previously found a valid position, use it. if (found_pos.lnum != 0) curwin->w_cursor = found_pos; break; } ! // For finding a local variable and the match is before the "{" or ! // inside a comment, continue searching. For K&R style function ! // declarations this skips the function header without types. if (!valid) CLEAR_POS(&found_pos); else found_pos = curwin->w_cursor; ! // Remove SEARCH_START from flags to avoid getting stuck at one ! // position. searchflags &= ~SEARCH_START; } *************** *** 2427,2433 **** else { curwin->w_set_curswant = TRUE; ! /* "n" searches forward now */ reset_search_dir(); } --- 2427,2433 ---- else { curwin->w_set_curswant = TRUE; ! // "n" searches forward now reset_search_dir(); } *************** *** 2452,2461 **** int retval = OK; int atend = FALSE; int n; ! int col_off1; /* margin offset for first screen line */ ! int col_off2; /* margin offset for wrapped screen line */ ! int width1; /* text width for first screen line */ ! int width2; /* test width for wrapped screen line */ oap->motion_type = MCHAR; oap->inclusive = (curwin->w_curswant == MAXCOL); --- 2452,2461 ---- int retval = OK; int atend = FALSE; int n; ! int col_off1; // margin offset for first screen line ! int col_off2; // margin offset for wrapped screen line ! int width1; // text width for first screen line ! int width2; // test width for wrapped screen line oap->motion_type = MCHAR; oap->inclusive = (curwin->w_curswant == MAXCOL); *************** *** 2465,2471 **** width1 = curwin->w_width - col_off1; width2 = curwin->w_width - col_off2; if (width2 == 0) ! width2 = 1; /* avoid divide by zero */ if (curwin->w_width != 0) { --- 2465,2471 ---- width1 = curwin->w_width - col_off1; width2 = curwin->w_width - col_off2; if (width2 == 0) ! width2 = 1; // avoid divide by zero if (curwin->w_width != 0) { *************** *** 2508,2514 **** curwin->w_curswant -= width2; else { ! /* to previous line */ if (curwin->w_cursor.lnum == 1) { retval = FAIL; --- 2508,2514 ---- curwin->w_curswant -= width2; else { ! // to previous line if (curwin->w_cursor.lnum == 1) { retval = FAIL; *************** *** 2516,2523 **** } --curwin->w_cursor.lnum; #ifdef FEAT_FOLDING ! /* Move to the start of a closed fold. Don't do that when ! * 'foldopen' contains "all": it will open in a moment. */ if (!(fdo_flags & FDO_ALL)) (void)hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL); --- 2516,2523 ---- } --curwin->w_cursor.lnum; #ifdef FEAT_FOLDING ! // Move to the start of a closed fold. Don't do that when ! // 'foldopen' contains "all": it will open in a moment. if (!(fdo_flags & FDO_ALL)) (void)hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL); *************** *** 2528,2547 **** + 1) * width2; } } ! else /* dir == FORWARD */ { if (linelen > width1) n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; else n = width1; if (curwin->w_curswant + width2 < (colnr_T)n) ! /* move forward within line */ curwin->w_curswant += width2; else { ! /* to next line */ #ifdef FEAT_FOLDING ! /* Move to the end of a closed fold. */ (void)hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum); #endif --- 2528,2547 ---- + 1) * width2; } } ! else // dir == FORWARD { if (linelen > width1) n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; else n = width1; if (curwin->w_curswant + width2 < (colnr_T)n) ! // move forward within line curwin->w_curswant += width2; else { ! // to next line #ifdef FEAT_FOLDING ! // Move to the end of a closed fold. (void)hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum); #endif *************** *** 2594,2600 **** } if (atend) ! curwin->w_curswant = MAXCOL; /* stick in the last column */ return retval; } --- 2594,2600 ---- } if (atend) ! curwin->w_curswant = MAXCOL; // stick in the last column return retval; } *************** *** 2628,2642 **** scrolldown(count, TRUE); if (get_scrolloff_value()) { ! /* Adjust the cursor position for 'scrolloff'. Mark w_topline as ! * valid, otherwise the screen jumps back at the end of the file. */ cursor_correct(); check_cursor_moved(curwin); curwin->w_valid |= VALID_TOPLINE; ! /* If moved back to where we were, at least move the cursor, otherwise ! * we get stuck at one position. Don't move the cursor up if the ! * first line of the buffer is already on the screen */ while (curwin->w_topline == prev_topline #ifdef FEAT_DIFF && curwin->w_topfill == prev_topfill --- 2628,2642 ---- scrolldown(count, TRUE); if (get_scrolloff_value()) { ! // Adjust the cursor position for 'scrolloff'. Mark w_topline as ! // valid, otherwise the screen jumps back at the end of the file. cursor_correct(); check_cursor_moved(curwin); curwin->w_valid |= VALID_TOPLINE; ! // If moved back to where we were, at least move the cursor, otherwise ! // we get stuck at one position. Don't move the cursor up if the ! // first line of the buffer is already on the screen while (curwin->w_topline == prev_topline #ifdef FEAT_DIFF && curwin->w_topfill == prev_topfill *************** *** 2656,2663 **** || cursor_up(1L, FALSE) == FAIL) break; } ! /* Mark w_topline as valid, otherwise the screen jumps back at the ! * end of the file. */ check_cursor_moved(curwin); curwin->w_valid |= VALID_TOPLINE; } --- 2656,2663 ---- || cursor_up(1L, FALSE) == FAIL) break; } ! // Mark w_topline as valid, otherwise the screen jumps back at the ! // end of the file. check_cursor_moved(curwin); curwin->w_valid |= VALID_TOPLINE; } *************** *** 2696,2705 **** for (;;) { #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; /* disallow scrolling here */ #endif ++no_mapping; ! ++allow_keys; /* no mapping for nchar, but allow key codes */ nchar = plain_vgetc(); LANGMAP_ADJUST(nchar, TRUE); --no_mapping; --- 2696,2705 ---- for (;;) { #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; // disallow scrolling here #endif ++no_mapping; ! ++allow_keys; // no mapping for nchar, but allow key codes nchar = plain_vgetc(); LANGMAP_ADJUST(nchar, TRUE); --no_mapping; *************** *** 2740,2748 **** dozet: if ( #ifdef FEAT_FOLDING ! /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" ! * and "zC" only in Visual mode. "zj" and "zk" are motion ! * commands. */ cap->nchar != 'f' && cap->nchar != 'F' && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) && cap->nchar != 'j' && cap->nchar != 'k' --- 2740,2748 ---- dozet: if ( #ifdef FEAT_FOLDING ! // "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" ! // and "zC" only in Visual mode. "zj" and "zk" are motion ! // commands. cap->nchar != 'f' && cap->nchar != 'F' && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) && cap->nchar != 'j' && cap->nchar != 'k' *************** *** 2769,2810 **** switch (nchar) { ! /* "z+", "z" and "zt": put cursor at top of screen */ case '+': if (cap->count0 == 0) { ! /* No count given: put cursor at the line below screen */ ! validate_botline(); /* make sure w_botline is valid */ if (curwin->w_botline > curbuf->b_ml.ml_line_count) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; else curwin->w_cursor.lnum = curwin->w_botline; } ! /* FALLTHROUGH */ case NL: case CAR: case K_KENTER: beginline(BL_WHITE | BL_FIX); ! /* FALLTHROUGH */ case 't': scroll_cursor_top(0, TRUE); redraw_later(VALID); set_fraction(curwin); break; ! /* "z." and "zz": put cursor in middle of screen */ case '.': beginline(BL_WHITE | BL_FIX); ! /* FALLTHROUGH */ case 'z': scroll_cursor_halfway(TRUE); redraw_later(VALID); set_fraction(curwin); break; ! /* "z^", "z-" and "zb": put cursor at bottom of screen */ ! case '^': /* Strange Vi behavior: z^ finds line at top of window ! * when is at bottom of window, and puts that one at ! * bottom of window. */ if (cap->count0 != 0) { scroll_cursor_bot(0, TRUE); --- 2769,2810 ---- switch (nchar) { ! // "z+", "z" and "zt": put cursor at top of screen case '+': if (cap->count0 == 0) { ! // No count given: put cursor at the line below screen ! validate_botline(); // make sure w_botline is valid if (curwin->w_botline > curbuf->b_ml.ml_line_count) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; else curwin->w_cursor.lnum = curwin->w_botline; } ! // FALLTHROUGH case NL: case CAR: case K_KENTER: beginline(BL_WHITE | BL_FIX); ! // FALLTHROUGH case 't': scroll_cursor_top(0, TRUE); redraw_later(VALID); set_fraction(curwin); break; ! // "z." and "zz": put cursor in middle of screen case '.': beginline(BL_WHITE | BL_FIX); ! // FALLTHROUGH case 'z': scroll_cursor_halfway(TRUE); redraw_later(VALID); set_fraction(curwin); break; ! // "z^", "z-" and "zb": put cursor at bottom of screen ! case '^': // Strange Vi behavior: z^ finds line at top of window ! // when is at bottom of window, and puts that one at ! // bottom of window. if (cap->count0 != 0) { scroll_cursor_bot(0, TRUE); *************** *** 2814,2835 **** curwin->w_cursor.lnum = 1; else curwin->w_cursor.lnum = curwin->w_topline - 1; ! /* FALLTHROUGH */ case '-': beginline(BL_WHITE | BL_FIX); ! /* FALLTHROUGH */ case 'b': scroll_cursor_bot(0, TRUE); redraw_later(VALID); set_fraction(curwin); break; ! /* "zH" - scroll screen right half-page */ case 'H': cap->count1 *= curwin->w_width / 2; ! /* FALLTHROUGH */ ! /* "zh" - scroll screen to the right */ case 'h': case K_LEFT: if (!curwin->w_p_wrap) --- 2814,2835 ---- curwin->w_cursor.lnum = 1; else curwin->w_cursor.lnum = curwin->w_topline - 1; ! // FALLTHROUGH case '-': beginline(BL_WHITE | BL_FIX); ! // FALLTHROUGH case 'b': scroll_cursor_bot(0, TRUE); redraw_later(VALID); set_fraction(curwin); break; ! // "zH" - scroll screen right half-page case 'H': cap->count1 *= curwin->w_width / 2; ! // FALLTHROUGH ! // "zh" - scroll screen to the right case 'h': case K_LEFT: if (!curwin->w_p_wrap) *************** *** 2842,2868 **** } break; ! /* "zL" - scroll screen left half-page */ case 'L': cap->count1 *= curwin->w_width / 2; ! /* FALLTHROUGH */ ! /* "zl" - scroll screen to the left */ case 'l': case K_RIGHT: if (!curwin->w_p_wrap) { ! /* scroll the window left */ curwin->w_leftcol += (colnr_T)cap->count1; leftcol_changed(); } break; ! /* "zs" - scroll screen, cursor at the start */ case 's': if (!curwin->w_p_wrap) { #ifdef FEAT_FOLDING if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) ! col = 0; /* like the cursor is in col 0 */ else #endif getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); --- 2842,2868 ---- } break; ! // "zL" - scroll screen left half-page case 'L': cap->count1 *= curwin->w_width / 2; ! // FALLTHROUGH ! // "zl" - scroll screen to the left case 'l': case K_RIGHT: if (!curwin->w_p_wrap) { ! // scroll the window left curwin->w_leftcol += (colnr_T)cap->count1; leftcol_changed(); } break; ! // "zs" - scroll screen, cursor at the start case 's': if (!curwin->w_p_wrap) { #ifdef FEAT_FOLDING if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) ! col = 0; // like the cursor is in col 0 else #endif getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); *************** *** 2878,2889 **** } break; ! /* "ze" - scroll screen, cursor at the end */ case 'e': if (!curwin->w_p_wrap) { #ifdef FEAT_FOLDING if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) ! col = 0; /* like the cursor is in col 0 */ else #endif getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); --- 2878,2889 ---- } break; ! // "ze" - scroll screen, cursor at the end case 'e': if (!curwin->w_p_wrap) { #ifdef FEAT_FOLDING if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) ! col = 0; // like the cursor is in col 0 else #endif getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); *************** *** 2901,2908 **** break; #ifdef FEAT_FOLDING ! /* "zF": create fold command */ ! /* "zf": create fold operator */ case 'F': case 'f': if (foldManualAllowed(TRUE)) { --- 2901,2908 ---- break; #ifdef FEAT_FOLDING ! // "zF": create fold command ! // "zf": create fold operator case 'F': case 'f': if (foldManualAllowed(TRUE)) { *************** *** 2910,2916 **** nv_operator(cap); curwin->w_p_fen = TRUE; ! /* "zF" is like "zfzf" */ if (nchar == 'F' && cap->oap->op_type == OP_FOLD) { nv_operator(cap); --- 2910,2916 ---- nv_operator(cap); curwin->w_p_fen = TRUE; ! // "zF" is like "zfzf" if (nchar == 'F' && cap->oap->op_type == OP_FOLD) { nv_operator(cap); *************** *** 2921,2928 **** clearopbeep(cap->oap); break; ! /* "zd": delete fold at cursor */ ! /* "zD": delete fold at cursor recursively */ case 'd': case 'D': if (foldManualAllowed(FALSE)) { --- 2921,2928 ---- clearopbeep(cap->oap); break; ! // "zd": delete fold at cursor ! // "zD": delete fold at cursor recursively case 'd': case 'D': if (foldManualAllowed(FALSE)) { *************** *** 2934,2940 **** } break; ! /* "zE": erase all folds */ case 'E': if (foldmethodIsManual(curwin)) { clearFolding(curwin); --- 2934,2940 ---- } break; ! // "zE": erase all folds case 'E': if (foldmethodIsManual(curwin)) { clearFolding(curwin); *************** *** 2947,2965 **** emsg(_("E352: Cannot erase folds with current 'foldmethod'")); break; ! /* "zn": fold none: reset 'foldenable' */ case 'n': curwin->w_p_fen = FALSE; break; ! /* "zN": fold Normal: set 'foldenable' */ case 'N': curwin->w_p_fen = TRUE; break; ! /* "zi": invert folding: toggle 'foldenable' */ case 'i': curwin->w_p_fen = !curwin->w_p_fen; break; ! /* "za": open closed fold or close open fold at cursor */ case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) openFold(curwin->w_cursor.lnum, cap->count1); else --- 2947,2965 ---- emsg(_("E352: Cannot erase folds with current 'foldmethod'")); break; ! // "zn": fold none: reset 'foldenable' case 'n': curwin->w_p_fen = FALSE; break; ! // "zN": fold Normal: set 'foldenable' case 'N': curwin->w_p_fen = TRUE; break; ! // "zi": invert folding: toggle 'foldenable' case 'i': curwin->w_p_fen = !curwin->w_p_fen; break; ! // "za": open closed fold or close open fold at cursor case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) openFold(curwin->w_cursor.lnum, cap->count1); else *************** *** 2969,2975 **** } break; ! /* "zA": open fold at cursor recursively */ case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) openFoldRecurse(curwin->w_cursor.lnum); else --- 2969,2975 ---- } break; ! // "zA": open fold at cursor recursively case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) openFoldRecurse(curwin->w_cursor.lnum); else *************** *** 2979,2999 **** } break; ! /* "zo": open fold at cursor or Visual area */ case 'o': if (VIsual_active) nv_operator(cap); else openFold(curwin->w_cursor.lnum, cap->count1); break; ! /* "zO": open fold recursively */ case 'O': if (VIsual_active) nv_operator(cap); else openFoldRecurse(curwin->w_cursor.lnum); break; ! /* "zc": close fold at cursor or Visual area */ case 'c': if (VIsual_active) nv_operator(cap); else --- 2979,2999 ---- } break; ! // "zo": open fold at cursor or Visual area case 'o': if (VIsual_active) nv_operator(cap); else openFold(curwin->w_cursor.lnum, cap->count1); break; ! // "zO": open fold recursively case 'O': if (VIsual_active) nv_operator(cap); else openFoldRecurse(curwin->w_cursor.lnum); break; ! // "zc": close fold at cursor or Visual area case 'c': if (VIsual_active) nv_operator(cap); else *************** *** 3001,3007 **** curwin->w_p_fen = TRUE; break; ! /* "zC": close fold recursively */ case 'C': if (VIsual_active) nv_operator(cap); else --- 3001,3007 ---- curwin->w_p_fen = TRUE; break; ! // "zC": close fold recursively case 'C': if (VIsual_active) nv_operator(cap); else *************** *** 3009,3049 **** curwin->w_p_fen = TRUE; break; ! /* "zv": open folds at the cursor */ case 'v': foldOpenCursor(); break; ! /* "zx": re-apply 'foldlevel' and open folds at the cursor */ case 'x': curwin->w_p_fen = TRUE; ! curwin->w_foldinvalid = TRUE; /* recompute folds */ ! newFoldLevel(); /* update right now */ foldOpenCursor(); break; ! /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ case 'X': curwin->w_p_fen = TRUE; ! curwin->w_foldinvalid = TRUE; /* recompute folds */ ! old_fdl = -1; /* force an update */ break; ! /* "zm": fold more */ case 'm': if (curwin->w_p_fdl > 0) { curwin->w_p_fdl -= cap->count1; if (curwin->w_p_fdl < 0) curwin->w_p_fdl = 0; } ! old_fdl = -1; /* force an update */ curwin->w_p_fen = TRUE; break; ! /* "zM": close all folds */ case 'M': curwin->w_p_fdl = 0; ! old_fdl = -1; /* force an update */ curwin->w_p_fen = TRUE; break; ! /* "zr": reduce folding */ case 'r': curwin->w_p_fdl += cap->count1; { int d = getDeepestNesting(); --- 3009,3049 ---- curwin->w_p_fen = TRUE; break; ! // "zv": open folds at the cursor case 'v': foldOpenCursor(); break; ! // "zx": re-apply 'foldlevel' and open folds at the cursor case 'x': curwin->w_p_fen = TRUE; ! curwin->w_foldinvalid = TRUE; // recompute folds ! newFoldLevel(); // update right now foldOpenCursor(); break; ! // "zX": undo manual opens/closes, re-apply 'foldlevel' case 'X': curwin->w_p_fen = TRUE; ! curwin->w_foldinvalid = TRUE; // recompute folds ! old_fdl = -1; // force an update break; ! // "zm": fold more case 'm': if (curwin->w_p_fdl > 0) { curwin->w_p_fdl -= cap->count1; if (curwin->w_p_fdl < 0) curwin->w_p_fdl = 0; } ! old_fdl = -1; // force an update curwin->w_p_fen = TRUE; break; ! // "zM": close all folds case 'M': curwin->w_p_fdl = 0; ! old_fdl = -1; // force an update curwin->w_p_fen = TRUE; break; ! // "zr": reduce folding case 'r': curwin->w_p_fdl += cap->count1; { int d = getDeepestNesting(); *************** *** 3053,3076 **** } break; ! /* "zR": open all folds */ case 'R': curwin->w_p_fdl = getDeepestNesting(); ! old_fdl = -1; /* force an update */ break; ! case 'j': /* "zj" move to next fold downwards */ ! case 'k': /* "zk" move to next fold upwards */ if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, cap->count1) == FAIL) clearopbeep(cap->oap); break; ! #endif /* FEAT_FOLDING */ #ifdef FEAT_SPELL ! case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ ++no_mapping; ! ++allow_keys; /* no mapping for nchar, but allow key codes */ nchar = plain_vgetc(); LANGMAP_ADJUST(nchar, TRUE); --no_mapping; --- 3053,3076 ---- } break; ! // "zR": open all folds case 'R': curwin->w_p_fdl = getDeepestNesting(); ! old_fdl = -1; // force an update break; ! case 'j': // "zj" move to next fold downwards ! case 'k': // "zk" move to next fold upwards if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, cap->count1) == FAIL) clearopbeep(cap->oap); break; ! #endif // FEAT_FOLDING #ifdef FEAT_SPELL ! case 'u': // "zug" and "zuw": undo "zg" and "zw" ++no_mapping; ! ++allow_keys; // no mapping for nchar, but allow key codes nchar = plain_vgetc(); LANGMAP_ADJUST(nchar, TRUE); --no_mapping; *************** *** 3084,3095 **** break; } undo = TRUE; ! /* FALLTHROUGH */ ! case 'g': /* "zg": add good word to word list */ ! case 'w': /* "zw": add wrong word to word list */ ! case 'G': /* "zG": add good word to temp word list */ ! case 'W': /* "zW": add wrong word to temp word list */ { char_u *ptr = NULL; int len; --- 3084,3095 ---- break; } undo = TRUE; ! // FALLTHROUGH ! case 'g': // "zg": add good word to word list ! case 'w': // "zw": add wrong word to word list ! case 'G': // "zG": add good word to temp word list ! case 'W': // "zW": add wrong word to temp word list { char_u *ptr = NULL; int len; *************** *** 3103,3111 **** { pos_T pos = curwin->w_cursor; ! /* Find bad word under the cursor. When 'spell' is ! * off this fails and find_ident_under_cursor() is ! * used below. */ emsg_off++; len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); emsg_off--; --- 3103,3111 ---- { pos_T pos = curwin->w_cursor; ! // Find bad word under the cursor. When 'spell' is ! // off this fails and find_ident_under_cursor() is ! // used below. emsg_off++; len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); emsg_off--; *************** *** 3125,3131 **** } break; ! case '=': /* "z=": suggestions for a badly spelled word */ if (!checkclearop(cap->oap)) spell_suggest((int)cap->count0); break; --- 3125,3131 ---- } break; ! case '=': // "z=": suggestions for a badly spelled word if (!checkclearop(cap->oap)) spell_suggest((int)cap->count0); break; *************** *** 3135,3141 **** } #ifdef FEAT_FOLDING ! /* Redraw when 'foldenable' changed */ if (old_fen != curwin->w_p_fen) { # ifdef FEAT_DIFF --- 3135,3141 ---- } #ifdef FEAT_FOLDING ! // Redraw when 'foldenable' changed if (old_fen != curwin->w_p_fen) { # ifdef FEAT_DIFF *************** *** 3143,3149 **** if (foldmethodIsDiff(curwin) && curwin->w_p_scb) { ! /* Adjust 'foldenable' in diff-synced windows. */ FOR_ALL_WINDOWS(wp) { if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) --- 3143,3149 ---- if (foldmethodIsDiff(curwin) && curwin->w_p_scb) { ! // Adjust 'foldenable' in diff-synced windows. FOR_ALL_WINDOWS(wp) { if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) *************** *** 3157,3163 **** changed_window_setting(); } ! /* Redraw when 'foldlevel' changed. */ if (old_fdl != curwin->w_p_fdl) newFoldLevel(); #endif --- 3157,3163 ---- changed_window_setting(); } ! // Redraw when 'foldlevel' changed. if (old_fdl != curwin->w_p_fdl) newFoldLevel(); #endif *************** *** 3173,3179 **** if (cap->oap->op_type != OP_NOP) clearopbeep(cap->oap); ! /* Even if an operator was pending, we still want to scroll */ gui_do_scroll(); } --- 3173,3179 ---- if (cap->oap->op_type != OP_NOP) clearopbeep(cap->oap); ! // Even if an operator was pending, we still want to scroll gui_do_scroll(); } *************** *** 3186,3192 **** if (cap->oap->op_type != OP_NOP) clearopbeep(cap->oap); ! /* Even if an operator was pending, we still want to scroll */ gui_do_horiz_scroll(scrollbar_value, FALSE); } #endif --- 3186,3192 ---- if (cap->oap->op_type != OP_NOP) clearopbeep(cap->oap); ! // Even if an operator was pending, we still want to scroll gui_do_horiz_scroll(scrollbar_value, FALSE); } #endif *************** *** 3201,3207 **** if (cap->oap->op_type != OP_NOP) clearopbeep(cap->oap); ! /* Even if an operator was pending, we still want to jump tabs. */ goto_tabpage(current_tab); } --- 3201,3207 ---- if (cap->oap->op_type != OP_NOP) clearopbeep(cap->oap); ! // Even if an operator was pending, we still want to jump tabs. goto_tabpage(current_tab); } *************** *** 3214,3220 **** if (cap->oap->op_type != OP_NOP) clearopbeep(cap->oap); ! /* Even if an operator was pending, we still want to jump tabs. */ handle_tabmenu(); } --- 3214,3220 ---- if (cap->oap->op_type != OP_NOP) clearopbeep(cap->oap); ! // Even if an operator was pending, we still want to jump tabs. handle_tabmenu(); } *************** *** 3293,3305 **** { if (cap->oap->op_type != OP_NOP) { ! /* Using ":" as a movement is characterwise exclusive. */ cap->oap->motion_type = MCHAR; cap->oap->inclusive = FALSE; } else if (cap->count0) { ! /* translate "count:" into ":.,.+(count - 1)" */ stuffcharReadbuff('.'); if (cap->count0 > 1) { --- 3293,3305 ---- { if (cap->oap->op_type != OP_NOP) { ! // Using ":" as a movement is characterwise exclusive. cap->oap->motion_type = MCHAR; cap->oap->inclusive = FALSE; } else if (cap->count0) { ! // translate "count:" into ":.,.+(count - 1)" stuffcharReadbuff('.'); if (cap->count0 > 1) { *************** *** 3308,3324 **** } } ! /* When typing, don't type below an old message */ if (KeyTyped) compute_cmdrow(); old_p_im = p_im; ! /* get a command line and execute it */ cmd_result = do_cmdline(NULL, getexline, NULL, cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); ! /* If 'insertmode' changed, enter or exit Insert mode */ if (p_im != old_p_im) { if (p_im) --- 3308,3324 ---- } } ! // When typing, don't type below an old message if (KeyTyped) compute_cmdrow(); old_p_im = p_im; ! // get a command line and execute it cmd_result = do_cmdline(NULL, getexline, NULL, cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); ! // If 'insertmode' changed, enter or exit Insert mode if (p_im != old_p_im) { if (p_im) *************** *** 3328,3334 **** } if (cmd_result == FAIL) ! /* The Ex command failed, do not execute the operator. */ clearop(cap->oap); else if (cap->oap->op_type != OP_NOP && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count --- 3328,3334 ---- } if (cmd_result == FAIL) ! // The Ex command failed, do not execute the operator. clearop(cap->oap); else if (cap->oap->op_type != OP_NOP && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count *************** *** 3336,3343 **** (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) || did_emsg )) ! /* The start of the operator has become invalid by the Ex command. ! */ clearopbeep(cap->oap); } } --- 3336,3342 ---- (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) || did_emsg )) ! // The start of the operator has become invalid by the Ex command. clearopbeep(cap->oap); } } *************** *** 3348,3360 **** static void nv_ctrlg(cmdarg_T *cap) { ! if (VIsual_active) /* toggle Selection/Visual mode */ { VIsual_select = !VIsual_select; showmode(); } else if (!checkclearop(cap->oap)) ! /* print full name if count given or :cd used */ fileinfo((int)cap->count0, FALSE, TRUE); } --- 3347,3359 ---- static void nv_ctrlg(cmdarg_T *cap) { ! if (VIsual_active) // toggle Selection/Visual mode { VIsual_select = !VIsual_select; showmode(); } else if (!checkclearop(cap->oap)) ! // print full name if count given or :cd used fileinfo((int)cap->count0, FALSE, TRUE); } *************** *** 3366,3372 **** { if (VIsual_active && VIsual_select) { ! cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ v_visop(cap); } else --- 3365,3371 ---- { if (VIsual_active && VIsual_select) { ! cap->cmdchar = 'x'; // BS key behaves like 'x' in Select mode v_visop(cap); } else *************** *** 3390,3396 **** ui_get_shellsize(); #endif #ifdef FEAT_SYN_HL ! /* Clear all syntax states to force resyncing. */ syn_stack_free_all(curwin->w_s); # ifdef FEAT_RELTIME { --- 3389,3395 ---- ui_get_shellsize(); #endif #ifdef FEAT_SYN_HL ! // Clear all syntax states to force resyncing. syn_stack_free_all(curwin->w_s); # ifdef FEAT_RELTIME { *************** *** 3422,3428 **** { VIsual_select = FALSE; showmode(); ! restart_VIsual_select = 2; /* restart Select mode later */ } else { --- 3421,3427 ---- { VIsual_select = FALSE; showmode(); ! restart_VIsual_select = 2; // restart Select mode later } else { *************** *** 3453,3463 **** { switch (cap->nchar) { ! /* "ZZ": equivalent to ":x". */ case 'Z': do_cmdline_cmd((char_u *)"x"); break; ! /* "ZQ": equivalent to ":q!" (Elvis compatible). */ case 'Q': do_cmdline_cmd((char_u *)"q!"); break; --- 3452,3462 ---- { switch (cap->nchar) { ! // "ZZ": equivalent to ":x". case 'Z': do_cmdline_cmd((char_u *)"x"); break; ! // "ZQ": equivalent to ":q!" (Elvis compatible). case 'Q': do_cmdline_cmd((char_u *)"q!"); break; *************** *** 3499,3516 **** unsigned buflen; char_u *newbuf; char_u *p; ! char_u *kp; /* value of 'keywordprg' */ ! int kp_help; /* 'keywordprg' is ":he" */ ! int kp_ex; /* 'keywordprg' starts with ":" */ ! int n = 0; /* init for GCC */ int cmdchar; ! int g_cmd; /* "g" command */ int tag_cmd = FALSE; char_u *aux_ptr; int isman; int isman_s; ! if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ { cmdchar = cap->nchar; g_cmd = TRUE; --- 3498,3515 ---- unsigned buflen; char_u *newbuf; char_u *p; ! char_u *kp; // value of 'keywordprg' ! int kp_help; // 'keywordprg' is ":he" ! int kp_ex; // 'keywordprg' starts with ":" ! int n = 0; // init for GCC int cmdchar; ! int g_cmd; // "g" command int tag_cmd = FALSE; char_u *aux_ptr; int isman; int isman_s; ! if (cap->cmdchar == 'g') // "g*", "g#", "g]" and "gCTRL-]" { cmdchar = cap->nchar; g_cmd = TRUE; *************** *** 3521,3527 **** g_cmd = FALSE; } ! if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ cmdchar = '#'; /* --- 3520,3526 ---- g_cmd = FALSE; } ! if (cmdchar == POUND) // the pound sign, '#' for English keyboards cmdchar = '#'; /* *************** *** 3543,3557 **** return; } ! /* Allocate buffer to put the command in. Inserting backslashes can ! * double the length of the word. p_kp / curbuf->b_p_kp could be added ! * and some numbers. */ kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 || STRCMP(kp, ":help") == 0); if (kp_help && *skipwhite(ptr) == NUL) { ! emsg(_(e_noident)); /* found white space only */ return; } kp_ex = (*kp == ':'); --- 3542,3556 ---- return; } ! // Allocate buffer to put the command in. Inserting backslashes can ! // double the length of the word. p_kp / curbuf->b_p_kp could be added ! // and some numbers. kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 || STRCMP(kp, ":help") == 0); if (kp_help && *skipwhite(ptr) == NUL) { ! emsg(_(e_noident)); // found white space only return; } kp_ex = (*kp == ':'); *************** *** 3576,3582 **** if (!g_cmd && vim_iswordp(ptr)) STRCPY(buf, "\\<"); ! no_smartcase = TRUE; /* don't use 'smartcase' now */ break; case 'K': --- 3575,3581 ---- if (!g_cmd && vim_iswordp(ptr)) STRCPY(buf, "\\<"); ! no_smartcase = TRUE; // don't use 'smartcase' now break; case 'K': *************** *** 3593,3600 **** } else { ! /* An external command will probably use an argument starting ! * with "-" as an option. To avoid trouble we skip the "-". */ while (*ptr == '-' && n > 0) { ++ptr; --- 3592,3599 ---- } else { ! // An external command will probably use an argument starting ! // with "-" as an option. To avoid trouble we skip the "-". while (*ptr == '-' && n > 0) { ++ptr; *************** *** 3602,3614 **** } if (n == 0) { ! emsg(_(e_noident)); /* found dashes only */ vim_free(buf); return; } ! /* When a count is given, turn it into a range. Is this ! * really what we want? */ isman = (STRCMP(kp, "man") == 0); isman_s = (STRCMP(kp, "man -s") == 0); if (cap->count0 != 0 && !(isman || isman_s)) --- 3601,3613 ---- } if (n == 0) { ! emsg(_(e_noident)); // found dashes only vim_free(buf); return; } ! // When a count is given, turn it into a range. Is this ! // really what we want? isman = (STRCMP(kp, "man") == 0); isman_s = (STRCMP(kp, "man -s") == 0); if (cap->count0 != 0 && !(isman || isman_s)) *************** *** 3658,3667 **** { ptr = vim_strnsave(ptr, n); if (kp_ex) ! /* Escape the argument properly for an Ex command */ p = vim_strsave_fnameescape(ptr, FALSE); else ! /* Escape the argument properly for a shell command */ p = vim_strsave_shellescape(ptr, TRUE, TRUE); vim_free(ptr); if (p == NULL) --- 3657,3666 ---- { ptr = vim_strnsave(ptr, n); if (kp_ex) ! // Escape the argument properly for an Ex command p = vim_strsave_fnameescape(ptr, FALSE); else ! // Escape the argument properly for a shell command p = vim_strsave_shellescape(ptr, TRUE, TRUE); vim_free(ptr); if (p == NULL) *************** *** 3689,3695 **** else if (tag_cmd) { if (curbuf->b_help) ! /* ":help" handles unescaped argument */ aux_ptr = (char_u *)""; else aux_ptr = (char_u *)"\\|\"\n["; --- 3688,3694 ---- else if (tag_cmd) { if (curbuf->b_help) ! // ":help" handles unescaped argument aux_ptr = (char_u *)""; else aux_ptr = (char_u *)"\\|\"\n["; *************** *** 3700,3710 **** p = buf + STRLEN(buf); while (n-- > 0) { ! /* put a backslash before \ and some others */ if (vim_strchr(aux_ptr, *ptr) != NULL) *p++ = '\\'; ! /* When current byte is a part of multibyte character, copy all ! * bytes of that character. */ if (has_mbyte) { int i; --- 3699,3709 ---- p = buf + STRLEN(buf); while (n-- > 0) { ! // put a backslash before \ and some others if (vim_strchr(aux_ptr, *ptr) != NULL) *p++ = '\\'; ! // When current byte is a part of multibyte character, copy all ! // bytes of that character. if (has_mbyte) { int i; *************** *** 3751,3758 **** int get_visual_text( cmdarg_T *cap, ! char_u **pp, /* return: start of selected text */ ! int *lenp) /* return: length of selected text */ { if (VIsual_mode != 'V') unadjust_for_sel(); --- 3750,3757 ---- int get_visual_text( cmdarg_T *cap, ! char_u **pp, // return: start of selected text ! int *lenp) // return: length of selected text { if (VIsual_mode != 'V') unadjust_for_sel(); *************** *** 3780,3786 **** *lenp = curwin->w_cursor.col - VIsual.col + 1; } if (has_mbyte) ! /* Correct the length to include the whole last character. */ *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; } reset_VIsual_and_resel(); --- 3779,3785 ---- *lenp = curwin->w_cursor.col - VIsual.col + 1; } if (has_mbyte) ! // Correct the length to include the whole last character. *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; } reset_VIsual_and_resel(); *************** *** 3815,3821 **** if (cap->cmdchar == 'L') { ! validate_botline(); /* make sure curwin->w_botline is valid */ curwin->w_cursor.lnum = curwin->w_botline - 1; if (cap->count1 - 1 >= curwin->w_cursor.lnum) curwin->w_cursor.lnum = 1; --- 3814,3820 ---- if (cap->cmdchar == 'L') { ! validate_botline(); // make sure curwin->w_botline is valid curwin->w_cursor.lnum = curwin->w_botline - 1; if (cap->count1 - 1 >= curwin->w_cursor.lnum) curwin->w_cursor.lnum = 1; *************** *** 3824,3830 **** #ifdef FEAT_FOLDING if (hasAnyFolding(curwin)) { ! /* Count a fold for one screen line. */ for (n = cap->count1 - 1; n > 0 && curwin->w_cursor.lnum > curwin->w_topline; --n) { --- 3823,3829 ---- #ifdef FEAT_FOLDING if (hasAnyFolding(curwin)) { ! // Count a fold for one screen line. for (n = cap->count1 - 1; n > 0 && curwin->w_cursor.lnum > curwin->w_topline; --n) { *************** *** 3843,3859 **** if (cap->cmdchar == 'M') { #ifdef FEAT_DIFF ! /* Don't count filler lines above the window. */ used -= diff_check_fill(curwin, curwin->w_topline) - curwin->w_topfill; #endif ! validate_botline(); /* make sure w_empty_rows is valid */ half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) { #ifdef FEAT_DIFF ! /* Count half he number of filler lines to be "below this ! * line" and half to be "above the next line". */ if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline + n) / 2 >= half) { --- 3842,3858 ---- if (cap->cmdchar == 'M') { #ifdef FEAT_DIFF ! // Don't count filler lines above the window. used -= diff_check_fill(curwin, curwin->w_topline) - curwin->w_topfill; #endif ! validate_botline(); // make sure w_empty_rows is valid half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) { #ifdef FEAT_DIFF ! // Count half he number of filler lines to be "below this ! // line" and half to be "above the next line". if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline + n) / 2 >= half) { *************** *** 3872,3884 **** if (n > 0 && used > curwin->w_height) --n; } ! else /* (cap->cmdchar == 'H') */ { n = cap->count1 - 1; #ifdef FEAT_FOLDING if (hasAnyFolding(curwin)) { ! /* Count a fold for one screen line. */ lnum = curwin->w_topline; while (n-- > 0 && lnum < curwin->w_botline - 1) { --- 3871,3883 ---- if (n > 0 && used > curwin->w_height) --n; } ! else // (cap->cmdchar == 'H') { n = cap->count1 - 1; #ifdef FEAT_FOLDING if (hasAnyFolding(curwin)) { ! // Count a fold for one screen line. lnum = curwin->w_topline; while (n-- > 0 && lnum < curwin->w_botline - 1) { *************** *** 3894,3900 **** curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; } ! /* Correct for 'so', except when an operator is pending. */ if (cap->oap->op_type == OP_NOP) cursor_correct(); beginline(BL_SOL | BL_FIX); --- 3893,3899 ---- curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; } ! // Correct for 'so', except when an operator is pending. if (cap->oap->op_type == OP_NOP) cursor_correct(); beginline(BL_SOL | BL_FIX); *************** *** 3911,3917 **** if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) { ! /* and move a word or WORD right */ if (mod_mask & MOD_MASK_CTRL) cap->arg = TRUE; nv_wordcmd(cap); --- 3910,3916 ---- if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) { ! // and move a word or WORD right if (mod_mask & MOD_MASK_CTRL) cap->arg = TRUE; nv_wordcmd(cap); *************** *** 3948,3956 **** && vim_strchr(p_ww, '>') != NULL)) && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { ! /* When deleting we also count the NL as a character. ! * Set cap->oap->inclusive when last char in the line is ! * included, move to next line after that */ if ( cap->oap->op_type != OP_NOP && !cap->oap->inclusive && !LINEEMPTY(curwin->w_cursor.lnum)) --- 3947,3955 ---- && vim_strchr(p_ww, '>') != NULL)) && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { ! // When deleting we also count the NL as a character. ! // Set cap->oap->inclusive when last char in the line is ! // included, move to next line after that if ( cap->oap->op_type != OP_NOP && !cap->oap->inclusive && !LINEEMPTY(curwin->w_cursor.lnum)) *************** *** 3967,3973 **** } if (cap->oap->op_type == OP_NOP) { ! /* Only beep and flush if not moved at all */ if (n == cap->count1) beep_flush(); } --- 3966,3972 ---- } if (cap->oap->op_type == OP_NOP) { ! // Only beep and flush if not moved at all if (n == cap->count1) beep_flush(); } *************** *** 4011,4017 **** if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) { ! /* and move a word or WORD left */ if (mod_mask & MOD_MASK_CTRL) cap->arg = 1; nv_bck_word(cap); --- 4010,4016 ---- if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) { ! // and move a word or WORD left if (mod_mask & MOD_MASK_CTRL) cap->arg = 1; nv_bck_word(cap); *************** *** 4024,4033 **** { if (oneleft() == FAIL) { ! /* and wrap to previous line if 'whichwrap' has 'b'. ! * 'h' wraps to previous line if 'whichwrap' has 'h'. ! * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. ! */ if ( (((cap->cmdchar == K_BS || cap->cmdchar == Ctrl_H) && vim_strchr(p_ww, 'b') != NULL) --- 4023,4031 ---- { if (oneleft() == FAIL) { ! // and wrap to previous line if 'whichwrap' has 'b'. ! // 'h' wraps to previous line if 'whichwrap' has 'h'. ! // CURS_LEFT wraps to previous line if 'whichwrap' has '<'. if ( (((cap->cmdchar == K_BS || cap->cmdchar == Ctrl_H) && vim_strchr(p_ww, 'b') != NULL) *************** *** 4041,4050 **** coladvance((colnr_T)MAXCOL); curwin->w_set_curswant = TRUE; ! /* When the NL before the first char has to be deleted we ! * put the cursor on the NUL after the previous line. ! * This is a very special case, be careful! ! * Don't adjust op_end now, otherwise it won't work. */ if ( (cap->oap->op_type == OP_DELETE || cap->oap->op_type == OP_CHANGE) && !LINEEMPTY(curwin->w_cursor.lnum)) --- 4039,4048 ---- coladvance((colnr_T)MAXCOL); curwin->w_set_curswant = TRUE; ! // When the NL before the first char has to be deleted we ! // put the cursor on the NUL after the previous line. ! // This is a very special case, be careful! ! // Don't adjust op_end now, otherwise it won't work. if ( (cap->oap->op_type == OP_DELETE || cap->oap->op_type == OP_CHANGE) && !LINEEMPTY(curwin->w_cursor.lnum)) *************** *** 4062,4068 **** } continue; } ! /* Only beep and flush if not moved at all */ else if (cap->oap->op_type == OP_NOP && n == cap->count1) beep_flush(); break; --- 4060,4066 ---- } continue; } ! // Only beep and flush if not moved at all else if (cap->oap->op_type == OP_NOP && n == cap->count1) beep_flush(); break; *************** *** 4084,4090 **** { if (mod_mask & MOD_MASK_SHIFT) { ! /* is page up */ cap->arg = BACKWARD; nv_page(cap); } --- 4082,4088 ---- { if (mod_mask & MOD_MASK_SHIFT) { ! // is page up cap->arg = BACKWARD; nv_page(cap); } *************** *** 4107,4131 **** { if (mod_mask & MOD_MASK_SHIFT) { ! /* is page down */ cap->arg = FORWARD; nv_page(cap); } #if defined(FEAT_QUICKFIX) ! /* Quickfix window only: view the result under the cursor. */ else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) qf_view_result(FALSE); #endif else { #ifdef FEAT_CMDWIN ! /* In the cmdline window a executes the command. */ if (cmdwin_type != 0 && cap->cmdchar == CAR) cmdwin_result = CAR; else #endif #ifdef FEAT_JOB_CHANNEL ! /* In a prompt buffer a in the last line invokes the callback. */ if (bt_prompt(curbuf) && cap->cmdchar == CAR && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) { --- 4105,4129 ---- { if (mod_mask & MOD_MASK_SHIFT) { ! // is page down cap->arg = FORWARD; nv_page(cap); } #if defined(FEAT_QUICKFIX) ! // Quickfix window only: view the result under the cursor. else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) qf_view_result(FALSE); #endif else { #ifdef FEAT_CMDWIN ! // In the cmdline window a executes the command. if (cmdwin_type != 0 && cap->cmdchar == CAR) cmdwin_result = CAR; else #endif #ifdef FEAT_JOB_CHANNEL ! // In a prompt buffer a in the last line invokes the callback. if (bt_prompt(curbuf) && cap->cmdchar == CAR && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) { *************** *** 4171,4177 **** if (ptr != NULL) { ! /* do autowrite if necessary */ if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) (void)autowrite(curbuf, FALSE); setpcmark(); --- 4169,4175 ---- if (ptr != NULL) { ! // do autowrite if necessary if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) (void)autowrite(curbuf, FALSE); setpcmark(); *************** *** 4196,4206 **** static void nv_end(cmdarg_T *cap) { ! if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ { cap->arg = TRUE; nv_goto(cap); ! cap->count1 = 1; /* to end of current line */ } nv_dollar(cap); } --- 4194,4204 ---- static void nv_end(cmdarg_T *cap) { ! if (cap->arg || (mod_mask & MOD_MASK_CTRL)) // CTRL-END = goto last line { cap->arg = TRUE; nv_goto(cap); ! cap->count1 = 1; // to end of current line } nv_dollar(cap); } *************** *** 4213,4224 **** { cap->oap->motion_type = MCHAR; cap->oap->inclusive = TRUE; ! /* In virtual mode when off the edge of a line and an operator ! * is pending (whew!) keep the cursor where it is. ! * Otherwise, send it to the end of the line. */ if (!virtual_active() || gchar_cursor() != NUL || cap->oap->op_type == OP_NOP) ! curwin->w_curswant = MAXCOL; /* so we stay at the end */ if (cursor_down((long)(cap->count1 - 1), cap->oap->op_type == OP_NOP) == FAIL) clearopbeep(cap->oap); --- 4211,4222 ---- { cap->oap->motion_type = MCHAR; cap->oap->inclusive = TRUE; ! // In virtual mode when off the edge of a line and an operator ! // is pending (whew!) keep the cursor where it is. ! // Otherwise, send it to the end of the line. if (!virtual_active() || gchar_cursor() != NUL || cap->oap->op_type == OP_NOP) ! curwin->w_curswant = MAXCOL; // so we stay at the end if (cursor_down((long)(cap->count1 - 1), cap->oap->op_type == OP_NOP) == FAIL) clearopbeep(cap->oap); *************** *** 4240,4254 **** if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) { ! /* Translate "g??" to "g?g?" */ cap->cmdchar = 'g'; cap->nchar = '?'; nv_operator(cap); return; } ! /* When using 'incsearch' the cursor may be moved to set a different search ! * start position. */ cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0, TRUE); if (cap->searchbuf == NULL) --- 4238,4252 ---- if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) { ! // Translate "g??" to "g?g?" cap->cmdchar = 'g'; cap->nchar = '?'; nv_operator(cap); return; } ! // When using 'incsearch' the cursor may be moved to set a different search ! // start position. cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0, TRUE); if (cap->searchbuf == NULL) *************** *** 4275,4283 **** if (i == 1 && !wrapped && EQUAL_POS(old, curwin->w_cursor)) { ! /* Avoid getting stuck on the current cursor position, which can ! * happen when an offset is given and the cursor is on the last char ! * in the buffer: Repeat with count + 1. */ cap->count1 += 1; (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, NULL); cap->count1 -= 1; --- 4273,4281 ---- if (i == 1 && !wrapped && EQUAL_POS(old, curwin->w_cursor)) { ! // Avoid getting stuck on the current cursor position, which can ! // happen when an offset is given and the cursor is on the last char ! // in the buffer: Repeat with count + 1. cap->count1 += 1; (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, NULL); cap->count1 -= 1; *************** *** 4323,4330 **** #endif } ! /* "/$" will put the cursor after the end of the line, may need to ! * correct that here */ check_cursor(); return i; } --- 4321,4328 ---- #endif } ! // "/$" will put the cursor after the end of the line, may need to ! // correct that here check_cursor(); return i; } *************** *** 4351,4357 **** else { curwin->w_set_curswant = TRUE; ! /* Include a Tab for "tx" and for "dfx". */ if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD && (t_cmd || cap->oap->op_type != OP_NOP)) { --- 4349,4355 ---- else { curwin->w_set_curswant = TRUE; ! // Include a Tab for "tx" and for "dfx". if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD && (t_cmd || cap->oap->op_type != OP_NOP)) { *************** *** 4379,4386 **** { pos_T new_pos = {0, 0, 0}; pos_T prev_pos; ! pos_T *pos = NULL; /* init for GCC */ ! pos_T old_pos; /* cursor position before command */ int flag; long n; int findc; --- 4377,4384 ---- { pos_T new_pos = {0, 0, 0}; pos_T prev_pos; ! pos_T *pos = NULL; // init for GCC ! pos_T old_pos; // cursor position before command int flag; long n; int findc; *************** *** 4472,4484 **** if ((pos = findmatchlimit(cap->oap, findc, (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) { ! if (new_pos.lnum == 0) /* nothing found */ { if (cap->nchar != 'm' && cap->nchar != 'M') clearopbeep(cap->oap); } else ! pos = &new_pos; /* use last one found */ break; } prev_pos = new_pos; --- 4470,4482 ---- if ((pos = findmatchlimit(cap->oap, findc, (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) { ! if (new_pos.lnum == 0) // nothing found { if (cap->nchar != 'm' && cap->nchar != 'M') clearopbeep(cap->oap); } else ! pos = &new_pos; // use last one found break; } prev_pos = new_pos; *************** *** 4495,4505 **** */ if (cap->nchar == 'm' || cap->nchar == 'M') { ! /* norm is TRUE for "]M" and "[m" */ int norm = ((findc == '{') == (cap->nchar == 'm')); n = cap->count1; ! /* found a match: we were inside a method */ if (prev_pos.lnum != 0) { pos = &prev_pos; --- 4493,4503 ---- */ if (cap->nchar == 'm' || cap->nchar == 'M') { ! // norm is TRUE for "]M" and "[m" int norm = ((findc == '{') == (cap->nchar == 'm')); n = cap->count1; ! // found a match: we were inside a method if (prev_pos.lnum != 0) { pos = &prev_pos; *************** *** 4515,4521 **** { if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) { ! /* if not found anything, that's an error */ if (pos == NULL) clearopbeep(cap->oap); n = 0; --- 4513,4519 ---- { if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) { ! // if not found anything, that's an error if (pos == NULL) clearopbeep(cap->oap); n = 0; *************** *** 4524,4545 **** c = gchar_cursor(); if (c == '{' || c == '}') { ! /* Must have found end/start of class: use it. ! * Or found the place to be at. */ if ((c == findc && norm) || (n == 1 && !norm)) { new_pos = curwin->w_cursor; pos = &new_pos; n = 0; } ! /* if no match found at all, we started outside of the ! * class and we're inside now. Just go on. */ else if (new_pos.lnum == 0) { new_pos = curwin->w_cursor; pos = &new_pos; } ! /* found start/end of other method: go to match */ else if ((pos = findmatchlimit(cap->oap, findc, (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) --- 4522,4543 ---- c = gchar_cursor(); if (c == '{' || c == '}') { ! // Must have found end/start of class: use it. ! // Or found the place to be at. if ((c == findc && norm) || (n == 1 && !norm)) { new_pos = curwin->w_cursor; pos = &new_pos; n = 0; } ! // if no match found at all, we started outside of the ! // class and we're inside now. Just go on. else if (new_pos.lnum == 0) { new_pos = curwin->w_cursor; pos = &new_pos; } ! // found start/end of other method: go to match else if ((pos = findmatchlimit(cap->oap, findc, (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) *************** *** 4573,4582 **** */ else if (cap->nchar == '[' || cap->nchar == ']') { ! if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ flag = '{'; else ! flag = '}'; /* "][" or "[]" */ curwin->w_set_curswant = TRUE; /* --- 4571,4580 ---- */ else if (cap->nchar == '[' || cap->nchar == ']') { ! if (cap->nchar == cap->cmdchar) // "]]" or "[[" flag = '{'; else ! flag = '}'; // "][" or "[]" curwin->w_set_curswant = TRUE; /* *************** *** 4683,4689 **** } #endif ! /* Not a valid cap->nchar. */ else clearopbeep(cap->oap); } --- 4681,4687 ---- } #endif ! // Not a valid cap->nchar. else clearopbeep(cap->oap); } *************** *** 4700,4706 **** #endif cap->oap->inclusive = TRUE; ! if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ { if (cap->count0 > 100) clearopbeep(cap->oap); --- 4698,4704 ---- #endif cap->oap->inclusive = TRUE; ! if (cap->count0) // {cnt}% : goto {cnt} percentage in file { if (cap->count0 > 100) clearopbeep(cap->oap); *************** *** 4708,4715 **** { cap->oap->motion_type = MLINE; setpcmark(); ! /* Round up, so CTRL-G will give same value. Watch out for a ! * large line count, the line number must not go negative! */ if (curbuf->b_ml.ml_line_count > 1000000) curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) / 100L * cap->count0; --- 4706,4713 ---- { cap->oap->motion_type = MLINE; setpcmark(); ! // Round up, so CTRL-G will give same value. Watch out for a ! // large line count, the line number must not go negative! if (curbuf->b_ml.ml_line_count > 1000000) curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) / 100L * cap->count0; *************** *** 4721,4727 **** beginline(BL_SOL | BL_FIX); } } ! else /* "%" : go to matching paren */ { cap->oap->motion_type = MCHAR; cap->oap->use_reg_one = TRUE; --- 4719,4725 ---- beginline(BL_SOL | BL_FIX); } } ! else // "%" : go to matching paren { cap->oap->motion_type = MCHAR; cap->oap->use_reg_one = TRUE; *************** *** 4754,4760 **** { cap->oap->motion_type = MCHAR; cap->oap->use_reg_one = TRUE; ! /* The motion used to be inclusive for "(", but that is not what Vi does. */ cap->oap->inclusive = FALSE; curwin->w_set_curswant = TRUE; --- 4752,4758 ---- { cap->oap->motion_type = MCHAR; cap->oap->use_reg_one = TRUE; ! // The motion used to be inclusive for "(", but that is not what Vi does. cap->oap->inclusive = FALSE; curwin->w_set_curswant = TRUE; *************** *** 4762,4768 **** clearopbeep(cap->oap); else { ! /* Don't leave the cursor on the NUL past end of line. */ adjust_cursor(cap->oap); curwin->w_cursor.coladd = 0; #ifdef FEAT_FOLDING --- 4760,4766 ---- clearopbeep(cap->oap); else { ! // Don't leave the cursor on the NUL past end of line. adjust_cursor(cap->oap); curwin->w_cursor.coladd = 0; #ifdef FEAT_FOLDING *************** *** 4816,4822 **** { if (cap->oap->op_type == OP_LOWER || VIsual_active) { ! /* translate "u" to "gu" and "guu" to "gugu" */ cap->cmdchar = 'g'; cap->nchar = 'u'; nv_operator(cap); --- 4814,4820 ---- { if (cap->oap->op_type == OP_LOWER || VIsual_active) { ! // translate "u" to "gu" and "guu" to "gugu" cap->cmdchar = 'g'; cap->nchar = 'u'; nv_operator(cap); *************** *** 4865,4898 **** } #endif ! /* get another character */ if (cap->nchar == Ctrl_V) { had_ctrl_v = Ctrl_V; cap->nchar = get_literal(); ! /* Don't redo a multibyte character with CTRL-V. */ if (cap->nchar > DEL) had_ctrl_v = NUL; } else had_ctrl_v = NUL; ! /* Abort if the character is a special key. */ if (IS_SPECIAL(cap->nchar)) { clearopbeep(cap->oap); return; } ! /* Visual mode "r" */ if (VIsual_active) { if (got_int) reset_VIsual(); if (had_ctrl_v) { ! /* Use a special (negative) number to make a difference between a ! * literal CR or NL and a line break. */ if (cap->nchar == CAR) cap->nchar = REPLACE_CR_NCHAR; else if (cap->nchar == NL) --- 4863,4896 ---- } #endif ! // get another character if (cap->nchar == Ctrl_V) { had_ctrl_v = Ctrl_V; cap->nchar = get_literal(); ! // Don't redo a multibyte character with CTRL-V. if (cap->nchar > DEL) had_ctrl_v = NUL; } else had_ctrl_v = NUL; ! // Abort if the character is a special key. if (IS_SPECIAL(cap->nchar)) { clearopbeep(cap->oap); return; } ! // Visual mode "r" if (VIsual_active) { if (got_int) reset_VIsual(); if (had_ctrl_v) { ! // Use a special (negative) number to make a difference between a ! // literal CR or NL and a line break. if (cap->nchar == CAR) cap->nchar = REPLACE_CR_NCHAR; else if (cap->nchar == NL) *************** *** 4902,4915 **** return; } ! /* Break tabs, etc. */ if (virtual_active()) { if (u_save_cursor() == FAIL) return; if (gchar_cursor() == NUL) { ! /* Add extra space and put the cursor on the first one. */ coladvance_force((colnr_T)(getviscol() + cap->count1)); curwin->w_cursor.col -= cap->count1; } --- 4900,4913 ---- return; } ! // Break tabs, etc. if (virtual_active()) { if (u_save_cursor() == FAIL) return; if (gchar_cursor() == NUL) { ! // Add extra space and put the cursor on the first one. coladvance_force((colnr_T)(getviscol() + cap->count1)); curwin->w_cursor.col -= cap->count1; } *************** *** 4917,4923 **** coladvance_force(getviscol()); } ! /* Abort if not enough characters to replace. */ ptr = ml_get_cursor(); if (STRLEN(ptr) < (unsigned)cap->count1 || (has_mbyte && mb_charlen(ptr) < cap->count1)) --- 4915,4921 ---- coladvance_force(getviscol()); } ! // Abort if not enough characters to replace. ptr = ml_get_cursor(); if (STRLEN(ptr) < (unsigned)cap->count1 || (has_mbyte && mb_charlen(ptr) < cap->count1)) *************** *** 4941,4947 **** return; } ! /* save line for undo */ if (u_save_cursor() == FAIL) return; --- 4939,4945 ---- return; } ! // save line for undo if (u_save_cursor() == FAIL) return; *************** *** 4955,4965 **** * autoindent. The insert command depends on being on the last * character of a line or not. */ ! (void)del_chars(cap->count1, FALSE); /* delete the characters */ stuffcharReadbuff('\r'); stuffcharReadbuff(ESC); ! /* Give 'r' to edit(), to get the redo command right. */ invoke_edit(cap, TRUE, 'r', FALSE); } else --- 4953,4963 ---- * autoindent. The insert command depends on being on the last * character of a line or not. */ ! (void)del_chars(cap->count1, FALSE); // delete the characters stuffcharReadbuff('\r'); stuffcharReadbuff(ESC); ! // Give 'r' to edit(), to get the redo command right. invoke_edit(cap, TRUE, 'r', FALSE); } else *************** *** 4977,4985 **** if (cap->ncharC2 != 0) AppendCharToRedobuff(cap->ncharC2); ! /* This is slow, but it handles replacing a single-byte with a ! * multi-byte and the other way around. Also handles adding ! * composing characters for utf-8. */ for (n = cap->count1; n > 0; --n) { State = REPLACE; --- 4975,4983 ---- if (cap->ncharC2 != 0) AppendCharToRedobuff(cap->ncharC2); ! // This is slow, but it handles replacing a single-byte with a ! // multi-byte and the other way around. Also handles adding ! // composing characters for utf-8. for (n = cap->count1; n > 0; --n) { State = REPLACE; *************** *** 4990,4996 **** if (c != NUL) ins_char(c); else ! /* will be decremented further down */ ++curwin->w_cursor.col; } else --- 4988,4994 ---- if (c != NUL) ins_char(c); else ! // will be decremented further down ++curwin->w_cursor.col; } else *************** *** 5040,5052 **** } #endif ! /* mark the buffer as changed and prepare for displaying */ changed_bytes(curwin->w_cursor.lnum, (colnr_T)(curwin->w_cursor.col - cap->count1)); } ! --curwin->w_cursor.col; /* cursor on the last replaced char */ ! /* if the character on the left of the current cursor is a multi-byte ! * character, move two characters left */ if (has_mbyte) mb_adjust_cursor(); curbuf->b_op_end = curwin->w_cursor; --- 5038,5050 ---- } #endif ! // mark the buffer as changed and prepare for displaying changed_bytes(curwin->w_cursor.lnum, (colnr_T)(curwin->w_cursor.col - cap->count1)); } ! --curwin->w_cursor.col; // cursor on the last replaced char ! // if the character on the left of the current cursor is a multi-byte ! // character, move two characters left if (has_mbyte) mb_adjust_cursor(); curbuf->b_op_end = curwin->w_cursor; *************** *** 5075,5082 **** curwin->w_cursor.lnum = old_cursor.lnum; curwin->w_curswant = right; ! /* 'selection "exclusive" and cursor at right-bottom corner: move it ! * right one column */ if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') ++curwin->w_curswant; coladvance(curwin->w_curswant); --- 5073,5080 ---- curwin->w_cursor.lnum = old_cursor.lnum; curwin->w_curswant = right; ! // 'selection "exclusive" and cursor at right-bottom corner: move it ! // right one column if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') ++curwin->w_curswant; coladvance(curwin->w_curswant); *************** *** 5110,5120 **** static void nv_Replace(cmdarg_T *cap) { ! if (VIsual_active) /* "R" is replace lines */ { cap->cmdchar = 'c'; cap->nchar = NUL; ! VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ VIsual_mode = 'V'; nv_operator(cap); } --- 5108,5118 ---- static void nv_Replace(cmdarg_T *cap) { ! if (VIsual_active) // "R" is replace lines { cap->cmdchar = 'c'; cap->nchar = NUL; ! VIsual_mode_orig = VIsual_mode; // remember original area for gv VIsual_mode = 'V'; nv_operator(cap); } *************** *** 5141,5147 **** { cap->cmdchar = 'r'; cap->nchar = cap->extra_char; ! nv_replace(cap); /* Do same as "r" in Visual mode for now */ } else if (!checkclearopq(cap->oap)) { --- 5139,5145 ---- { cap->cmdchar = 'r'; cap->nchar = cap->extra_char; ! nv_replace(cap); // Do same as "r" in Visual mode for now } else if (!checkclearopq(cap->oap)) { *************** *** 5149,5155 **** emsg(_(e_modifiable)); else { ! if (cap->extra_char == Ctrl_V) /* get another character */ cap->extra_char = get_literal(); stuffcharReadbuff(cap->extra_char); stuffcharReadbuff(ESC); --- 5147,5153 ---- emsg(_(e_modifiable)); else { ! if (cap->extra_char == Ctrl_V) // get another character cap->extra_char = get_literal(); stuffcharReadbuff(cap->extra_char); stuffcharReadbuff(ESC); *************** *** 5279,5285 **** cap->oap->motion_type = flag ? MLINE : MCHAR; if (cap->cmdchar == '`') cap->oap->use_reg_one = TRUE; ! cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ curwin->w_set_curswant = TRUE; } --- 5277,5283 ---- cap->oap->motion_type = flag ? MLINE : MCHAR; if (cap->cmdchar == '`') cap->oap->use_reg_one = TRUE; ! cap->oap->inclusive = FALSE; // ignored if not MCHAR curwin->w_set_curswant = TRUE; } *************** *** 5291,5298 **** { static char_u trans[] = "YyDdCcxdXdAAIIrr"; ! /* Uppercase means linewise, except in block mode, then "D" deletes till ! * the end of the line, and "C" replaces till EOL */ if (isupper(cap->cmdchar)) { if (VIsual_mode != Ctrl_V) --- 5289,5296 ---- { static char_u trans[] = "YyDdCcxdXdAAIIrr"; ! // Uppercase means linewise, except in block mode, then "D" deletes till ! // the end of the line, and "C" replaces till EOL if (isupper(cap->cmdchar)) { if (VIsual_mode != Ctrl_V) *************** *** 5314,5320 **** nv_subst(cmdarg_T *cap) { #ifdef FEAT_TERMINAL ! /* When showing output of term_dumpdiff() swap the top and botom. */ if (term_swap_diff() == OK) return; #endif --- 5312,5318 ---- nv_subst(cmdarg_T *cap) { #ifdef FEAT_TERMINAL ! // When showing output of term_dumpdiff() swap the top and botom. if (term_swap_diff() == OK) return; #endif *************** *** 5325,5331 **** return; } #endif ! if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ { if (cap->cmdchar == 'S') { --- 5323,5329 ---- return; } #endif ! if (VIsual_active) // "vs" and "vS" are the same as "vc" { if (cap->cmdchar == 'S') { *************** *** 5346,5354 **** nv_abbrev(cmdarg_T *cap) { if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) ! cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ ! /* in Visual mode these commands are operators */ if (VIsual_active) v_visop(cap); else --- 5344,5352 ---- nv_abbrev(cmdarg_T *cap) { if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) ! cap->cmdchar = 'x'; // DEL key behaves like 'x' ! // in Visual mode these commands are operators if (VIsual_active) v_visop(cap); else *************** *** 5405,5411 **** int c; #ifdef FEAT_FOLDING pos_T old_cursor = curwin->w_cursor; ! int old_KeyTyped = KeyTyped; /* getting file may reset it */ #endif if (cap->cmdchar == 'g') --- 5403,5409 ---- int c; #ifdef FEAT_FOLDING pos_T old_cursor = curwin->w_cursor; ! int old_KeyTyped = KeyTyped; // getting file may reset it #endif if (cap->cmdchar == 'g') *************** *** 5413,5419 **** else c = cap->nchar; pos = getmark(c, (cap->oap->op_type == OP_NOP)); ! if (pos == (pos_T *)-1) /* jumped to other file */ { if (cap->arg) { --- 5411,5417 ---- else c = cap->nchar; pos = getmark(c, (cap->oap->op_type == OP_NOP)); ! if (pos == (pos_T *)-1) // jumped to other file { if (cap->arg) { *************** *** 5426,5432 **** else nv_cursormark(cap, cap->arg, pos); ! /* May need to clear the coladd that a mark includes. */ if (!virtual_active()) curwin->w_cursor.coladd = 0; check_cursor_col(); --- 5424,5430 ---- else nv_cursormark(cap, cap->arg, pos); ! // May need to clear the coladd that a mark includes. if (!virtual_active()) curwin->w_cursor.coladd = 0; check_cursor_col(); *************** *** 5450,5456 **** pos_T *pos; # ifdef FEAT_FOLDING linenr_T lnum = curwin->w_cursor.lnum; ! int old_KeyTyped = KeyTyped; /* getting file may reset it */ # endif if (!checkclearopq(cap->oap)) --- 5448,5454 ---- pos_T *pos; # ifdef FEAT_FOLDING linenr_T lnum = curwin->w_cursor.lnum; ! int old_KeyTyped = KeyTyped; // getting file may reset it # endif if (!checkclearopq(cap->oap)) *************** *** 5459,5470 **** pos = movechangelist((int)cap->count1); else pos = movemark((int)cap->count1); ! if (pos == (pos_T *)-1) /* jump to other file */ { curwin->w_set_curswant = TRUE; check_cursor(); } ! else if (pos != NULL) /* can jump */ nv_cursormark(cap, FALSE, pos); else if (cap->cmdchar == 'g') { --- 5457,5468 ---- pos = movechangelist((int)cap->count1); else pos = movemark((int)cap->count1); ! if (pos == (pos_T *)-1) // jump to other file { curwin->w_set_curswant = TRUE; check_cursor(); } ! else if (pos != NULL) // can jump nv_cursormark(cap, FALSE, pos); else if (cap->cmdchar == 'g') { *************** *** 5505,5511 **** if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) { cap->oap->regname = cap->nchar; ! cap->opcount = cap->count0; /* remember count before '"' */ #ifdef FEAT_EVAL set_reg_var(cap->oap->regname); #endif --- 5503,5509 ---- if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) { cap->oap->regname = cap->nchar; ! cap->opcount = cap->count0; // remember count before '"' #ifdef FEAT_EVAL set_reg_var(cap->oap->regname); #endif *************** *** 5526,5568 **** if (cap->cmdchar == Ctrl_Q) cap->cmdchar = Ctrl_V; ! /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it ! * characterwise, linewise, or blockwise. */ if (cap->oap->op_type != OP_NOP) { motion_force = cap->oap->motion_force = cap->cmdchar; ! finish_op = FALSE; /* operator doesn't finish now but later */ return; } VIsual_select = cap->arg; ! if (VIsual_active) /* change Visual mode */ { ! if (VIsual_mode == cap->cmdchar) /* stop visual mode */ end_visual_mode(); ! else /* toggle char/block mode */ ! { /* or char/line mode */ VIsual_mode = cap->cmdchar; showmode(); } ! redraw_curbuf_later(INVERTED); /* update the inversion */ } ! else /* start Visual mode */ { check_visual_highlight(); if (cap->count0 > 0 && resel_VIsual_mode != NUL) { ! /* use previously selected part */ VIsual = curwin->w_cursor; VIsual_active = TRUE; VIsual_reselect = TRUE; if (!cap->arg) ! /* start Select mode when 'selectmode' contains "cmd" */ may_start_select('c'); setmouse(); if (p_smd && msg_silent == 0) ! redraw_cmdline = TRUE; /* show visual mode later */ /* * For V and ^V, we multiply the number of lines even if there * was only one -- webb --- 5524,5566 ---- if (cap->cmdchar == Ctrl_Q) cap->cmdchar = Ctrl_V; ! // 'v', 'V' and CTRL-V can be used while an operator is pending to make it ! // characterwise, linewise, or blockwise. if (cap->oap->op_type != OP_NOP) { motion_force = cap->oap->motion_force = cap->cmdchar; ! finish_op = FALSE; // operator doesn't finish now but later return; } VIsual_select = cap->arg; ! if (VIsual_active) // change Visual mode { ! if (VIsual_mode == cap->cmdchar) // stop visual mode end_visual_mode(); ! else // toggle char/block mode ! { // or char/line mode VIsual_mode = cap->cmdchar; showmode(); } ! redraw_curbuf_later(INVERTED); // update the inversion } ! else // start Visual mode { check_visual_highlight(); if (cap->count0 > 0 && resel_VIsual_mode != NUL) { ! // use previously selected part VIsual = curwin->w_cursor; VIsual_active = TRUE; VIsual_reselect = TRUE; if (!cap->arg) ! // start Select mode when 'selectmode' contains "cmd" may_start_select('c'); setmouse(); if (p_smd && msg_silent == 0) ! redraw_cmdline = TRUE; // show visual mode later /* * For V and ^V, we multiply the number of lines even if there * was only one -- webb *************** *** 5601,5619 **** } else curwin->w_set_curswant = TRUE; ! redraw_curbuf_later(INVERTED); /* show the inversion */ } else { if (!cap->arg) ! /* start Select mode when 'selectmode' contains "cmd" */ may_start_select('c'); n_start_visual_mode(cap->cmdchar); if (VIsual_mode != 'V' && *p_sel == 'e') ! ++cap->count1; /* include one more char */ if (cap->count0 > 0 && --cap->count1 > 0) { ! /* With a count select that many characters or lines. */ if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) nv_right(cap); else if (VIsual_mode == 'V') --- 5599,5617 ---- } else curwin->w_set_curswant = TRUE; ! redraw_curbuf_later(INVERTED); // show the inversion } else { if (!cap->arg) ! // start Select mode when 'selectmode' contains "cmd" may_start_select('c'); n_start_visual_mode(cap->cmdchar); if (VIsual_mode != 'V' && *p_sel == 'e') ! ++cap->count1; // include one more char if (cap->count0 > 0 && --cap->count1 > 0) { ! // With a count select that many characters or lines. if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) nv_right(cap); else if (VIsual_mode == 'V') *************** *** 5629,5635 **** void start_selection(void) { ! /* if 'selectmode' contains "key", start Select mode */ may_start_select('k'); n_start_visual_mode('v'); } --- 5627,5633 ---- void start_selection(void) { ! // if 'selectmode' contains "key", start Select mode may_start_select('k'); n_start_visual_mode('v'); } *************** *** 5652,5658 **** n_start_visual_mode(int c) { #ifdef FEAT_CONCEAL ! /* Check for redraw before changing the state. */ conceal_check_cursor_line(); #endif --- 5650,5656 ---- n_start_visual_mode(int c) { #ifdef FEAT_CONCEAL ! // Check for redraw before changing the state. conceal_check_cursor_line(); #endif *************** *** 5675,5694 **** setmouse(); #ifdef FEAT_CONCEAL ! /* Check for redraw after changing the state. */ conceal_check_cursor_line(); #endif if (p_smd && msg_silent == 0) ! redraw_cmdline = TRUE; /* show visual mode later */ #ifdef FEAT_CLIPBOARD ! /* Make sure the clipboard gets updated. Needed because start and ! * end may still be the same, and the selection needs to be owned */ clip_star.vmode = NUL; #endif ! /* Only need to redraw this line, unless still need to redraw an old ! * Visual area (when 'lazyredraw' is set). */ if (curwin->w_redr_type < INVERTED) { curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; --- 5673,5692 ---- setmouse(); #ifdef FEAT_CONCEAL ! // Check for redraw after changing the state. conceal_check_cursor_line(); #endif if (p_smd && msg_silent == 0) ! redraw_cmdline = TRUE; // show visual mode later #ifdef FEAT_CLIPBOARD ! // Make sure the clipboard gets updated. Needed because start and ! // end may still be the same, and the selection needs to be owned clip_star.vmode = NUL; #endif ! // Only need to redraw this line, unless still need to redraw an old ! // Visual area (when 'lazyredraw' is set). if (curwin->w_redr_type < INVERTED) { curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; *************** *** 5705,5717 **** { if (cap->nchar == ':') { ! /* "CTRL-W :" is the same as typing ":"; useful in a terminal window */ cap->cmdchar = ':'; cap->nchar = NUL; nv_colon(cap); } else if (!checkclearop(cap->oap)) ! do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ } /* --- 5703,5715 ---- { if (cap->nchar == ':') { ! // "CTRL-W :" is the same as typing ":"; useful in a terminal window cap->cmdchar = ':'; cap->nchar = NUL; nv_colon(cap); } else if (!checkclearop(cap->oap)) ! do_window(cap->nchar, cap->count0, NUL); // everything is in window.c } /* *************** *** 5722,5728 **** { clearop(cap->oap); if (VIsual_active) ! end_visual_mode(); /* stop Visual mode */ do_cmdline_cmd((char_u *)"st"); } --- 5720,5726 ---- { clearop(cap->oap); if (VIsual_active) ! end_visual_mode(); // stop Visual mode do_cmdline_cmd((char_u *)"st"); } *************** *** 5793,5799 **** beep_flush(); else { ! /* set w_cursor to the start of the Visual area, tpos to the end */ if (VIsual_active) { i = VIsual_mode; --- 5791,5797 ---- beep_flush(); else { ! // set w_cursor to the start of the Visual area, tpos to the end if (VIsual_active) { i = VIsual_mode; *************** *** 5822,5829 **** VIsual_active = TRUE; VIsual_reselect = TRUE; ! /* Set Visual to the start and w_cursor to the end of the Visual ! * area. Make sure they are on an existing character. */ check_cursor(); VIsual = curwin->w_cursor; curwin->w_cursor = tpos; --- 5820,5827 ---- VIsual_active = TRUE; VIsual_reselect = TRUE; ! // Set Visual to the start and w_cursor to the end of the Visual ! // area. Make sure they are on an existing character. check_cursor(); VIsual = curwin->w_cursor; curwin->w_cursor = tpos; *************** *** 5840,5847 **** may_start_select('c'); setmouse(); #ifdef FEAT_CLIPBOARD ! /* Make sure the clipboard gets updated. Needed because start and ! * end are still the same, and the selection needs to be owned */ clip_star.vmode = NUL; #endif redraw_curbuf_later(INVERTED); --- 5838,5845 ---- may_start_select('c'); setmouse(); #ifdef FEAT_CLIPBOARD ! // Make sure the clipboard gets updated. Needed because start and ! // end are still the same, and the selection needs to be owned clip_star.vmode = NUL; #endif redraw_curbuf_later(INVERTED); *************** *** 5863,5874 **** */ case K_BS: cap->nchar = Ctrl_H; ! /* FALLTHROUGH */ case 'h': case 'H': case Ctrl_H: # ifdef EBCDIC ! /* EBCDIC: 'v'-'h' != '^v'-'^h' */ if (cap->nchar == Ctrl_H) cap->cmdchar = Ctrl_V; else --- 5861,5872 ---- */ case K_BS: cap->nchar = Ctrl_H; ! // FALLTHROUGH case 'h': case 'H': case Ctrl_H: # ifdef EBCDIC ! // EBCDIC: 'v'-'h' != '^v'-'^h' if (cap->nchar == Ctrl_H) cap->cmdchar = Ctrl_V; else *************** *** 5878,5887 **** nv_visual(cap); break; ! /* "gn", "gN" visually select next/previous search match ! * "gn" selects next match ! * "gN" selects previous match ! */ case 'N': case 'n': if (!current_search(cap->count1, cap->nchar == 'n')) --- 5876,5884 ---- nv_visual(cap); break; ! // "gn", "gN" visually select next/previous search match ! // "gn" selects next match ! // "gN" selects previous match case 'N': case 'n': if (!current_search(cap->count1, cap->nchar == 'n')) *************** *** 5894,5901 **** */ case 'j': case K_DOWN: ! /* with 'nowrap' it works just like the normal "j" command; also when ! * in a closed fold */ if (!curwin->w_p_wrap #ifdef FEAT_FOLDING || hasFolding(curwin->w_cursor.lnum, NULL, NULL) --- 5891,5898 ---- */ case 'j': case K_DOWN: ! // with 'nowrap' it works just like the normal "j" command; also when ! // in a closed fold if (!curwin->w_p_wrap #ifdef FEAT_FOLDING || hasFolding(curwin->w_cursor.lnum, NULL, NULL) *************** *** 5913,5920 **** case 'k': case K_UP: ! /* with 'nowrap' it works just like the normal "k" command; also when ! * in a closed fold */ if (!curwin->w_p_wrap #ifdef FEAT_FOLDING || hasFolding(curwin->w_cursor.lnum, NULL, NULL) --- 5910,5917 ---- case 'k': case K_UP: ! // with 'nowrap' it works just like the normal "k" command; also when ! // in a closed fold if (!curwin->w_p_wrap #ifdef FEAT_FOLDING || hasFolding(curwin->w_cursor.lnum, NULL, NULL) *************** *** 5943,5949 **** */ case '^': flag = TRUE; ! /* FALLTHROUGH */ case '0': case 'm': --- 5940,5946 ---- */ case '^': flag = TRUE; ! // FALLTHROUGH case '0': case 'm': *************** *** 5963,5971 **** } else i = curwin->w_leftcol; ! /* Go to the middle of the screen line. When 'number' or ! * 'relativenumber' is on and lines are wrapping the middle can be more ! * to the left. */ if (cap->nchar == 'm') i += (curwin->w_width - curwin_col_off() + ((curwin->w_p_wrap && i > 0) --- 5960,5968 ---- } else i = curwin->w_leftcol; ! // Go to the middle of the screen line. When 'number' or ! // 'relativenumber' is on and lines are wrapping the middle can be more ! // to the left. if (cap->nchar == 'm') i += (curwin->w_width - curwin_col_off() + ((curwin->w_p_wrap && i > 0) *************** *** 6000,6007 **** break; case '_': ! /* "g_": to the last non-blank character in the line or lines ! * downward. */ cap->oap->motion_type = MCHAR; cap->oap->inclusive = TRUE; curwin->w_curswant = MAXCOL; --- 5997,6004 ---- break; case '_': ! // "g_": to the last non-blank character in the line or lines ! // downward. cap->oap->motion_type = MCHAR; cap->oap->inclusive = TRUE; curwin->w_curswant = MAXCOL; *************** *** 6012,6022 **** { char_u *ptr = ml_get_curline(); ! /* In Visual mode we may end up after the line. */ if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) --curwin->w_cursor.col; ! /* Decrease the cursor column until it's on a non-blank. */ while (curwin->w_cursor.col > 0 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) --curwin->w_cursor.col; --- 6009,6019 ---- { char_u *ptr = ml_get_curline(); ! // In Visual mode we may end up after the line. if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) --curwin->w_cursor.col; ! // Decrease the cursor column until it's on a non-blank. while (curwin->w_cursor.col > 0 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) --curwin->w_cursor.col; *************** *** 6035,6041 **** oap->inclusive = TRUE; if (curwin->w_p_wrap && curwin->w_width != 0) { ! curwin->w_curswant = MAXCOL; /* so we stay at the end */ if (cap->count1 == 1) { int width1 = curwin->w_width - col_off; --- 6032,6038 ---- oap->inclusive = TRUE; if (curwin->w_p_wrap && curwin->w_width != 0) { ! curwin->w_curswant = MAXCOL; // so we stay at the end if (cap->count1 == 1) { int width1 = curwin->w_width - col_off; *************** *** 6048,6054 **** * width2; coladvance((colnr_T)i); ! /* Make sure we stick in this column. */ validate_virtcol(); curwin->w_curswant = curwin->w_virtcol; curwin->w_set_curswant = FALSE; --- 6045,6051 ---- * width2; coladvance((colnr_T)i); ! // Make sure we stick in this column. validate_virtcol(); curwin->w_curswant = curwin->w_virtcol; curwin->w_set_curswant = FALSE; *************** *** 6089,6098 **** case '*': case '#': #if POUND != '#' ! case POUND: /* pound sign (sometimes equal to '#') */ #endif ! case Ctrl_RSB: /* :tag or :tselect for current identifier */ ! case ']': /* :tselect for current identifier */ nv_ident(cap); break; --- 6086,6095 ---- case '*': case '#': #if POUND != '#' ! case POUND: // pound sign (sometimes equal to '#') #endif ! case Ctrl_RSB: // :tag or :tselect for current identifier ! case ']': // :tselect for current identifier nv_ident(cap); break; *************** *** 6155,6164 **** break; #endif ! /* "g'm" and "g`m": jump to mark without setting pcmark */ case '\'': cap->arg = TRUE; ! /* FALLTHROUGH */ case '`': nv_gomark(cap); break; --- 6152,6161 ---- break; #endif ! // "g'm" and "g`m": jump to mark without setting pcmark case '\'': cap->arg = TRUE; ! // FALLTHROUGH case '`': nv_gomark(cap); break; *************** *** 6190,6196 **** show_utf8(); break; ! /* "g<": show scrollback text */ case '<': show_sb_text(); break; --- 6187,6193 ---- show_utf8(); break; ! // "g<": show scrollback text case '<': show_sb_text(); break; *************** *** 6217,6223 **** case 'q': case 'w': oap->cursor_start = curwin->w_cursor; ! /* FALLTHROUGH */ case '~': case 'u': case 'U': --- 6214,6220 ---- case 'q': case 'w': oap->cursor_start = curwin->w_cursor; ! // FALLTHROUGH case '~': case 'u': case 'U': *************** *** 6271,6283 **** break; #ifdef FEAT_BYTEOFF ! /* "go": goto byte count from start of buffer */ case 'o': goto_byte(cap->count0); break; #endif ! /* "gQ": improved Ex mode */ case 'Q': if (text_locked()) { --- 6268,6280 ---- break; #ifdef FEAT_BYTEOFF ! // "go": goto byte count from start of buffer case 'o': goto_byte(cap->count0); break; #endif ! // "gQ": improved Ex mode case 'Q': if (text_locked()) { *************** *** 6311,6317 **** break; case '+': ! case '-': /* "g+" and "g-": undo or redo along the timeline */ if (!checkclearopq(oap)) undo_time(cap->nchar == '-' ? -cap->count1 : cap->count1, FALSE, FALSE, FALSE); --- 6308,6314 ---- break; case '+': ! case '-': // "g+" and "g-": undo or redo along the timeline if (!checkclearopq(oap)) undo_time(cap->nchar == '-' ? -cap->count1 : cap->count1, FALSE, FALSE, FALSE); *************** *** 6337,6347 **** { #ifdef FEAT_FOLDING if (cap->cmdchar == 'O') ! /* Open above the first line of a folded sequence of lines */ (void)hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL); else ! /* Open below the last line of a folded sequence of lines */ (void)hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum); #endif --- 6334,6344 ---- { #ifdef FEAT_FOLDING if (cap->cmdchar == 'O') ! // Open above the first line of a folded sequence of lines (void)hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL); else ! // Open below the last line of a folded sequence of lines (void)hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum); #endif *************** *** 6360,6369 **** #endif #ifdef FEAT_SYN_HL if (curwin->w_p_cul) ! /* force redraw of cursorline */ curwin->w_valid &= ~VALID_CROW; #endif ! /* When '#' is in 'cpoptions' ignore the count. */ if (vim_strchr(p_cpo, CPO_HASH) != NULL) cap->count1 = 1; invoke_edit(cap, FALSE, cap->cmdchar, TRUE); --- 6357,6366 ---- #endif #ifdef FEAT_SYN_HL if (curwin->w_p_cul) ! // force redraw of cursorline curwin->w_valid &= ~VALID_CROW; #endif ! // When '#' is in 'cpoptions' ignore the count. if (vim_strchr(p_cpo, CPO_HASH) != NULL) cap->count1 = 1; invoke_edit(cap, FALSE, cap->cmdchar, TRUE); *************** *** 6408,6417 **** static void nv_Undo(cmdarg_T *cap) { ! /* In Visual mode and typing "gUU" triggers an operator */ if (cap->oap->op_type == OP_UPPER || VIsual_active) { ! /* translate "gUU" to "gUgU" */ cap->cmdchar = 'g'; cap->nchar = 'U'; nv_operator(cap); --- 6405,6414 ---- static void nv_Undo(cmdarg_T *cap) { ! // In Visual mode and typing "gUU" triggers an operator if (cap->oap->op_type == OP_UPPER || VIsual_active) { ! // translate "gUU" to "gUgU" cap->cmdchar = 'g'; cap->nchar = 'U'; nv_operator(cap); *************** *** 6463,6469 **** } #endif ! if (op_type == cap->oap->op_type) /* double operator works on lines */ nv_lineop(cap); else if (!checkclearop(cap->oap)) { --- 6460,6466 ---- } #endif ! if (op_type == cap->oap->op_type) // double operator works on lines nv_lineop(cap); else if (!checkclearop(cap->oap)) { *************** *** 6511,6523 **** cap->oap->motion_type = MLINE; if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) clearopbeep(cap->oap); ! else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ && cap->oap->motion_force != 'v' && cap->oap->motion_force != Ctrl_V) || cap->oap->op_type == OP_LSHIFT || cap->oap->op_type == OP_RSHIFT) beginline(BL_SOL | BL_FIX); ! else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ beginline(BL_WHITE | BL_FIX); } --- 6508,6520 ---- cap->oap->motion_type = MLINE; if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) clearopbeep(cap->oap); ! else if ( (cap->oap->op_type == OP_DELETE // only with linewise motions && cap->oap->motion_force != 'v' && cap->oap->motion_force != Ctrl_V) || cap->oap->op_type == OP_LSHIFT || cap->oap->op_type == OP_RSHIFT) beginline(BL_SOL | BL_FIX); ! else if (cap->oap->op_type != OP_YANK) // 'Y' does not move cursor beginline(BL_WHITE | BL_FIX); } *************** *** 6527,6533 **** static void nv_home(cmdarg_T *cap) { ! /* CTRL-HOME is like "gg" */ if (mod_mask & MOD_MASK_CTRL) nv_goto(cap); else --- 6524,6530 ---- static void nv_home(cmdarg_T *cap) { ! // CTRL-HOME is like "gg" if (mod_mask & MOD_MASK_CTRL) nv_goto(cap); else *************** *** 6535,6542 **** cap->count0 = 1; nv_pipe(cap); } ! ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a ! one-character line). */ } /* --- 6532,6539 ---- cap->count0 = 1; nv_pipe(cap); } ! ins_at_eol = FALSE; // Don't move cursor past eol (only necessary in a ! // one-character line). } /* *************** *** 6555,6562 **** } else curwin->w_curswant = 0; ! /* keep curswant at the column where we wanted to go, not where ! * we ended; differs if line is too short */ curwin->w_set_curswant = FALSE; } --- 6552,6559 ---- } else curwin->w_curswant = 0; ! // keep curswant at the column where we wanted to go, not where ! // we ended; differs if line is too short curwin->w_set_curswant = FALSE; } *************** *** 6605,6611 **** if (!word_end && cap->oap->op_type == OP_CHANGE) { n = gchar_cursor(); ! if (n != NUL) /* not an empty line */ { if (VIM_ISWHITE(n)) { --- 6602,6608 ---- if (!word_end && cap->oap->op_type == OP_CHANGE) { n = gchar_cursor(); ! if (n != NUL) // not an empty line { if (VIM_ISWHITE(n)) { *************** *** 6649,6656 **** else n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); ! /* Don't leave the cursor on the NUL past the end of line. Unless we ! * didn't move it forward. */ if (LT_POS(startpos, curwin->w_cursor)) adjust_cursor(cap->oap); --- 6646,6653 ---- else n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); ! // Don't leave the cursor on the NUL past the end of line. Unless we ! // didn't move it forward. if (LT_POS(startpos, curwin->w_cursor)) adjust_cursor(cap->oap); *************** *** 6674,6690 **** static void adjust_cursor(oparg_T *oap) { ! /* The cursor cannot remain on the NUL when: ! * - the column is > 0 ! * - not in Visual mode or 'selection' is "o" ! * - 'virtualedit' is not "all" and not "onemore". ! */ if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL && (!VIsual_active || *p_sel == 'o') && !virtual_active() && (ve_flags & VE_ONEMORE) == 0) { --curwin->w_cursor.col; ! /* prevent cursor from moving on the trail byte */ if (has_mbyte) mb_adjust_cursor(); oap->inclusive = TRUE; --- 6671,6686 ---- static void adjust_cursor(oparg_T *oap) { ! // The cursor cannot remain on the NUL when: ! // - the column is > 0 ! // - not in Visual mode or 'selection' is "o" ! // - 'virtualedit' is not "all" and not "onemore". if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL && (!VIsual_active || *p_sel == 'o') && !virtual_active() && (ve_flags & VE_ONEMORE) == 0) { --curwin->w_cursor.col; ! // prevent cursor from moving on the trail byte if (has_mbyte) mb_adjust_cursor(); oap->inclusive = TRUE; *************** *** 6705,6712 **** if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) foldOpenCursor(); #endif ! ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a ! one-character line). */ } /* --- 6701,6708 ---- if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) foldOpenCursor(); #endif ! ins_at_eol = FALSE; // Don't move cursor past eol (only necessary in a ! // one-character line). } /* *************** *** 6770,6776 **** VIsual_select = TRUE; else if (VIsual_reselect) { ! cap->nchar = 'v'; /* fake "gv" command */ cap->arg = TRUE; nv_g_cmd(cap); } --- 6766,6772 ---- VIsual_select = TRUE; else if (VIsual_reselect) { ! cap->nchar = 'v'; // fake "gv" command cap->arg = TRUE; nv_g_cmd(cap); } *************** *** 6793,6799 **** cap->oap->motion_type = MLINE; setpcmark(); ! /* When a count is given, use it instead of the default lnum */ if (cap->count0 != 0) lnum = cap->count0; if (lnum < 1L) --- 6789,6795 ---- cap->oap->motion_type = MLINE; setpcmark(); ! // When a count is given, use it instead of the default lnum if (cap->count0 != 0) lnum = cap->count0; if (lnum < 1L) *************** *** 6818,6824 **** { clearop(cap->oap); if (restart_edit != 0 && mode_displayed) ! clear_cmdline = TRUE; /* unshow mode later */ restart_edit = 0; #ifdef FEAT_CMDWIN if (cmdwin_type != 0) --- 6814,6820 ---- { clearop(cap->oap); if (restart_edit != 0 && mode_displayed) ! clear_cmdline = TRUE; // unshow mode later restart_edit = 0; #ifdef FEAT_CMDWIN if (cmdwin_type != 0) *************** *** 6826,6835 **** #endif if (VIsual_active) { ! end_visual_mode(); /* stop Visual */ redraw_curbuf_later(INVERTED); } ! /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ if (cap->nchar == Ctrl_G && p_im) restart_edit = 'a'; } --- 6822,6831 ---- #endif if (VIsual_active) { ! end_visual_mode(); // stop Visual redraw_curbuf_later(INVERTED); } ! // CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. if (cap->nchar == Ctrl_G && p_im) restart_edit = 'a'; } *************** *** 6852,6858 **** && cap->oap->regname == 0 && !p_im); ! if (cap->arg) /* TRUE for CTRL-C */ { if (restart_edit == 0 #ifdef FEAT_CMDWIN --- 6848,6854 ---- && cap->oap->regname == 0 && !p_im); ! if (cap->arg) // TRUE for CTRL-C { if (restart_edit == 0 #ifdef FEAT_CMDWIN *************** *** 6867,6881 **** msg(_("Type :qa and press to exit Vim")); } ! /* Don't reset "restart_edit" when 'insertmode' is set, it won't be ! * set again below when halfway a mapping. */ if (!p_im) restart_edit = 0; #ifdef FEAT_CMDWIN if (cmdwin_type != 0) { cmdwin_result = K_IGNORE; ! got_int = FALSE; /* don't stop executing autocommands et al. */ return; } #endif --- 6863,6877 ---- msg(_("Type :qa and press to exit Vim")); } ! // Don't reset "restart_edit" when 'insertmode' is set, it won't be ! // set again below when halfway a mapping. if (!p_im) restart_edit = 0; #ifdef FEAT_CMDWIN if (cmdwin_type != 0) { cmdwin_result = K_IGNORE; ! got_int = FALSE; // don't stop executing autocommands et al. return; } #endif *************** *** 6883,6890 **** if (VIsual_active) { ! end_visual_mode(); /* stop Visual */ ! check_cursor_col(); /* make sure cursor is not beyond EOL */ curwin->w_set_curswant = TRUE; redraw_curbuf_later(INVERTED); } --- 6879,6886 ---- if (VIsual_active) { ! end_visual_mode(); // stop Visual ! check_cursor_col(); // make sure cursor is not beyond EOL curwin->w_set_curswant = TRUE; redraw_curbuf_later(INVERTED); } *************** *** 6892,6899 **** vim_beep(BO_ESC); clearop(cap->oap); ! /* A CTRL-C is often used at the start of a menu. When 'insertmode' is ! * set return to Insert mode afterwards. */ if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) restart_edit = 'a'; } --- 6888,6895 ---- vim_beep(BO_ESC); clearop(cap->oap); ! // A CTRL-C is often used at the start of a menu. When 'insertmode' is ! // set return to Insert mode afterwards. if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) restart_edit = 'a'; } *************** *** 6909,6916 **** { int save_State = State; ! /* Pretend Insert mode here to allow the cursor on the ! * character past the end of the line */ State = INSERT; coladvance((colnr_T)MAXCOL); State = save_State; --- 6905,6912 ---- { int save_State = State; ! // Pretend Insert mode here to allow the cursor on the ! // character past the end of the line State = INSERT; coladvance((colnr_T)MAXCOL); State = save_State; *************** *** 6926,6936 **** static void nv_edit(cmdarg_T *cap) { ! /* is equal to "i" */ if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) cap->cmdchar = 'i'; ! /* in Visual mode "A" and "I" are an operator */ if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) { #ifdef FEAT_TERMINAL --- 6922,6932 ---- static void nv_edit(cmdarg_T *cap) { ! // is equal to "i" if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) cap->cmdchar = 'i'; ! // in Visual mode "A" and "I" are an operator if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) { #ifdef FEAT_TERMINAL *************** *** 6945,6951 **** v_visop(cap); } ! /* in Visual mode and after an operator "a" and "i" are for text objects */ else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') && (cap->oap->op_type != OP_NOP || VIsual_active)) { --- 6941,6947 ---- v_visop(cap); } ! // in Visual mode and after an operator "a" and "i" are for text objects else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') && (cap->oap->op_type != OP_NOP || VIsual_active)) { *************** *** 6965,6975 **** #endif else if (!curbuf->b_p_ma && !p_im) { ! /* Only give this error when 'insertmode' is off. */ emsg(_(e_modifiable)); clearop(cap->oap); if (cap->cmdchar == K_PS) ! /* drop the pasted text */ bracketed_paste(PASTE_INSERT, TRUE, NULL); } else if (cap->cmdchar == K_PS && VIsual_active) --- 6961,6971 ---- #endif else if (!curbuf->b_p_ma && !p_im) { ! // Only give this error when 'insertmode' is off. emsg(_(e_modifiable)); clearop(cap->oap); if (cap->cmdchar == K_PS) ! // drop the pasted text bracketed_paste(PASTE_INSERT, TRUE, NULL); } else if (cap->cmdchar == K_PS && VIsual_active) *************** *** 6977,6983 **** pos_T old_pos = curwin->w_cursor; pos_T old_visual = VIsual; ! /* In Visual mode the selected text is deleted. */ if (VIsual_mode == 'V' || curwin->w_cursor.lnum != VIsual.lnum) { shift_delete_registers(); --- 6973,6979 ---- pos_T old_pos = curwin->w_cursor; pos_T old_visual = VIsual; ! // In Visual mode the selected text is deleted. if (VIsual_mode == 'V' || curwin->w_cursor.lnum != VIsual.lnum) { shift_delete_registers(); *************** *** 6991,7014 **** do_pending_operator(cap, 0, FALSE); cap->cmdchar = K_PS; ! /* When the last char in the line was deleted then append. Detect this ! * by checking if the cursor moved to before the Visual area. */ if (*ml_get_cursor() != NUL && LT_POS(curwin->w_cursor, old_pos) && LT_POS(curwin->w_cursor, old_visual)) inc_cursor(); ! /* Insert to replace the deleted text with the pasted text. */ invoke_edit(cap, FALSE, cap->cmdchar, FALSE); } else if (!checkclearopq(cap->oap)) { switch (cap->cmdchar) { ! case 'A': /* "A"ppend after the line */ set_cursor_for_append_to_line(); break; ! case 'I': /* "I"nsert before the first non-blank */ if (vim_strchr(p_cpo, CPO_INSEND) == NULL) beginline(BL_WHITE); else --- 6987,7010 ---- do_pending_operator(cap, 0, FALSE); cap->cmdchar = K_PS; ! // When the last char in the line was deleted then append. Detect this ! // by checking if the cursor moved to before the Visual area. if (*ml_get_cursor() != NUL && LT_POS(curwin->w_cursor, old_pos) && LT_POS(curwin->w_cursor, old_visual)) inc_cursor(); ! // Insert to replace the deleted text with the pasted text. invoke_edit(cap, FALSE, cap->cmdchar, FALSE); } else if (!checkclearopq(cap->oap)) { switch (cap->cmdchar) { ! case 'A': // "A"ppend after the line set_cursor_for_append_to_line(); break; ! case 'I': // "I"nsert before the first non-blank if (vim_strchr(p_cpo, CPO_INSEND) == NULL) beginline(BL_WHITE); else *************** *** 7016,7030 **** break; case K_PS: ! /* Bracketed paste works like "a"ppend, unless the cursor is in ! * the first column, then it inserts. */ if (curwin->w_cursor.col == 0) break; ! /* FALLTHROUGH */ ! case 'a': /* "a"ppend is like "i"nsert on the next character. */ ! /* increment coladd when in virtual space, increment the ! * column otherwise, also to append after an unprintable char */ if (virtual_active() && (curwin->w_cursor.coladd > 0 || *ml_get_cursor() == NUL --- 7012,7026 ---- break; case K_PS: ! // Bracketed paste works like "a"ppend, unless the cursor is in ! // the first column, then it inserts. if (curwin->w_cursor.col == 0) break; ! // FALLTHROUGH ! case 'a': // "a"ppend is like "i"nsert on the next character. ! // increment coladd when in virtual space, increment the ! // column otherwise, also to append after an unprintable char if (virtual_active() && (curwin->w_cursor.coladd > 0 || *ml_get_cursor() == NUL *************** *** 7039,7046 **** { int save_State = State; ! /* Pretend Insert mode here to allow the cursor on the ! * character past the end of the line */ State = INSERT; coladvance(getviscol()); State = save_State; --- 7035,7042 ---- { int save_State = State; ! // Pretend Insert mode here to allow the cursor on the ! // character past the end of the line State = INSERT; coladvance(getviscol()); State = save_State; *************** *** 7049,7055 **** invoke_edit(cap, FALSE, cap->cmdchar, FALSE); } else if (cap->cmdchar == K_PS) ! /* drop the pasted text */ bracketed_paste(PASTE_INSERT, TRUE, NULL); } --- 7045,7051 ---- invoke_edit(cap, FALSE, cap->cmdchar, FALSE); } else if (cap->cmdchar == K_PS) ! // drop the pasted text bracketed_paste(PASTE_INSERT, TRUE, NULL); } *************** *** 7059,7079 **** static void invoke_edit( cmdarg_T *cap, ! int repl, /* "r" or "gr" command */ int cmd, int startln) { int restart_edit_save = 0; ! /* Complicated: When the user types "aa" we don't want to do Insert ! * mode recursively. But when doing "a." or "arx" we do allow ! * it. */ if (repl || !stuff_empty()) restart_edit_save = restart_edit; else restart_edit_save = 0; ! /* Always reset "restart_edit", this is not a restarted edit. */ restart_edit = 0; if (edit(cmd, startln, cap->count1)) --- 7055,7075 ---- static void invoke_edit( cmdarg_T *cap, ! int repl, // "r" or "gr" command int cmd, int startln) { int restart_edit_save = 0; ! // Complicated: When the user types "aa" we don't want to do Insert ! // mode recursively. But when doing "a." or "arx" we do allow ! // it. if (repl || !stuff_empty()) restart_edit_save = restart_edit; else restart_edit_save = 0; ! // Always reset "restart_edit", this is not a restarted edit. restart_edit = 0; if (edit(cmd, startln, cap->count1)) *************** *** 7096,7162 **** char_u *mps_save; if (cap->cmdchar == 'i') ! include = FALSE; /* "ix" = inner object: exclude white space */ else ! include = TRUE; /* "ax" = an object: include white space */ ! /* Make sure (), [], {} and <> are in 'matchpairs' */ mps_save = curbuf->b_p_mps; curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; switch (cap->nchar) { ! case 'w': /* "aw" = a word */ flag = current_word(cap->oap, cap->count1, include, FALSE); break; ! case 'W': /* "aW" = a WORD */ flag = current_word(cap->oap, cap->count1, include, TRUE); break; ! case 'b': /* "ab" = a braces block */ case '(': case ')': flag = current_block(cap->oap, cap->count1, include, '(', ')'); break; ! case 'B': /* "aB" = a Brackets block */ case '{': case '}': flag = current_block(cap->oap, cap->count1, include, '{', '}'); break; ! case '[': /* "a[" = a [] block */ case ']': flag = current_block(cap->oap, cap->count1, include, '[', ']'); break; ! case '<': /* "a<" = a <> block */ case '>': flag = current_block(cap->oap, cap->count1, include, '<', '>'); break; ! case 't': /* "at" = a tag block (xml and html) */ ! /* Do not adjust oap->end in do_pending_operator() ! * otherwise there are different results for 'dit' ! * (note leading whitespace in last line): ! * 1) 2) ! * foobar foobar ! * ! */ cap->retval |= CA_NO_ADJ_OP_END; flag = current_tagblock(cap->oap, cap->count1, include); break; ! case 'p': /* "ap" = a paragraph */ flag = current_par(cap->oap, cap->count1, include, 'p'); break; ! case 's': /* "as" = a sentence */ flag = current_sent(cap->oap, cap->count1, include); break; ! case '"': /* "a"" = a double quoted string */ ! case '\'': /* "a'" = a single quoted string */ ! case '`': /* "a`" = a backtick quoted string */ flag = current_quote(cap->oap, cap->count1, include, cap->nchar); break; ! #if 0 /* TODO */ ! case 'S': /* "aS" = a section */ ! case 'f': /* "af" = a filename */ ! case 'u': /* "au" = a URL */ #endif default: flag = FAIL; --- 7092,7157 ---- char_u *mps_save; if (cap->cmdchar == 'i') ! include = FALSE; // "ix" = inner object: exclude white space else ! include = TRUE; // "ax" = an object: include white space ! // Make sure (), [], {} and <> are in 'matchpairs' mps_save = curbuf->b_p_mps; curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; switch (cap->nchar) { ! case 'w': // "aw" = a word flag = current_word(cap->oap, cap->count1, include, FALSE); break; ! case 'W': // "aW" = a WORD flag = current_word(cap->oap, cap->count1, include, TRUE); break; ! case 'b': // "ab" = a braces block case '(': case ')': flag = current_block(cap->oap, cap->count1, include, '(', ')'); break; ! case 'B': // "aB" = a Brackets block case '{': case '}': flag = current_block(cap->oap, cap->count1, include, '{', '}'); break; ! case '[': // "a[" = a [] block case ']': flag = current_block(cap->oap, cap->count1, include, '[', ']'); break; ! case '<': // "a<" = a <> block case '>': flag = current_block(cap->oap, cap->count1, include, '<', '>'); break; ! case 't': // "at" = a tag block (xml and html) ! // Do not adjust oap->end in do_pending_operator() ! // otherwise there are different results for 'dit' ! // (note leading whitespace in last line): ! // 1) 2) ! // foobar foobar ! // cap->retval |= CA_NO_ADJ_OP_END; flag = current_tagblock(cap->oap, cap->count1, include); break; ! case 'p': // "ap" = a paragraph flag = current_par(cap->oap, cap->count1, include, 'p'); break; ! case 's': // "as" = a sentence flag = current_sent(cap->oap, cap->count1, include); break; ! case '"': // "a"" = a double quoted string ! case '\'': // "a'" = a single quoted string ! case '`': // "a`" = a backtick quoted string flag = current_quote(cap->oap, cap->count1, include, cap->nchar); break; ! #if 0 // TODO ! case 'S': // "aS" = a section ! case 'f': // "af" = a filename ! case 'u': // "au" = a URL #endif default: flag = FAIL; *************** *** 7180,7186 **** { if (cap->oap->op_type == OP_FORMAT) { ! /* "gqq" is the same as "gqgq": format line */ cap->cmdchar = 'g'; cap->nchar = 'q'; nv_operator(cap); --- 7175,7181 ---- { if (cap->oap->op_type == OP_FORMAT) { ! // "gqq" is the same as "gqgq": format line cap->cmdchar = 'g'; cap->nchar = 'q'; nv_operator(cap); *************** *** 7195,7202 **** } else #endif ! /* (stop) recording into a named register, unless executing a ! * register */ if (reg_executing == 0 && do_record(cap->nchar) == FAIL) clearopbeep(cap->oap); } --- 7190,7197 ---- } else #endif ! // (stop) recording into a named register, unless executing a ! // register if (reg_executing == 0 && do_record(cap->nchar) == FAIL) clearopbeep(cap->oap); } *************** *** 7248,7263 **** static void nv_join(cmdarg_T *cap) { ! if (VIsual_active) /* join the visual lines */ nv_operator(cap); else if (!checkclearop(cap->oap)) { if (cap->count0 <= 1) ! cap->count0 = 2; /* default for join is two lines! */ if (curwin->w_cursor.lnum + cap->count0 - 1 > curbuf->b_ml.ml_line_count) { ! /* can't join when on the last line */ if (cap->count0 <= 2) { clearopbeep(cap->oap); --- 7243,7258 ---- static void nv_join(cmdarg_T *cap) { ! if (VIsual_active) // join the visual lines nv_operator(cap); else if (!checkclearop(cap->oap)) { if (cap->count0 <= 1) ! cap->count0 = 2; // default for join is two lines! if (curwin->w_cursor.lnum + cap->count0 - 1 > curbuf->b_ml.ml_line_count) { ! // can't join when on the last line if (cap->count0 <= 2) { clearopbeep(cap->oap); *************** *** 7299,7305 **** if (cap->oap->op_type != OP_NOP) { #ifdef FEAT_DIFF ! /* "dp" is ":diffput" */ if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') { clearop(cap->oap); --- 7294,7300 ---- if (cap->oap->op_type != OP_NOP) { #ifdef FEAT_DIFF ! // "dp" is ":diffput" if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') { clearop(cap->oap); *************** *** 7333,7343 **** if (VIsual_active) { ! /* Putting in Visual mode: The put text replaces the selected ! * text. First delete the selected text, then put the new text. ! * Need to save and restore the registers that the delete ! * overwrites if the old contents is being put. ! */ was_visual = TRUE; regname = cap->oap->regname; #ifdef FEAT_CLIPBOARD --- 7328,7337 ---- if (VIsual_active) { ! // Putting in Visual mode: The put text replaces the selected ! // text. First delete the selected text, then put the new text. ! // Need to save and restore the registers that the delete ! // overwrites if the old contents is being put. was_visual = TRUE; regname = cap->oap->regname; #ifdef FEAT_CLIPBOARD *************** *** 7351,7358 **** ) { ! /* The delete is going to overwrite the register we want to ! * put, save it first. */ reg1 = get_register(regname, TRUE); } --- 7345,7352 ---- ) { ! // The delete is going to overwrite the register we want to ! // put, save it first. reg1 = get_register(regname, TRUE); } *************** *** 7366,7385 **** empty = (curbuf->b_ml.ml_flags & ML_EMPTY); --msg_silent; ! /* delete PUT_LINE_BACKWARD; */ cap->oap->regname = regname; if (reg1 != NULL) { ! /* Delete probably changed the register we want to put, save ! * it first. Then put back what was there before the delete. */ reg2 = get_register(regname, FALSE); put_register(regname, reg1); } ! /* When deleted a linewise Visual area, put the register as ! * lines to avoid it joined with the next line. When deletion was ! * characterwise, split a line when putting lines. */ if (VIsual_mode == 'V') flags |= PUT_LINE; else if (VIsual_mode == 'v') --- 7360,7379 ---- empty = (curbuf->b_ml.ml_flags & ML_EMPTY); --msg_silent; ! // delete PUT_LINE_BACKWARD; cap->oap->regname = regname; if (reg1 != NULL) { ! // Delete probably changed the register we want to put, save ! // it first. Then put back what was there before the delete. reg2 = get_register(regname, FALSE); put_register(regname, reg1); } ! // When deleted a linewise Visual area, put the register as ! // lines to avoid it joined with the next line. When deletion was ! // characterwise, split a line when putting lines. if (VIsual_mode == 'V') flags |= PUT_LINE; else if (VIsual_mode == 'v') *************** *** 7391,7428 **** && curwin->w_cursor.col < curbuf->b_op_start.col) || (VIsual_mode == 'V' && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) ! /* cursor is at the end of the line or end of file, put ! * forward. */ dir = FORWARD; ! /* May have been reset in do_put(). */ VIsual_active = TRUE; } do_put(cap->oap->regname, dir, cap->count1, flags); ! /* If a register was saved, put it back now. */ if (reg2 != NULL) put_register(regname, reg2); ! /* What to reselect with "gv"? Selecting the just put text seems to ! * be the most useful, since the original text was removed. */ if (was_visual) { curbuf->b_visual.vi_start = curbuf->b_op_start; curbuf->b_visual.vi_end = curbuf->b_op_end; ! /* need to adjust cursor position */ if (*p_sel == 'e') inc(&curbuf->b_visual.vi_end); } ! /* When all lines were selected and deleted do_put() leaves an empty ! * line that needs to be deleted now. */ if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) { ml_delete(curbuf->b_ml.ml_line_count, TRUE); deleted_lines(curbuf->b_ml.ml_line_count + 1, 1); ! /* If the cursor was in that line, move it to the end of the last ! * line. */ if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; --- 7385,7422 ---- && curwin->w_cursor.col < curbuf->b_op_start.col) || (VIsual_mode == 'V' && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) ! // cursor is at the end of the line or end of file, put ! // forward. dir = FORWARD; ! // May have been reset in do_put(). VIsual_active = TRUE; } do_put(cap->oap->regname, dir, cap->count1, flags); ! // If a register was saved, put it back now. if (reg2 != NULL) put_register(regname, reg2); ! // What to reselect with "gv"? Selecting the just put text seems to ! // be the most useful, since the original text was removed. if (was_visual) { curbuf->b_visual.vi_start = curbuf->b_op_start; curbuf->b_visual.vi_end = curbuf->b_op_end; ! // need to adjust cursor position if (*p_sel == 'e') inc(&curbuf->b_visual.vi_end); } ! // When all lines were selected and deleted do_put() leaves an empty ! // line that needs to be deleted now. if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) { ml_delete(curbuf->b_ml.ml_line_count, TRUE); deleted_lines(curbuf->b_ml.ml_line_count + 1, 1); ! // If the cursor was in that line, move it to the end of the last ! // line. if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; *************** *** 7440,7446 **** nv_open(cmdarg_T *cap) { #ifdef FEAT_DIFF ! /* "do" is ":diffget" */ if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') { clearop(cap->oap); --- 7434,7440 ---- nv_open(cmdarg_T *cap) { #ifdef FEAT_DIFF ! // "do" is ":diffget" if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') { clearop(cap->oap); *************** *** 7448,7454 **** } else #endif ! if (VIsual_active) /* switch start and end of visual */ v_swap_corners(cap->cmdchar); #ifdef FEAT_JOB_CHANNEL else if (bt_prompt(curbuf)) --- 7442,7448 ---- } else #endif ! if (VIsual_active) // switch start and end of visual v_swap_corners(cap->cmdchar); #ifdef FEAT_JOB_CHANNEL else if (bt_prompt(curbuf)) *************** *** 7484,7488 **** { apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); did_cursorhold = TRUE; ! cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ } --- 7478,7482 ---- { apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); did_cursorhold = TRUE; ! cap->retval |= CA_COMMAND_BUSY; // don't call edit() now } *** ../vim-8.1.2391/src/ops.c 2019-11-30 22:47:42.651331201 +0100 --- src/ops.c 2019-12-05 20:07:52.552942849 +0100 *************** *** 72,84 **** { int i; ! if (char1 == 'r') /* ignore second character */ return OP_REPLACE; ! if (char1 == '~') /* when tilde is an operator */ return OP_TILDE; ! if (char1 == 'g' && char2 == Ctrl_A) /* add */ return OP_NR_ADD; ! if (char1 == 'g' && char2 == Ctrl_X) /* subtract */ return OP_NR_SUB; for (i = 0; ; ++i) { --- 72,84 ---- { int i; ! if (char1 == 'r') // ignore second character return OP_REPLACE; ! if (char1 == '~') // when tilde is an operator return OP_TILDE; ! if (char1 == 'g' && char2 == Ctrl_A) // add return OP_NR_ADD; ! if (char1 == 'g' && char2 == Ctrl_X) // subtract return OP_NR_SUB; for (i = 0; ; ++i) { *************** *** 152,164 **** for (i = oap->line_count; --i >= 0; ) { first_char = *ml_get_curline(); ! if (first_char == NUL) /* empty line */ curwin->w_cursor.col = 0; else if (oap->block_mode) shift_block(oap, amount); else ! /* Move the line right if it doesn't start with '#', 'smartindent' ! * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) if (first_char != '#' || !preprocs_left()) #endif --- 152,164 ---- for (i = oap->line_count; --i >= 0; ) { first_char = *ml_get_curline(); ! if (first_char == NUL) // empty line curwin->w_cursor.col = 0; else if (oap->block_mode) shift_block(oap, amount); else ! // Move the line right if it doesn't start with '#', 'smartindent' ! // isn't set or 'cindent' isn't set or '#' isn't in 'cino'. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) if (first_char != '#' || !preprocs_left()) #endif *************** *** 172,187 **** curwin->w_cursor.lnum = oap->start.lnum; curwin->w_cursor.col = block_col; } ! else if (curs_top) /* put cursor on first line, for ">>" */ { curwin->w_cursor.lnum = oap->start.lnum; ! beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ } else ! --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ #ifdef FEAT_FOLDING ! /* The cursor line is not in a closed fold */ foldOpenCursor(); #endif --- 172,187 ---- curwin->w_cursor.lnum = oap->start.lnum; curwin->w_cursor.col = block_col; } ! else if (curs_top) // put cursor on first line, for ">>" { curwin->w_cursor.lnum = oap->start.lnum; ! beginline(BL_SOL | BL_FIX); // shift_line() may have set cursor.col } else ! --curwin->w_cursor.lnum; // put cursor on last line, for ":>" #ifdef FEAT_FOLDING ! // The cursor line is not in a closed fold foldOpenCursor(); #endif *************** *** 291,308 **** #ifdef FEAT_RIGHTLEFT int old_p_ri = p_ri; ! p_ri = 0; /* don't want revins in indent */ #endif ! State = INSERT; /* don't want REPLACE for State */ block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); if (bd.is_short) return; ! /* total is number of screen columns to be inserted/removed */ total = (int)((unsigned)amount * (unsigned)sw_val); if ((total / sw_val) != amount) ! return; /* multiplication overflow */ oldp = ml_get_curline(); --- 291,308 ---- #ifdef FEAT_RIGHTLEFT int old_p_ri = p_ri; ! p_ri = 0; // don't want revins in indent #endif ! State = INSERT; // don't want REPLACE for State block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); if (bd.is_short) return; ! // total is number of screen columns to be inserted/removed total = (int)((unsigned)amount * (unsigned)sw_val); if ((total / sw_val) != amount) ! return; // multiplication overflow oldp = ml_get_curline(); *************** *** 314,320 **** * 3. Divvy into TABs & spp * 4. Construct new string */ ! total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ ws_vcol = bd.start_vcol - bd.pre_whitesp; if (bd.startspaces) { --- 314,320 ---- * 3. Divvy into TABs & spp * 4. Construct new string */ ! total += bd.pre_whitesp; // all virtual WS upto & incl a split TAB ws_vcol = bd.start_vcol - bd.pre_whitesp; if (bd.startspaces) { *************** *** 333,346 **** } for ( ; VIM_ISWHITE(*bd.textstart); ) { ! /* TODO: is passing bd.textstart for start of the line OK? */ incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, (colnr_T)(bd.start_vcol)); total += incr; bd.start_vcol += incr; } ! /* OK, now total=all the VWS reqd, and textstart points at the 1st ! * non-ws char in the block. */ #ifdef FEAT_VARTABS if (!curbuf->b_p_et) tabstop_fromto(ws_vcol, ws_vcol + total, --- 333,346 ---- } for ( ; VIM_ISWHITE(*bd.textstart); ) { ! // TODO: is passing bd.textstart for start of the line OK? incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, (colnr_T)(bd.start_vcol)); total += incr; bd.start_vcol += incr; } ! // OK, now total=all the VWS reqd, and textstart points at the 1st ! // non-ws char in the block. #ifdef FEAT_VARTABS if (!curbuf->b_p_et) tabstop_fromto(ws_vcol, ws_vcol + total, *************** *** 349,361 **** j = total; #else if (!curbuf->b_p_et) ! i = ((ws_vcol % ts_val) + total) / ts_val; /* number of tabs */ if (i) ! j = ((ws_vcol % ts_val) + total) % ts_val; /* number of spp */ else j = total; #endif ! /* if we're splitting a TAB, allow for it */ bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); len = (int)STRLEN(bd.textstart) + 1; newp = alloc(bd.textcol + i + j + len); --- 349,361 ---- j = total; #else if (!curbuf->b_p_et) ! i = ((ws_vcol % ts_val) + total) / ts_val; // number of tabs if (i) ! j = ((ws_vcol % ts_val) + total) % ts_val; // number of spp else j = total; #endif ! // if we're splitting a TAB, allow for it bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); len = (int)STRLEN(bd.textstart) + 1; newp = alloc(bd.textcol + i + j + len); *************** *** 365,384 **** mch_memmove(newp, oldp, (size_t)bd.textcol); vim_memset(newp + bd.textcol, TAB, (size_t)i); vim_memset(newp + bd.textcol + i, ' ', (size_t)j); ! /* the end */ mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); } ! else /* left */ { ! colnr_T destination_col; /* column to which text in block will ! be shifted */ ! char_u *verbatim_copy_end; /* end of the part of the line which is ! copied verbatim */ ! colnr_T verbatim_copy_width;/* the (displayed) width of this part ! of line */ ! unsigned fill; /* nr of spaces that replace a TAB */ ! unsigned new_line_len; /* the length of the line after the ! block shift */ size_t block_space_width; size_t shift_amount; char_u *non_white = bd.textstart; --- 365,384 ---- mch_memmove(newp, oldp, (size_t)bd.textcol); vim_memset(newp + bd.textcol, TAB, (size_t)i); vim_memset(newp + bd.textcol + i, ' ', (size_t)j); ! // the end mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); } ! else // left { ! colnr_T destination_col; // column to which text in block will ! // be shifted ! char_u *verbatim_copy_end; // end of the part of the line which is ! // copied verbatim ! colnr_T verbatim_copy_width;// the (displayed) width of this part ! // of line ! unsigned fill; // nr of spaces that replace a TAB ! unsigned new_line_len; // the length of the line after the ! // block shift size_t block_space_width; size_t shift_amount; char_u *non_white = bd.textstart; *************** *** 392,404 **** * non-whitespace character. */ ! /* If "bd.startspaces" is set, "bd.textstart" points to the character, ! * the part of which is displayed at the block's beginning. Let's start ! * searching from the next character. */ if (bd.startspaces) MB_PTR_ADV(non_white); ! /* The character's column is in "bd.start_vcol". */ non_white_col = bd.start_vcol; while (VIM_ISWHITE(*non_white)) --- 392,404 ---- * non-whitespace character. */ ! // If "bd.startspaces" is set, "bd.textstart" points to the character, ! // the part of which is displayed at the block's beginning. Let's start ! // searching from the next character. if (bd.startspaces) MB_PTR_ADV(non_white); ! // The character's column is in "bd.start_vcol". non_white_col = bd.start_vcol; while (VIM_ISWHITE(*non_white)) *************** *** 408,436 **** } block_space_width = non_white_col - oap->start_vcol; ! /* We will shift by "total" or "block_space_width", whichever is less. ! */ shift_amount = (block_space_width < (size_t)total ? block_space_width : (size_t)total); ! /* The column to which we will shift the text. */ destination_col = (colnr_T)(non_white_col - shift_amount); ! /* Now let's find out how much of the beginning of the line we can ! * reuse without modification. */ verbatim_copy_end = bd.textstart; verbatim_copy_width = bd.start_vcol; ! /* If "bd.startspaces" is set, "bd.textstart" points to the character ! * preceding the block. We have to subtract its width to obtain its ! * column number. */ if (bd.startspaces) verbatim_copy_width -= bd.start_char_vcols; while (verbatim_copy_width < destination_col) { char_u *line = verbatim_copy_end; ! /* TODO: is passing verbatim_copy_end for start of the line OK? */ incr = lbr_chartabsize(line, verbatim_copy_end, verbatim_copy_width); if (verbatim_copy_width + incr > destination_col) --- 408,435 ---- } block_space_width = non_white_col - oap->start_vcol; ! // We will shift by "total" or "block_space_width", whichever is less. shift_amount = (block_space_width < (size_t)total ? block_space_width : (size_t)total); ! // The column to which we will shift the text. destination_col = (colnr_T)(non_white_col - shift_amount); ! // Now let's find out how much of the beginning of the line we can ! // reuse without modification. verbatim_copy_end = bd.textstart; verbatim_copy_width = bd.start_vcol; ! // If "bd.startspaces" is set, "bd.textstart" points to the character ! // preceding the block. We have to subtract its width to obtain its ! // column number. if (bd.startspaces) verbatim_copy_width -= bd.start_char_vcols; while (verbatim_copy_width < destination_col) { char_u *line = verbatim_copy_end; ! // TODO: is passing verbatim_copy_end for start of the line OK? incr = lbr_chartabsize(line, verbatim_copy_end, verbatim_copy_width); if (verbatim_copy_width + incr > destination_col) *************** *** 439,453 **** MB_PTR_ADV(verbatim_copy_end); } ! /* If "destination_col" is different from the width of the initial ! * part of the line that will be copied, it means we encountered a tab ! * character, which we will have to partly replace with spaces. */ fill = destination_col - verbatim_copy_width; ! /* The replacement line will consist of: ! * - the beginning of the original line up to "verbatim_copy_end", ! * - "fill" number of spaces, ! * - the rest of the line, pointed to by non_white. */ new_line_len = (unsigned)(verbatim_copy_end - oldp) + fill + (unsigned)STRLEN(non_white) + 1; --- 438,452 ---- MB_PTR_ADV(verbatim_copy_end); } ! // If "destination_col" is different from the width of the initial ! // part of the line that will be copied, it means we encountered a tab ! // character, which we will have to partly replace with spaces. fill = destination_col - verbatim_copy_width; ! // The replacement line will consist of: ! // - the beginning of the original line up to "verbatim_copy_end", ! // - "fill" number of spaces, ! // - the rest of the line, pointed to by non_white. new_line_len = (unsigned)(verbatim_copy_end - oldp) + fill + (unsigned)STRLEN(non_white) + 1; *************** *** 459,465 **** vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); } ! /* replace the line */ ml_replace(curwin->w_cursor.lnum, newp, FALSE); changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); State = oldstate; --- 458,464 ---- vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); } ! // replace the line ml_replace(curwin->w_cursor.lnum, newp, FALSE); changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); State = oldstate; *************** *** 481,502 **** struct block_def *bdp) { int ts_val; ! int count = 0; /* extra spaces to replace a cut TAB */ ! int spaces = 0; /* non-zero if cutting a TAB */ ! colnr_T offset; /* pointer along new line */ ! unsigned s_len; /* STRLEN(s) */ ! char_u *newp, *oldp; /* new, old lines */ ! linenr_T lnum; /* loop var */ int oldstate = State; ! State = INSERT; /* don't want REPLACE for State */ s_len = (unsigned)STRLEN(s); for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) { block_prep(oap, bdp, lnum, TRUE); if (bdp->is_short && b_insert) ! continue; /* OP_INSERT, line ends before block start */ oldp = ml_get(lnum); --- 480,501 ---- struct block_def *bdp) { int ts_val; ! int count = 0; // extra spaces to replace a cut TAB ! int spaces = 0; // non-zero if cutting a TAB ! colnr_T offset; // pointer along new line ! unsigned s_len; // STRLEN(s) ! char_u *newp, *oldp; // new, old lines ! linenr_T lnum; // loop var int oldstate = State; ! State = INSERT; // don't want REPLACE for State s_len = (unsigned)STRLEN(s); for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) { block_prep(oap, bdp, lnum, TRUE); if (bdp->is_short && b_insert) ! continue; // OP_INSERT, line ends before block start oldp = ml_get(lnum); *************** *** 505,526 **** ts_val = bdp->start_char_vcols; spaces = bdp->startspaces; if (spaces != 0) ! count = ts_val - 1; /* we're cutting a TAB */ offset = bdp->textcol; } ! else /* append */ { ts_val = bdp->end_char_vcols; ! if (!bdp->is_short) /* spaces = padding after block */ { spaces = (bdp->endspaces ? ts_val - bdp->endspaces : 0); if (spaces != 0) ! count = ts_val - 1; /* we're cutting a TAB */ offset = bdp->textcol + bdp->textlen - (spaces != 0); } ! else /* spaces = padding to block edge */ { ! /* if $ used, just append to EOL (ie spaces==0) */ if (!bdp->is_MAX) spaces = (oap->end_vcol - bdp->end_vcol) + 1; count = spaces; --- 504,525 ---- ts_val = bdp->start_char_vcols; spaces = bdp->startspaces; if (spaces != 0) ! count = ts_val - 1; // we're cutting a TAB offset = bdp->textcol; } ! else // append { ts_val = bdp->end_char_vcols; ! if (!bdp->is_short) // spaces = padding after block { spaces = (bdp->endspaces ? ts_val - bdp->endspaces : 0); if (spaces != 0) ! count = ts_val - 1; // we're cutting a TAB offset = bdp->textcol + bdp->textlen - (spaces != 0); } ! else // spaces = padding to block edge { ! // if $ used, just append to EOL (ie spaces==0) if (!bdp->is_MAX) spaces = (oap->end_vcol - bdp->end_vcol) + 1; count = spaces; *************** *** 532,538 **** { int off; ! /* Avoid starting halfway a multi-byte character. */ if (b_insert) { off = (*mb_head_off)(oldp, oldp + offset + spaces); --- 531,537 ---- { int off; ! // Avoid starting halfway a multi-byte character. if (b_insert) { off = (*mb_head_off)(oldp, oldp + offset + spaces); *************** *** 550,573 **** if (newp == NULL) continue; ! /* copy up to shifted part */ mch_memmove(newp, oldp, (size_t)(offset)); oldp += offset; ! /* insert pre-padding */ vim_memset(newp + offset, ' ', (size_t)spaces); ! /* copy the new text */ mch_memmove(newp + offset + spaces, s, (size_t)s_len); offset += s_len; if (spaces && !bdp->is_short) { ! /* insert post-padding */ vim_memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces)); ! /* We're splitting a TAB, don't copy it. */ oldp++; ! /* We allowed for that TAB, remember this now */ count++; } --- 549,572 ---- if (newp == NULL) continue; ! // copy up to shifted part mch_memmove(newp, oldp, (size_t)(offset)); oldp += offset; ! // insert pre-padding vim_memset(newp + offset, ' ', (size_t)spaces); ! // copy the new text mch_memmove(newp + offset + spaces, s, (size_t)s_len); offset += s_len; if (spaces && !bdp->is_short) { ! // insert post-padding vim_memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces)); ! // We're splitting a TAB, don't copy it. oldp++; ! // We allowed for that TAB, remember this now count++; } *************** *** 579,590 **** if (lnum == oap->end.lnum) { ! /* Set "']" mark to the end of the block instead of the end of ! * the insert in the first line. */ curbuf->b_op_end.lnum = oap->end.lnum; curbuf->b_op_end.col = offset; } ! } /* for all lnum */ changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); --- 578,589 ---- if (lnum == oap->end.lnum) { ! // Set "']" mark to the end of the block instead of the end of ! // the insert in the first line. curbuf->b_op_end.lnum = oap->end.lnum; curbuf->b_op_end.col = offset; } ! } // for all lnum changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); *************** *** 603,615 **** while (*arg != NUL) { ! /* Stuff a sequence of normal ASCII characters, that's fast. Also ! * stuff K_SPECIAL to get the effect of a special key when "literally" ! * is TRUE. */ start = arg; while ((*arg >= ' ' #ifndef EBCDIC ! && *arg < DEL /* EBCDIC: chars above space are normal */ #endif ) || (*arg == K_SPECIAL && !literally)) --- 602,614 ---- while (*arg != NUL) { ! // Stuff a sequence of normal ASCII characters, that's fast. Also ! // stuff K_SPECIAL to get the effect of a special key when "literally" ! // is TRUE. start = arg; while ((*arg >= ' ' #ifndef EBCDIC ! && *arg < DEL // EBCDIC: chars above space are normal #endif ) || (*arg == K_SPECIAL && !literally)) *************** *** 617,623 **** if (arg > start) stuffReadbuffLen(start, (long)(arg - start)); ! /* stuff a single special character */ if (*arg != NUL) { if (has_mbyte) --- 616,622 ---- if (arg > start) stuffReadbuffLen(start, (long)(arg - start)); ! // stuff a single special character if (*arg != NUL) { if (has_mbyte) *************** *** 647,656 **** linenr_T old_lcount = curbuf->b_ml.ml_line_count; int did_yank = FALSE; ! if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ return OK; ! /* Nothing to delete, return here. Do prepare undo, for op_change(). */ if (oap->empty) return u_save_cursor(); --- 646,655 ---- linenr_T old_lcount = curbuf->b_ml.ml_line_count; int did_yank = FALSE; ! if (curbuf->b_ml.ml_flags & ML_EMPTY) // nothing to do return OK; ! // Nothing to delete, return here. Do prepare undo, for op_change(). if (oap->empty) return u_save_cursor(); *************** *** 701,708 **** * 'cpoptions' (Vi compatible). */ if (virtual_op) ! /* Virtual editing: Nothing gets deleted, but we set the '[ and '] ! * marks as if it happened. */ goto setmarks; if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) beep_flush(); --- 700,707 ---- * 'cpoptions' (Vi compatible). */ if (virtual_op) ! // Virtual editing: Nothing gets deleted, but we set the '[ and '] ! // marks as if it happened. goto setmarks; if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) beep_flush(); *************** *** 718,731 **** { if (oap->regname != 0) { ! /* check for read-only register */ if (!valid_yank_reg(oap->regname, TRUE)) { beep_flush(); return OK; } ! get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ ! if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ did_yank = TRUE; } --- 717,730 ---- { if (oap->regname != 0) { ! // check for read-only register if (!valid_yank_reg(oap->regname, TRUE)) { beep_flush(); return OK; } ! get_yank_register(oap->regname, TRUE); // yank into specif'd reg. ! if (op_yank(oap, TRUE, FALSE) == OK) // yank without message did_yank = TRUE; } *************** *** 744,751 **** did_yank = TRUE; } ! /* Yank into small delete register when no named register specified ! * and the delete is within one line. */ if (( #ifdef FEAT_CLIPBOARD ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || --- 743,750 ---- did_yank = TRUE; } ! // Yank into small delete register when no named register specified ! // and the delete is within one line. if (( #ifdef FEAT_CLIPBOARD ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || *************** *** 771,777 **** { int msg_silent_save = msg_silent; ! msg_silent = 0; /* must display the prompt */ n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); msg_silent = msg_silent_save; if (n != 'y') --- 770,776 ---- { int msg_silent_save = msg_silent; ! msg_silent = 0; // must display the prompt n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); msg_silent = msg_silent_save; if (n != 'y') *************** *** 799,808 **** for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) { block_prep(oap, &bd, lnum, TRUE); ! if (bd.textlen == 0) /* nothing to delete */ continue; ! /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ if (lnum == curwin->w_cursor.lnum) { curwin->w_cursor.col = bd.textcol + bd.startspaces; --- 798,807 ---- for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) { block_prep(oap, &bd, lnum, TRUE); ! if (bd.textlen == 0) // nothing to delete continue; ! // Adjust cursor position for tab replaced by spaces and 'lbr'. if (lnum == curwin->w_cursor.lnum) { curwin->w_cursor.col = bd.textcol + bd.startspaces; *************** *** 817,831 **** newp = alloc(STRLEN(oldp) + 1 - n); if (newp == NULL) continue; ! /* copy up to deleted part */ mch_memmove(newp, oldp, (size_t)bd.textcol); ! /* insert spaces */ vim_memset(newp + bd.textcol, ' ', (size_t)(bd.startspaces + bd.endspaces)); ! /* copy the part after the deleted part */ oldp += bd.textcol + bd.textlen; STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); ! /* replace the line */ ml_replace(lnum, newp, FALSE); #ifdef FEAT_PROP_POPUP --- 816,830 ---- newp = alloc(STRLEN(oldp) + 1 - n); if (newp == NULL) continue; ! // copy up to deleted part mch_memmove(newp, oldp, (size_t)bd.textcol); ! // insert spaces vim_memset(newp + bd.textcol, ' ', (size_t)(bd.startspaces + bd.endspaces)); ! // copy the part after the deleted part oldp += bd.textcol + bd.textlen; STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); ! // replace the line ml_replace(lnum, newp, FALSE); #ifdef FEAT_PROP_POPUP *************** *** 837,852 **** check_cursor_col(); changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, oap->end.lnum + 1, 0L); ! oap->line_count = 0; /* no lines deleted */ } else if (oap->motion_type == MLINE) { if (oap->op_type == OP_CHANGE) { ! /* Delete the lines except the first one. Temporarily move the ! * cursor to the next line. Save the current line number, if the ! * last line is deleted it may be changed. ! */ if (oap->line_count > 1) { lnum = curwin->w_cursor.lnum; --- 836,850 ---- check_cursor_col(); changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, oap->end.lnum + 1, 0L); ! oap->line_count = 0; // no lines deleted } else if (oap->motion_type == MLINE) { if (oap->op_type == OP_CHANGE) { ! // Delete the lines except the first one. Temporarily move the ! // cursor to the next line. Save the current line number, if the ! // last line is deleted it may be changed. if (oap->line_count > 1) { lnum = curwin->w_cursor.lnum; *************** *** 856,879 **** } if (u_save_cursor() == FAIL) return FAIL; ! if (curbuf->b_p_ai) /* don't delete indent */ { ! beginline(BL_WHITE); /* cursor on first non-white */ ! did_ai = TRUE; /* delete the indent when ESC hit */ ai_col = curwin->w_cursor.col; } else ! beginline(0); /* cursor in column 0 */ ! truncate_line(FALSE); /* delete the rest of the line */ ! /* leave cursor past last char in line */ if (oap->line_count > 1) ! u_clearline(); /* "U" command not possible after "2cc" */ } else { del_lines(oap->line_count, TRUE); beginline(BL_WHITE | BL_FIX); ! u_clearline(); /* "U" command not possible after "dd" */ } } else --- 854,877 ---- } if (u_save_cursor() == FAIL) return FAIL; ! if (curbuf->b_p_ai) // don't delete indent { ! beginline(BL_WHITE); // cursor on first non-white ! did_ai = TRUE; // delete the indent when ESC hit ai_col = curwin->w_cursor.col; } else ! beginline(0); // cursor in column 0 ! truncate_line(FALSE); // delete the rest of the line ! // leave cursor past last char in line if (oap->line_count > 1) ! u_clearline(); // "U" command not possible after "2cc" } else { del_lines(oap->line_count, TRUE); beginline(BL_WHITE | BL_FIX); ! u_clearline(); // "U" command not possible after "dd" } } else *************** *** 882,891 **** { int endcol = 0; ! /* For virtualedit: break the tabs that are partly included. */ if (gchar_pos(&oap->start) == '\t') { ! if (u_save_cursor() == FAIL) /* save first line for undo */ return FAIL; if (oap->line_count == 1) endcol = getviscol2(oap->end.col, oap->end.coladd); --- 880,889 ---- { int endcol = 0; ! // For virtualedit: break the tabs that are partly included. if (gchar_pos(&oap->start) == '\t') { ! if (u_save_cursor() == FAIL) // save first line for undo return FAIL; if (oap->line_count == 1) endcol = getviscol2(oap->end.col, oap->end.coladd); *************** *** 900,910 **** } } ! /* Break a tab only when it's included in the area. */ if (gchar_pos(&oap->end) == '\t' && (int)oap->end.coladd < oap->inclusive) { ! /* save last line for undo */ if (u_save((linenr_T)(oap->end.lnum - 1), (linenr_T)(oap->end.lnum + 1)) == FAIL) return FAIL; --- 898,908 ---- } } ! // Break a tab only when it's included in the area. if (gchar_pos(&oap->end) == '\t' && (int)oap->end.coladd < oap->inclusive) { ! // save last line for undo if (u_save((linenr_T)(oap->end.lnum - 1), (linenr_T)(oap->end.lnum + 1)) == FAIL) return FAIL; *************** *** 917,928 **** mb_adjust_opend(oap); } ! if (oap->line_count == 1) /* delete characters within one line */ { ! if (u_save_cursor() == FAIL) /* save line for undo */ return FAIL; ! /* if 'cpoptions' contains '$', display '$' at end of change */ if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL && oap->op_type == OP_CHANGE && oap->end.lnum == curwin->w_cursor.lnum --- 915,926 ---- mb_adjust_opend(oap); } ! if (oap->line_count == 1) // delete characters within one line { ! if (u_save_cursor() == FAIL) // save line for undo return FAIL; ! // if 'cpoptions' contains '$', display '$' at end of change if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL && oap->op_type == OP_CHANGE && oap->end.lnum == curwin->w_cursor.lnum *************** *** 933,941 **** if (virtual_op) { ! /* fix up things for virtualedit-delete: ! * break the tabs which are going to get in our way ! */ char_u *curline = ml_get_curline(); int len = (int)STRLEN(curline); --- 931,938 ---- if (virtual_op) { ! // fix up things for virtualedit-delete: ! // break the tabs which are going to get in our way char_u *curline = ml_get_curline(); int len = (int)STRLEN(curline); *************** *** 943,980 **** && (int)oap->end.col >= len - 1 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) n++; ! /* Delete at least one char (e.g, when on a control char). */ if (n == 0 && oap->start.coladd != oap->end.coladd) n = 1; ! /* When deleted a char in the line, reset coladd. */ if (gchar_cursor() != NUL) curwin->w_cursor.coladd = 0; } (void)del_bytes((long)n, !virtual_op, oap->op_type == OP_DELETE && !oap->is_VIsual); } ! else /* delete characters between lines */ { pos_T curpos; ! /* save deleted and changed lines for undo */ if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) return FAIL; ! truncate_line(TRUE); /* delete from cursor to end of line */ ! curpos = curwin->w_cursor; /* remember curwin->w_cursor */ ++curwin->w_cursor.lnum; del_lines((long)(oap->line_count - 2), FALSE); ! /* delete from start of line until op_end */ n = (oap->end.col + 1 - !oap->inclusive); curwin->w_cursor.col = 0; (void)del_bytes((long)n, !virtual_op, oap->op_type == OP_DELETE && !oap->is_VIsual); ! curwin->w_cursor = curpos; /* restore curwin->w_cursor */ (void)do_join(2, FALSE, FALSE, FALSE, FALSE); } } --- 940,977 ---- && (int)oap->end.col >= len - 1 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) n++; ! // Delete at least one char (e.g, when on a control char). if (n == 0 && oap->start.coladd != oap->end.coladd) n = 1; ! // When deleted a char in the line, reset coladd. if (gchar_cursor() != NUL) curwin->w_cursor.coladd = 0; } (void)del_bytes((long)n, !virtual_op, oap->op_type == OP_DELETE && !oap->is_VIsual); } ! else // delete characters between lines { pos_T curpos; ! // save deleted and changed lines for undo if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) return FAIL; ! truncate_line(TRUE); // delete from cursor to end of line ! curpos = curwin->w_cursor; // remember curwin->w_cursor ++curwin->w_cursor.lnum; del_lines((long)(oap->line_count - 2), FALSE); ! // delete from start of line until op_end n = (oap->end.col + 1 - !oap->inclusive); curwin->w_cursor.col = 0; (void)del_bytes((long)n, !virtual_op, oap->op_type == OP_DELETE && !oap->is_VIsual); ! curwin->w_cursor = curpos; // restore curwin->w_cursor (void)do_join(2, FALSE, FALSE, FALSE, FALSE); } } *************** *** 1025,1031 **** State = REPLACE; ins_char(c); State = n; ! /* Backup to the replaced character. */ dec_cursor(); } --- 1022,1028 ---- State = REPLACE; ins_char(c); State = n; ! // Backup to the replaced character. dec_cursor(); } *************** *** 1044,1050 **** int had_ctrl_v_cr = FALSE; if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) ! return OK; /* nothing to do */ if (c == REPLACE_CR_NCHAR) { --- 1041,1047 ---- int had_ctrl_v_cr = FALSE; if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) ! return OK; // nothing to do if (c == REPLACE_CR_NCHAR) { *************** *** 1072,1088 **** bd.is_MAX = (curwin->w_curswant == MAXCOL); for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) { ! curwin->w_cursor.col = 0; /* make sure cursor position is valid */ block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) ! continue; /* nothing to replace */ ! /* n == number of extra chars required ! * If we split a TAB, it may be replaced by several characters. ! * Thus the number of characters may increase! ! */ ! /* If the range starts in virtual space, count the initial ! * coladd offset as part of "startspaces" */ if (virtual_op && bd.is_short && *bd.textstart == NUL) { pos_T vpos; --- 1069,1084 ---- bd.is_MAX = (curwin->w_curswant == MAXCOL); for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) { ! curwin->w_cursor.col = 0; // make sure cursor position is valid block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) ! continue; // nothing to replace ! // n == number of extra chars required ! // If we split a TAB, it may be replaced by several characters. ! // Thus the number of characters may increase! ! // If the range starts in virtual space, count the initial ! // coladd offset as part of "startspaces" if (virtual_op && bd.is_short && *bd.textstart == NUL) { pos_T vpos; *************** *** 1093,1112 **** n = bd.startspaces; } else ! /* allow for pre spaces */ n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); ! /* allow for post spp */ n += (bd.endspaces && !bd.is_oneChar && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; ! /* Figure out how many characters to replace. */ numc = oap->end_vcol - oap->start_vcol + 1; if (bd.is_short && (!virtual_op || bd.is_MAX)) numc -= (oap->end_vcol - bd.end_vcol) + 1; ! /* A double-wide character can be replaced only up to half the ! * times. */ if ((*mb_char2cells)(c) > 1) { if ((numc & 1) && !bd.is_short) --- 1089,1108 ---- n = bd.startspaces; } else ! // allow for pre spaces n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); ! // allow for post spp n += (bd.endspaces && !bd.is_oneChar && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; ! // Figure out how many characters to replace. numc = oap->end_vcol - oap->start_vcol + 1; if (bd.is_short && (!virtual_op || bd.is_MAX)) numc -= (oap->end_vcol - bd.end_vcol) + 1; ! // A double-wide character can be replaced only up to half the ! // times. if ((*mb_char2cells)(c) > 1) { if ((numc & 1) && !bd.is_short) *************** *** 1117,1126 **** numc = numc / 2; } ! /* Compute bytes needed, move character count to num_chars. */ num_chars = numc; numc *= (*mb_char2len)(c); ! /* oldlen includes textlen, so don't double count */ n += numc - bd.textlen; oldp = ml_get_curline(); --- 1113,1122 ---- numc = numc / 2; } ! // Compute bytes needed, move character count to num_chars. num_chars = numc; numc *= (*mb_char2len)(c); ! // oldlen includes textlen, so don't double count n += numc - bd.textlen; oldp = ml_get_curline(); *************** *** 1129,1142 **** if (newp == NULL) continue; vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); ! /* copy up to deleted part */ mch_memmove(newp, oldp, (size_t)bd.textcol); oldp += bd.textcol + bd.textlen; ! /* insert pre-spaces */ vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); ! /* insert replacement chars CHECK FOR ALLOCATED SPACE */ ! /* REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR ! * literally. */ if (had_ctrl_v_cr || (c != '\r' && c != '\n')) { if (has_mbyte) --- 1125,1138 ---- if (newp == NULL) continue; vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); ! // copy up to deleted part mch_memmove(newp, oldp, (size_t)bd.textcol); oldp += bd.textcol + bd.textlen; ! // insert pre-spaces vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); ! // insert replacement chars CHECK FOR ALLOCATED SPACE ! // REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR ! // literally. if (had_ctrl_v_cr || (c != '\r' && c != '\n')) { if (has_mbyte) *************** *** 1149,1168 **** vim_memset(newp + STRLEN(newp), c, (size_t)numc); if (!bd.is_short) { ! /* insert post-spaces */ vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); ! /* copy the part after the changed part */ STRMOVE(newp + STRLEN(newp), oldp); } } else { ! /* Replacing with \r or \n means splitting the line. */ after_p = alloc(oldlen + 1 + n - STRLEN(newp)); if (after_p != NULL) STRMOVE(after_p, oldp); } ! /* replace the line */ ml_replace(curwin->w_cursor.lnum, newp, FALSE); if (after_p != NULL) { --- 1145,1164 ---- vim_memset(newp + STRLEN(newp), c, (size_t)numc); if (!bd.is_short) { ! // insert post-spaces vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); ! // copy the part after the changed part STRMOVE(newp + STRLEN(newp), oldp); } } else { ! // Replacing with \r or \n means splitting the line. after_p = alloc(oldlen + 1 + n - STRLEN(newp)); if (after_p != NULL) STRMOVE(after_p, oldp); } ! // replace the line ml_replace(curwin->w_cursor.lnum, newp, FALSE); if (after_p != NULL) { *************** *** 1196,1203 **** { if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) { ! /* This is slow, but it handles replacing a single-byte ! * with a multi-byte and the other way around. */ if (curwin->w_cursor.lnum == oap->end.lnum) oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); replace_character(c); --- 1192,1199 ---- { if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) { ! // This is slow, but it handles replacing a single-byte ! // with a multi-byte and the other way around. if (curwin->w_cursor.lnum == oap->end.lnum) oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); replace_character(c); *************** *** 1210,1217 **** if (curwin->w_cursor.lnum == oap->end.lnum) { ! /* oap->end has to be recalculated when ! * the tab breaks */ end_vcol = getviscol2(oap->end.col, oap->end.coladd); } --- 1206,1213 ---- if (curwin->w_cursor.lnum == oap->end.lnum) { ! // oap->end has to be recalculated when ! // the tab breaks end_vcol = getviscol2(oap->end.col, oap->end.coladd); } *************** *** 1230,1238 **** && oap->start.col == oap->end.col && oap->start.coladd) virtcols -= oap->start.coladd; ! /* oap->end has been trimmed so it's effectively inclusive; ! * as a result an extra +1 must be counted so we don't ! * trample the NUL byte. */ coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); curwin->w_cursor.col -= (virtcols + 1); for (; virtcols >= 0; virtcols--) --- 1226,1234 ---- && oap->start.col == oap->end.col && oap->start.coladd) virtcols -= oap->start.coladd; ! // oap->end has been trimmed so it's effectively inclusive; ! // as a result an extra +1 must be counted so we don't ! // trample the NUL byte. coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); curwin->w_cursor.col -= (virtcols + 1); for (; virtcols >= 0; virtcols--) *************** *** 1246,1252 **** } } ! /* Advance to next character, stop at the end of the file. */ if (inc_cursor() == -1) break; } --- 1242,1248 ---- } } ! // Advance to next character, stop at the end of the file. if (inc_cursor() == -1) break; } *************** *** 1258,1264 **** if (!cmdmod.lockmarks) { ! /* Set "'[" and "']" marks. */ curbuf->b_op_start = oap->start; curbuf->b_op_end = oap->end; } --- 1254,1260 ---- if (!cmdmod.lockmarks) { ! // Set "'[" and "']" marks. curbuf->b_op_start = oap->start; curbuf->b_op_end = oap->end; } *************** *** 1283,1289 **** return; pos = oap->start; ! if (oap->block_mode) /* Visual block mode */ { for (; pos.lnum <= oap->end.lnum; ++pos.lnum) { --- 1279,1285 ---- return; pos = oap->start; ! if (oap->block_mode) // Visual block mode { for (; pos.lnum <= oap->end.lnum; ++pos.lnum) { *************** *** 1309,1315 **** if (did_change) changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); } ! else /* not block mode */ { if (oap->motion_type == MLINE) { --- 1305,1311 ---- if (did_change) changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); } ! else // not block mode { if (oap->motion_type == MLINE) { *************** *** 1366,1372 **** } if (!did_change && oap->is_VIsual) ! /* No change: need to remove the Visual selection */ redraw_curbuf_later(INVERTED); if (!cmdmod.lockmarks) --- 1362,1368 ---- } if (!did_change && oap->is_VIsual) ! // No change: need to remove the Visual selection redraw_curbuf_later(INVERTED); if (!cmdmod.lockmarks) *************** *** 1400,1411 **** { int len = (*mb_ptr2len)(ml_get_pos(pos)); ! /* we're counting bytes, not characters */ if (len > 0) todo -= len - 1; } did_change |= swapchar(op_type, pos); ! if (inc(pos) == -1) /* at end of file */ break; } return did_change; --- 1396,1407 ---- { int len = (*mb_ptr2len)(ml_get_pos(pos)); ! // we're counting bytes, not characters if (len > 0) todo -= len - 1; } did_change |= swapchar(op_type, pos); ! if (inc(pos) == -1) // at end of file break; } return did_change; *************** *** 1426,1432 **** c = gchar_pos(pos); ! /* Only do rot13 encoding for ASCII characters. */ if (c >= 0x80 && op_type == OP_ROT13) return FALSE; --- 1422,1428 ---- c = gchar_pos(pos); ! // Only do rot13 encoding for ASCII characters. if (c >= 0x80 && op_type == OP_ROT13) return FALSE; *************** *** 1435,1441 **** { pos_T sp = curwin->w_cursor; ! /* Special handling of German sharp s: change to "SS". */ curwin->w_cursor = *pos; del_char(FALSE); ins_char('S'); --- 1431,1437 ---- { pos_T sp = curwin->w_cursor; ! // Special handling of German sharp s: change to "SS". curwin->w_cursor = *pos; del_char(FALSE); ins_char('S'); *************** *** 1444,1450 **** inc(pos); } ! if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ return FALSE; nc = c; if (MB_ISLOWER(c)) --- 1440,1446 ---- inc(pos); } ! if (enc_dbcs != 0 && c >= 0x100) // No lower/uppercase letter return FALSE; nc = c; if (MB_ISLOWER(c)) *************** *** 1468,1474 **** pos_T sp = curwin->w_cursor; curwin->w_cursor = *pos; ! /* don't use del_char(), it also removes composing chars */ del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); ins_char(nc); curwin->w_cursor = sp; --- 1464,1470 ---- pos_T sp = curwin->w_cursor; curwin->w_cursor = *pos; ! // don't use del_char(), it also removes composing chars del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); ins_char(nc); curwin->w_cursor = sp; *************** *** 1493,1511 **** int i; pos_T t1; ! /* edit() changes this - record it for OP_APPEND */ bd.is_MAX = (curwin->w_curswant == MAXCOL); ! /* vis block is still marked. Get rid of it now. */ curwin->w_cursor.lnum = oap->start.lnum; update_screen(INVERTED); if (oap->block_mode) { ! /* When 'virtualedit' is used, need to insert the extra spaces before ! * doing block_prep(). When only "block" is used, virtual edit is ! * already disabled, but still need it when calling ! * coladvance_force(). */ if (curwin->w_cursor.coladd > 0) { int old_ve_flags = ve_flags; --- 1489,1507 ---- int i; pos_T t1; ! // edit() changes this - record it for OP_APPEND bd.is_MAX = (curwin->w_curswant == MAXCOL); ! // vis block is still marked. Get rid of it now. curwin->w_cursor.lnum = oap->start.lnum; update_screen(INVERTED); if (oap->block_mode) { ! // When 'virtualedit' is used, need to insert the extra spaces before ! // doing block_prep(). When only "block" is used, virtual edit is ! // already disabled, but still need it when calling ! // coladvance_force(). if (curwin->w_cursor.coladd > 0) { int old_ve_flags = ve_flags; *************** *** 1519,1527 **** --curwin->w_cursor.col; ve_flags = old_ve_flags; } ! /* Get the info about the block before entering the text */ block_prep(oap, &bd, oap->start.lnum, TRUE); ! /* Get indent information */ ind_pre = (colnr_T)getwhitecols_curline(); firstline = ml_get(oap->start.lnum) + bd.textcol; --- 1515,1523 ---- --curwin->w_cursor.col; ve_flags = old_ve_flags; } ! // Get the info about the block before entering the text block_prep(oap, &bd, oap->start.lnum, TRUE); ! // Get indent information ind_pre = (colnr_T)getwhitecols_curline(); firstline = ml_get(oap->start.lnum) + bd.textcol; *************** *** 1534,1548 **** { if (oap->block_mode && curwin->w_cursor.coladd == 0) { ! /* Move the cursor to the character right of the block. */ curwin->w_set_curswant = TRUE; while (*ml_get_cursor() != NUL && (curwin->w_cursor.col < bd.textcol + bd.textlen)) ++curwin->w_cursor.col; if (bd.is_short && !bd.is_MAX) { ! /* First line was too short, make it longer and adjust the ! * values in "bd". */ if (u_save_cursor() == FAIL) return; for (i = 0; i < bd.endspaces; ++i) --- 1530,1544 ---- { if (oap->block_mode && curwin->w_cursor.coladd == 0) { ! // Move the cursor to the character right of the block. curwin->w_set_curswant = TRUE; while (*ml_get_cursor() != NUL && (curwin->w_cursor.col < bd.textcol + bd.textlen)) ++curwin->w_cursor.col; if (bd.is_short && !bd.is_MAX) { ! // First line was too short, make it longer and adjust the ! // values in "bd". if (u_save_cursor() == FAIL) return; for (i = 0; i < bd.endspaces; ++i) *************** *** 1555,1561 **** curwin->w_cursor = oap->end; check_cursor_col(); ! /* Works just like an 'i'nsert on the next character. */ if (!LINEEMPTY(curwin->w_cursor.lnum) && oap->start_vcol != oap->end_vcol) inc_cursor(); --- 1551,1557 ---- curwin->w_cursor = oap->end; check_cursor_col(); ! // Works just like an 'i'nsert on the next character. if (!LINEEMPTY(curwin->w_cursor.lnum) && oap->start_vcol != oap->end_vcol) inc_cursor(); *************** *** 1565,1580 **** t1 = oap->start; (void)edit(NUL, FALSE, (linenr_T)count1); ! /* When a tab was inserted, and the characters in front of the tab ! * have been converted to a tab as well, the column of the cursor ! * might have actually been reduced, so need to adjust here. */ if (t1.lnum == curbuf->b_op_start_orig.lnum && LT_POS(curbuf->b_op_start_orig, t1)) oap->start = curbuf->b_op_start_orig; ! /* If user has moved off this line, we don't know what to do, so do ! * nothing. ! * Also don't repeat the insert when Insert mode ended with CTRL-C. */ if (curwin->w_cursor.lnum != oap->start.lnum || got_int) return; --- 1561,1576 ---- t1 = oap->start; (void)edit(NUL, FALSE, (linenr_T)count1); ! // When a tab was inserted, and the characters in front of the tab ! // have been converted to a tab as well, the column of the cursor ! // might have actually been reduced, so need to adjust here. if (t1.lnum == curbuf->b_op_start_orig.lnum && LT_POS(curbuf->b_op_start_orig, t1)) oap->start = curbuf->b_op_start_orig; ! // If user has moved off this line, we don't know what to do, so do ! // nothing. ! // Also don't repeat the insert when Insert mode ended with CTRL-C. if (curwin->w_cursor.lnum != oap->start.lnum || got_int) return; *************** *** 1585,1592 **** size_t len; int add; ! /* If indent kicked in, the firstline might have changed ! * but only do that, if the indent actually increased. */ ind_post = (colnr_T)getwhitecols_curline(); if (curbuf->b_op_start.col > ind_pre && ind_post > ind_pre) { --- 1581,1588 ---- size_t len; int add; ! // If indent kicked in, the firstline might have changed ! // but only do that, if the indent actually increased. ind_post = (colnr_T)getwhitecols_curline(); if (curbuf->b_op_start.col > ind_pre && ind_post > ind_pre) { *************** *** 1595,1603 **** did_indent = TRUE; } ! /* The user may have moved the cursor before inserting something, try ! * to adjust the block for that. But only do it, if the difference ! * does not come from indent kicking in. */ if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX && !did_indent) { --- 1591,1599 ---- did_indent = TRUE; } ! // The user may have moved the cursor before inserting something, try ! // to adjust the block for that. But only do it, if the difference ! // does not come from indent kicking in. if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX && !did_indent) { *************** *** 1620,1626 **** int t = getviscol2(curbuf->b_op_start_orig.col, curbuf->b_op_start_orig.coladd); oap->start.col = curbuf->b_op_start_orig.col; ! /* reset pre_textlen to the value of OP_INSERT */ pre_textlen += bd.textlen; pre_textlen -= t - oap->start_vcol; oap->start_vcol = t; --- 1616,1622 ---- int t = getviscol2(curbuf->b_op_start_orig.col, curbuf->b_op_start_orig.coladd); oap->start.col = curbuf->b_op_start_orig.col; ! // reset pre_textlen to the value of OP_INSERT pre_textlen += bd.textlen; pre_textlen -= t - oap->start_vcol; oap->start_vcol = t; *************** *** 1665,1671 **** ins_text = vim_strnsave(firstline, (int)ins_len); if (ins_text != NULL) { ! /* block handled here */ if (u_save(oap->start.lnum, (linenr_T)(oap->end.lnum + 1)) == OK) block_insert(oap, ins_text, (oap->op_type == OP_INSERT), --- 1661,1667 ---- ins_text = vim_strnsave(firstline, (int)ins_len); if (ins_text != NULL) { ! // block handled here if (u_save(oap->start.lnum, (linenr_T)(oap->end.lnum + 1)) == OK) block_insert(oap, ins_text, (oap->op_type == OP_INSERT), *************** *** 1708,1719 **** && !curbuf->b_p_cin # endif ) ! can_si = TRUE; /* It's like opening a new line, do si */ #endif } ! /* First delete the text in the region. In an empty buffer only need to ! * save for undo */ if (curbuf->b_ml.ml_flags & ML_EMPTY) { if (u_save_cursor() == FAIL) --- 1704,1715 ---- && !curbuf->b_p_cin # endif ) ! can_si = TRUE; // It's like opening a new line, do si #endif } ! // First delete the text in the region. In an empty buffer only need to ! // save for undo if (curbuf->b_ml.ml_flags & ML_EMPTY) { if (u_save_cursor() == FAIL) *************** *** 1726,1736 **** && !virtual_op) inc_cursor(); ! /* check for still on same line ( in inserted text meaningless) */ ! /* skip blank lines too */ if (oap->block_mode) { ! /* Add spaces before getting the current line length. */ if (virtual_op && (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL)) coladvance_force(getviscol()); --- 1722,1732 ---- && !virtual_op) inc_cursor(); ! // check for still on same line ( in inserted text meaningless) ! // skip blank lines too if (oap->block_mode) { ! // Add spaces before getting the current line length. if (virtual_op && (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL)) coladvance_force(getviscol()); *************** *** 1754,1761 **** */ if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) { ! /* Auto-indenting may have changed the indent. If the cursor was past ! * the indent, exclude that indent change from the inserted text. */ firstline = ml_get(oap->start.lnum); if (bd.textcol > (colnr_T)pre_indent) { --- 1750,1757 ---- */ if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) { ! // Auto-indenting may have changed the indent. If the cursor was past ! // the indent, exclude that indent change from the inserted text. firstline = ml_get(oap->start.lnum); if (bd.textcol > (colnr_T)pre_indent) { *************** *** 1768,1775 **** ins_len = (long)STRLEN(firstline) - pre_textlen; if (ins_len > 0) { ! /* Subsequent calls to ml_get() flush the firstline data - take a ! * copy of the inserted text. */ if ((ins_text = alloc(ins_len + 1)) != NULL) { vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); --- 1764,1771 ---- ins_len = (long)STRLEN(firstline) - pre_textlen; if (ins_len > 0) { ! // Subsequent calls to ml_get() flush the firstline data - take a ! // copy of the inserted text. if ((ins_text = alloc(ins_len + 1)) != NULL) { vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); *************** *** 1781,1788 **** { pos_T vpos; ! /* If the block starts in virtual space, count the ! * initial coladd offset as part of "startspaces" */ if (bd.is_short) { vpos.lnum = linenr; --- 1777,1784 ---- { pos_T vpos; ! // If the block starts in virtual space, count the ! // initial coladd offset as part of "startspaces" if (bd.is_short) { vpos.lnum = linenr; *************** *** 1794,1800 **** newp = alloc(STRLEN(oldp) + vpos.coladd + ins_len + 1); if (newp == NULL) continue; ! /* copy up to block start */ mch_memmove(newp, oldp, (size_t)bd.textcol); offset = bd.textcol; vim_memset(newp + offset, ' ', (size_t)vpos.coladd); --- 1790,1796 ---- newp = alloc(STRLEN(oldp) + vpos.coladd + ins_len + 1); if (newp == NULL) continue; ! // copy up to block start mch_memmove(newp, oldp, (size_t)bd.textcol); offset = bd.textcol; vim_memset(newp + offset, ' ', (size_t)vpos.coladd); *************** *** 1829,1842 **** && (ve_flags & VE_ONEMORE) == 0 && !(restart_edit || (State & INSERT))) { ! /* Put the cursor on the last character in the line. */ dec_cursor(); if (ve_flags == VE_ALL) { colnr_T scol, ecol; ! /* Coladd is set to the width of the last character. */ getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); curwin->w_cursor.coladd = ecol - scol + 1; } --- 1825,1838 ---- && (ve_flags & VE_ONEMORE) == 0 && !(restart_edit || (State & INSERT))) { ! // Put the cursor on the last character in the line. dec_cursor(); if (ve_flags == VE_ALL) { colnr_T scol, ecol; ! // Coladd is set to the width of the last character. getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); curwin->w_cursor.coladd = ecol - scol + 1; } *************** *** 1869,1877 **** *is_comment = FALSE; if (leader_offset != -1) { ! /* Let's check whether the line ends with an unclosed comment. ! * If the last comment leader has COM_END in flags, there's no comment. ! */ while (*comment_flags) { if (*comment_flags == COM_END --- 1865,1872 ---- *is_comment = FALSE; if (leader_offset != -1) { ! // Let's check whether the line ends with an unclosed comment. ! // If the last comment leader has COM_END in flags, there's no comment. while (*comment_flags) { if (*comment_flags == COM_END *************** *** 1891,1901 **** if (lead_len == 0) return line; ! /* Find: ! * - COM_END, ! * - colon, ! * whichever comes first. ! */ while (*comment_flags) { if (*comment_flags == COM_END --- 1886,1895 ---- if (lead_len == 0) return line; ! // Find: ! // - COM_END, ! // - colon, ! // whichever comes first. while (*comment_flags) { if (*comment_flags == COM_END *************** *** 1904,1913 **** ++comment_flags; } ! /* If we found a colon, it means that we are not processing a line ! * starting with a closing part of a three-part comment. That's good, ! * because we don't want to remove those as this would be annoying. ! */ if (*comment_flags == ':' || *comment_flags == NUL) line += lead_len; --- 1898,1906 ---- ++comment_flags; } ! // If we found a colon, it means that we are not processing a line ! // starting with a closing part of a three-part comment. That's good, ! // because we don't want to remove those as this would be annoying. if (*comment_flags == ':' || *comment_flags == NUL) line += lead_len; *************** *** 1936,1946 **** char_u *curr_start = NULL; char_u *cend; char_u *newp; ! char_u *spaces; /* number of spaces inserted before a line */ int endcurr1 = NUL; int endcurr2 = NUL; ! int currsize = 0; /* size of the current line */ ! int sumsize = 0; /* size of the long new line */ linenr_T t; colnr_T col = 0; int ret = OK; --- 1929,1939 ---- char_u *curr_start = NULL; char_u *cend; char_u *newp; ! char_u *spaces; // number of spaces inserted before a line int endcurr1 = NUL; int endcurr2 = NUL; ! int currsize = 0; // size of the current line ! int sumsize = 0; // size of the long new line linenr_T t; colnr_T col = 0; int ret = OK; *************** *** 1957,1965 **** (linenr_T)(curwin->w_cursor.lnum + count)) == FAIL) return FAIL; ! /* Allocate an array to store the number of spaces inserted before each ! * line. We will use it to pre-compute the length of the new line and the ! * proper placement of each original line in the new one. */ spaces = lalloc_clear(count, TRUE); if (spaces == NULL) return FAIL; --- 1950,1958 ---- (linenr_T)(curwin->w_cursor.lnum + count)) == FAIL) return FAIL; ! // Allocate an array to store the number of spaces inserted before each ! // line. We will use it to pre-compute the length of the new line and the ! // proper placement of each original line in the new one. spaces = lalloc_clear(count, TRUE); if (spaces == NULL) return FAIL; *************** *** 1983,1996 **** curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); if (t == 0 && setmark && !cmdmod.lockmarks) { ! /* Set the '[ mark. */ curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); } if (remove_comments) { ! /* We don't want to remove the comment leader if the ! * previous line is not a comment. */ if (t > 0 && prev_was_comment) { --- 1976,1989 ---- curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); if (t == 0 && setmark && !cmdmod.lockmarks) { ! // Set the '[ mark. curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); } if (remove_comments) { ! // We don't want to remove the comment leader if the ! // previous line is not a comment. if (t > 0 && prev_was_comment) { *************** *** 2015,2026 **** || mb_ptr2char(curr) < 0x100 || endcurr1 < 0x100) ) { ! /* don't add a space if the line is ending in a space */ if (endcurr1 == ' ') endcurr1 = endcurr2; else ++spaces[t]; ! /* extra space when 'joinspaces' set and line ends in '.' */ if ( p_js && (endcurr1 == '.' || (vim_strchr(p_cpo, CPO_JOINSP) == NULL --- 2008,2019 ---- || mb_ptr2char(curr) < 0x100 || endcurr1 < 0x100) ) { ! // don't add a space if the line is ending in a space if (endcurr1 == ' ') endcurr1 = endcurr2; else ++spaces[t]; ! // extra space when 'joinspaces' set and line ends in '.' if ( p_js && (endcurr1 == '.' || (vim_strchr(p_cpo, CPO_JOINSP) == NULL *************** *** 2059,2068 **** } } ! /* store the column position before last line */ col = sumsize - currsize - spaces[count - 1]; ! /* allocate the space for the new line */ newp = alloc(sumsize + 1); if (newp == NULL) { --- 2052,2061 ---- } } ! // store the column position before last line col = sumsize - currsize - spaces[count - 1]; ! // allocate the space for the new line newp = alloc(sumsize + 1); if (newp == NULL) { *************** *** 2139,2151 **** if (setmark && !cmdmod.lockmarks) { ! /* Set the '] mark. */ curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; curwin->w_buffer->b_op_end.col = (colnr_T)sumsize; } ! /* Only report the change in the first line here, del_lines() will report ! * the deleted line. */ changed_lines(curwin->w_cursor.lnum, currsize, curwin->w_cursor.lnum + 1, 0L); /* --- 2132,2144 ---- if (setmark && !cmdmod.lockmarks) { ! // Set the '] mark. curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; curwin->w_buffer->b_op_end.col = (colnr_T)sumsize; } ! // Only report the change in the first line here, del_lines() will report ! // the deleted line. changed_lines(curwin->w_cursor.lnum, currsize, curwin->w_cursor.lnum + 1, 0L); /* *************** *** 2259,2270 **** static void op_format( oparg_T *oap, ! int keep_cursor) /* keep cursor on same text char */ { long old_line_count = curbuf->b_ml.ml_line_count; ! /* Place the cursor where the "gq" or "gw" command was given, so that "u" ! * can put it back there. */ curwin->w_cursor = oap->cursor_start; if (u_save((linenr_T)(oap->start.lnum - 1), --- 2252,2263 ---- static void op_format( oparg_T *oap, ! int keep_cursor) // keep cursor on same text char { long old_line_count = curbuf->b_ml.ml_line_count; ! // Place the cursor where the "gq" or "gw" command was given, so that "u" ! // can put it back there. curwin->w_cursor = oap->cursor_start; if (u_save((linenr_T)(oap->start.lnum - 1), *************** *** 2273,2287 **** curwin->w_cursor = oap->start; if (oap->is_VIsual) ! /* When there is no change: need to remove the Visual selection */ redraw_curbuf_later(INVERTED); if (!cmdmod.lockmarks) ! /* Set '[ mark at the start of the formatted area */ curbuf->b_op_start = oap->start; ! /* For "gw" remember the cursor position and put it back below (adjusted ! * for joined and split lines). */ if (keep_cursor) saved_cursor = oap->cursor_start; --- 2266,2280 ---- curwin->w_cursor = oap->start; if (oap->is_VIsual) ! // When there is no change: need to remove the Visual selection redraw_curbuf_later(INVERTED); if (!cmdmod.lockmarks) ! // Set '[ mark at the start of the formatted area curbuf->b_op_start = oap->start; ! // For "gw" remember the cursor position and put it back below (adjusted ! // for joined and split lines). if (keep_cursor) saved_cursor = oap->cursor_start; *************** *** 2299,2305 **** msgmore(old_line_count); if (!cmdmod.lockmarks) ! /* put '] mark on the end of the formatted area */ curbuf->b_op_end = curwin->w_cursor; if (keep_cursor) --- 2292,2298 ---- msgmore(old_line_count); if (!cmdmod.lockmarks) ! // put '] mark on the end of the formatted area curbuf->b_op_end = curwin->w_cursor; if (keep_cursor) *************** *** 2316,2323 **** { if (wp->w_old_cursor_lnum != 0) { ! /* When lines have been inserted or deleted, adjust the end of ! * the Visual area to be redrawn. */ if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) wp->w_old_cursor_lnum += old_line_count; else --- 2309,2316 ---- { if (wp->w_old_cursor_lnum != 0) { ! // When lines have been inserted or deleted, adjust the end of ! // the Visual area to be redrawn. if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) wp->w_old_cursor_lnum += old_line_count; else *************** *** 2335,2346 **** op_formatexpr(oparg_T *oap) { if (oap->is_VIsual) ! /* When there is no change: need to remove the Visual selection */ redraw_curbuf_later(INVERTED); if (fex_format(oap->start.lnum, oap->line_count, NUL) != 0) ! /* As documented: when 'formatexpr' returns non-zero fall back to ! * internal formatting. */ op_format(oap, FALSE); } --- 2328,2339 ---- op_formatexpr(oparg_T *oap) { if (oap->is_VIsual) ! // When there is no change: need to remove the Visual selection redraw_curbuf_later(INVERTED); if (fex_format(oap->start.lnum, oap->line_count, NUL) != 0) ! // As documented: when 'formatexpr' returns non-zero fall back to ! // internal formatting. op_format(oap, FALSE); } *************** *** 2348,2354 **** fex_format( linenr_T lnum, long count, ! int c) /* character to be inserted */ { int use_sandbox = was_set_insecurely((char_u *)"formatexpr", OPT_LOCAL); --- 2341,2347 ---- fex_format( linenr_T lnum, long count, ! int c) // character to be inserted { int use_sandbox = was_set_insecurely((char_u *)"formatexpr", OPT_LOCAL); *************** *** 2363,2369 **** set_vim_var_nr(VV_COUNT, count); set_vim_var_char(c); ! /* Make a copy, the option could be changed while calling it. */ fex = vim_strsave(curbuf->b_p_fex); if (fex == NULL) return 0; --- 2356,2362 ---- set_vim_var_nr(VV_COUNT, count); set_vim_var_char(c); ! // Make a copy, the option could be changed while calling it. fex = vim_strsave(curbuf->b_p_fex); if (fex == NULL) return 0; *************** *** 2393,2429 **** void format_lines( linenr_T line_count, ! int avoid_fex) /* don't use 'formatexpr' */ { int max_len; ! int is_not_par; /* current line not part of parag. */ ! int next_is_not_par; /* next line not part of paragraph */ ! int is_end_par; /* at end of paragraph */ ! int prev_is_end_par = FALSE;/* prev. line not part of parag. */ int next_is_start_par = FALSE; ! int leader_len = 0; /* leader len of current line */ ! int next_leader_len; /* leader len of next line */ ! char_u *leader_flags = NULL; /* flags for leader of current line */ ! char_u *next_leader_flags; /* flags for leader of next line */ ! int do_comments; /* format comments */ ! int do_comments_list = 0; /* format comments with 'n' or '2' */ int advance = TRUE; ! int second_indent = -1; /* indent for second line (comment ! * aware) */ int do_second_indent; int do_number_indent; int do_trail_white; int first_par_line = TRUE; int smd_save; long count; ! int need_set_indent = TRUE; /* set indent of next paragraph */ int force_format = FALSE; int old_State = State; ! /* length of a line to force formatting: 3 * 'tw' */ max_len = comp_textwidth(TRUE) * 3; ! /* check for 'q', '2' and '1' in 'formatoptions' */ do_comments = has_format_option(FO_Q_COMS); do_second_indent = has_format_option(FO_Q_SECOND); do_number_indent = has_format_option(FO_Q_NUMBER); --- 2386,2422 ---- void format_lines( linenr_T line_count, ! int avoid_fex) // don't use 'formatexpr' { int max_len; ! int is_not_par; // current line not part of parag. ! int next_is_not_par; // next line not part of paragraph ! int is_end_par; // at end of paragraph ! int prev_is_end_par = FALSE;// prev. line not part of parag. int next_is_start_par = FALSE; ! int leader_len = 0; // leader len of current line ! int next_leader_len; // leader len of next line ! char_u *leader_flags = NULL; // flags for leader of current line ! char_u *next_leader_flags; // flags for leader of next line ! int do_comments; // format comments ! int do_comments_list = 0; // format comments with 'n' or '2' int advance = TRUE; ! int second_indent = -1; // indent for second line (comment ! // aware) int do_second_indent; int do_number_indent; int do_trail_white; int first_par_line = TRUE; int smd_save; long count; ! int need_set_indent = TRUE; // set indent of next paragraph int force_format = FALSE; int old_State = State; ! // length of a line to force formatting: 3 * 'tw' max_len = comp_textwidth(TRUE) * 3; ! // check for 'q', '2' and '1' in 'formatoptions' do_comments = has_format_option(FO_Q_COMS); do_second_indent = has_format_option(FO_Q_SECOND); do_number_indent = has_format_option(FO_Q_NUMBER); *************** *** 2503,2509 **** { if (leader_len == 0 && next_leader_len == 0) { ! /* no comment found */ second_indent = get_indent_lnum(curwin->w_cursor.lnum + 1); } --- 2496,2502 ---- { if (leader_len == 0 && next_leader_len == 0) { ! // no comment found second_indent = get_indent_lnum(curwin->w_cursor.lnum + 1); } *************** *** 2517,2529 **** { if (leader_len == 0 && next_leader_len == 0) { ! /* no comment found */ second_indent = get_number_indent(curwin->w_cursor.lnum); } else { ! /* get_number_indent() is now "comment aware"... */ second_indent = get_number_indent(curwin->w_cursor.lnum); do_comments_list = 1; --- 2510,2522 ---- { if (leader_len == 0 && next_leader_len == 0) { ! // no comment found second_indent = get_number_indent(curwin->w_cursor.lnum); } else { ! // get_number_indent() is now "comment aware"... second_indent = get_number_indent(curwin->w_cursor.lnum); do_comments_list = 1; *************** *** 2547,2564 **** if (is_end_par || force_format) { if (need_set_indent) ! /* replace indent in first line with minimal number of ! * tabs and spaces, according to current options */ (void)set_indent(get_indent(), SIN_CHANGED); ! /* put cursor on last non-space */ ! State = NORMAL; /* don't go past end-of-line */ coladvance((colnr_T)MAXCOL); while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) dec_cursor(); ! /* do the formatting, without 'showmode' */ ! State = INSERT; /* for open_line() */ smd_save = p_smd; p_smd = FALSE; insertchar(NUL, INSCHAR_FORMAT --- 2540,2557 ---- if (is_end_par || force_format) { if (need_set_indent) ! // replace indent in first line with minimal number of ! // tabs and spaces, according to current options (void)set_indent(get_indent(), SIN_CHANGED); ! // put cursor on last non-space ! State = NORMAL; // don't go past end-of-line coladvance((colnr_T)MAXCOL); while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) dec_cursor(); ! // do the formatting, without 'showmode' ! State = INSERT; // for open_line() smd_save = p_smd; p_smd = FALSE; insertchar(NUL, INSCHAR_FORMAT *************** *** 2569,2580 **** State = old_State; p_smd = smd_save; second_indent = -1; ! /* at end of par.: need to set indent of next par. */ need_set_indent = is_end_par; if (is_end_par) { ! /* When called with a negative line count, break at the ! * end of the paragraph. */ if (line_count < 0) break; first_par_line = TRUE; --- 2562,2573 ---- State = old_State; p_smd = smd_save; second_indent = -1; ! // at end of par.: need to set indent of next par. need_set_indent = is_end_par; if (is_end_par) { ! // When called with a negative line count, break at the ! // end of the paragraph. if (line_count < 0) break; first_par_line = TRUE; *************** *** 2617,2623 **** break; } first_par_line = FALSE; ! /* If the line is getting long, format it next time */ if (STRLEN(ml_get_curline()) > (size_t)max_len) force_format = TRUE; else --- 2610,2616 ---- break; } first_par_line = FALSE; ! // If the line is getting long, format it next time if (STRLEN(ml_get_curline()) > (size_t)max_len) force_format = TRUE; else *************** *** 2639,2646 **** if (*s == NUL) return FALSE; ! /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro ! * invocation may call function multiple times". */ l = STRLEN(s) - 1; return VIM_ISWHITE(s[l]); } --- 2632,2639 ---- if (*s == NUL) return FALSE; ! // Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro ! // invocation may call function multiple times". l = STRLEN(s) - 1; return VIM_ISWHITE(s[l]); } *************** *** 2660,2666 **** char_u **leader_flags, int do_comments) { ! char_u *flags = NULL; /* init for GCC */ char_u *ptr; ptr = ml_get(lnum); --- 2653,2659 ---- char_u **leader_flags, int do_comments) { ! char_u *flags = NULL; // init for GCC char_u *ptr; ptr = ml_get(lnum); *************** *** 2692,2726 **** paragraph_start(linenr_T lnum) { char_u *p; ! int leader_len = 0; /* leader len of current line */ ! char_u *leader_flags = NULL; /* flags for leader of current line */ ! int next_leader_len; /* leader len of next line */ ! char_u *next_leader_flags; /* flags for leader of next line */ ! int do_comments; /* format comments */ if (lnum <= 1) ! return TRUE; /* start of the file */ p = ml_get(lnum - 1); if (*p == NUL) ! return TRUE; /* after empty line */ do_comments = has_format_option(FO_Q_COMS); if (fmt_check_par(lnum - 1, &leader_len, &leader_flags, do_comments)) ! return TRUE; /* after non-paragraph line */ if (fmt_check_par(lnum, &next_leader_len, &next_leader_flags, do_comments)) ! return TRUE; /* "lnum" is not a paragraph line */ if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) ! return TRUE; /* missing trailing space in previous line. */ if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) ! return TRUE; /* numbered item starts in "lnum". */ if (!same_leader(lnum - 1, leader_len, leader_flags, next_leader_len, next_leader_flags)) ! return TRUE; /* change of comment leader. */ return FALSE; } --- 2685,2719 ---- paragraph_start(linenr_T lnum) { char_u *p; ! int leader_len = 0; // leader len of current line ! char_u *leader_flags = NULL; // flags for leader of current line ! int next_leader_len; // leader len of next line ! char_u *next_leader_flags; // flags for leader of next line ! int do_comments; // format comments if (lnum <= 1) ! return TRUE; // start of the file p = ml_get(lnum - 1); if (*p == NUL) ! return TRUE; // after empty line do_comments = has_format_option(FO_Q_COMS); if (fmt_check_par(lnum - 1, &leader_len, &leader_flags, do_comments)) ! return TRUE; // after non-paragraph line if (fmt_check_par(lnum, &next_leader_len, &next_leader_flags, do_comments)) ! return TRUE; // "lnum" is not a paragraph line if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) ! return TRUE; // missing trailing space in previous line. if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) ! return TRUE; // numbered item starts in "lnum". if (!same_leader(lnum - 1, leader_len, leader_flags, next_leader_len, next_leader_flags)) ! return TRUE; // change of comment leader. return FALSE; } *************** *** 2769,2775 **** prev_pstart = line; while (bdp->start_vcol < oap->start_vcol && *pstart) { ! /* Count a tab for what it's worth (if list mode not on) */ incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); bdp->start_vcol += incr; if (VIM_ISWHITE(*pstart)) --- 2762,2768 ---- prev_pstart = line; while (bdp->start_vcol < oap->start_vcol && *pstart) { ! // Count a tab for what it's worth (if list mode not on) incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); bdp->start_vcol += incr; if (VIM_ISWHITE(*pstart)) *************** *** 2786,2792 **** MB_PTR_ADV(pstart); } bdp->start_char_vcols = incr; ! if (bdp->start_vcol < oap->start_vcol) /* line too short */ { bdp->end_vcol = bdp->start_vcol; bdp->is_short = TRUE; --- 2779,2785 ---- MB_PTR_ADV(pstart); } bdp->start_char_vcols = incr; ! if (bdp->start_vcol < oap->start_vcol) // line too short { bdp->end_vcol = bdp->start_vcol; bdp->is_short = TRUE; *************** *** 2795,2808 **** } else { ! /* notice: this converts partly selected Multibyte characters to ! * spaces, too. */ bdp->startspaces = bdp->start_vcol - oap->start_vcol; if (is_del && bdp->startspaces) bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; pend = pstart; bdp->end_vcol = bdp->start_vcol; ! if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ { bdp->is_oneChar = TRUE; if (oap->op_type == OP_INSERT) --- 2788,2801 ---- } else { ! // notice: this converts partly selected Multibyte characters to ! // spaces, too. bdp->startspaces = bdp->start_vcol - oap->start_vcol; if (is_del && bdp->startspaces) bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; pend = pstart; bdp->end_vcol = bdp->start_vcol; ! if (bdp->end_vcol > oap->end_vcol) // it's all in one character { bdp->is_oneChar = TRUE; if (oap->op_type == OP_INSERT) *************** *** 2817,2825 **** bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; if (is_del && oap->op_type != OP_LSHIFT) { ! /* just putting the sum of those two into ! * bdp->startspaces doesn't work for Visual replace, ! * so we have to split the tab in two */ bdp->startspaces = bdp->start_char_vcols - (bdp->start_vcol - oap->start_vcol); bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; --- 2810,2818 ---- bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; if (is_del && oap->op_type != OP_LSHIFT) { ! // just putting the sum of those two into ! // bdp->startspaces doesn't work for Visual replace, ! // so we have to split the tab in two bdp->startspaces = bdp->start_char_vcols - (bdp->start_vcol - oap->start_vcol); bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; *************** *** 2831,2837 **** prev_pend = pend; while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) { ! /* Count a tab for what it's worth (if list mode not on) */ prev_pend = pend; incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); bdp->end_vcol += incr; --- 2824,2830 ---- prev_pend = pend; while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) { ! // Count a tab for what it's worth (if list mode not on) prev_pend = pend; incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); bdp->end_vcol += incr; *************** *** 2839,2856 **** if (bdp->end_vcol <= oap->end_vcol && (!is_del || oap->op_type == OP_APPEND ! || oap->op_type == OP_REPLACE)) /* line too short */ { bdp->is_short = TRUE; ! /* Alternative: include spaces to fill up the block. ! * Disadvantage: can lead to trailing spaces when the line is ! * short where the text is put */ ! /* if (!is_del || oap->op_type == OP_APPEND) */ if (oap->op_type == OP_APPEND || virtual_op) bdp->endspaces = oap->end_vcol - bdp->end_vcol + oap->inclusive; else ! bdp->endspaces = 0; /* replace doesn't add characters */ } else if (bdp->end_vcol > oap->end_vcol) { --- 2832,2849 ---- if (bdp->end_vcol <= oap->end_vcol && (!is_del || oap->op_type == OP_APPEND ! || oap->op_type == OP_REPLACE)) // line too short { bdp->is_short = TRUE; ! // Alternative: include spaces to fill up the block. ! // Disadvantage: can lead to trailing spaces when the line is ! // short where the text is put ! // if (!is_del || oap->op_type == OP_APPEND) if (oap->op_type == OP_APPEND || virtual_op) bdp->endspaces = oap->end_vcol - bdp->end_vcol + oap->inclusive; else ! bdp->endspaces = 0; // replace doesn't add characters } else if (bdp->end_vcol > oap->end_vcol) { *************** *** 2878,2885 **** void op_addsub( oparg_T *oap, ! linenr_T Prenum1, /* Amount of add/subtract */ ! int g_cmd) /* was g/g */ { pos_T pos; struct block_def bd; --- 2871,2878 ---- void op_addsub( oparg_T *oap, ! linenr_T Prenum1, // Amount of add/subtract ! int g_cmd) // was g/g { pos_T pos; struct block_def bd; *************** *** 2928,2934 **** pos = oap->start; for (; pos.lnum <= oap->end.lnum; ++pos.lnum) { ! if (oap->block_mode) /* Visual block mode */ { block_prep(oap, &bd, pos.lnum, FALSE); pos.col = bd.textcol; --- 2921,2927 ---- pos = oap->start; for (; pos.lnum <= oap->end.lnum; ++pos.lnum) { ! if (oap->block_mode) // Visual block mode { block_prep(oap, &bd, pos.lnum, FALSE); pos.col = bd.textcol; *************** *** 2940,2946 **** pos.col = 0; length = (colnr_T)STRLEN(ml_get(pos.lnum)); } ! else /* oap->motion_type == MCHAR */ { if (pos.lnum == oap->start.lnum && !oap->inclusive) dec(&(oap->end)); --- 2933,2939 ---- pos.col = 0; length = (colnr_T)STRLEN(ml_get(pos.lnum)); } ! else // oap->motion_type == MCHAR { if (pos.lnum == oap->start.lnum && !oap->inclusive) dec(&(oap->end)); *************** *** 2962,2968 **** one_change = do_addsub(oap->op_type, &pos, length, amount); if (one_change) { ! /* Remember the start position of the first change. */ if (change_cnt == 0) startpos = curbuf->b_op_start; ++change_cnt; --- 2955,2961 ---- one_change = do_addsub(oap->op_type, &pos, length, amount); if (one_change) { ! // Remember the start position of the first change. if (change_cnt == 0) startpos = curbuf->b_op_start; ++change_cnt; *************** *** 2989,2999 **** changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); if (!change_cnt && oap->is_VIsual) ! /* No change: need to remove the Visual selection */ redraw_curbuf_later(INVERTED); ! /* Set '[ mark if something changed. Keep the last end ! * position from do_addsub(). */ if (change_cnt > 0 && !cmdmod.lockmarks) curbuf->b_op_start = startpos; --- 2982,2992 ---- changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); if (!change_cnt && oap->is_VIsual) ! // No change: need to remove the Visual selection redraw_curbuf_later(INVERTED); ! // Set '[ mark if something changed. Keep the last end ! // position from do_addsub(). if (change_cnt > 0 && !cmdmod.lockmarks) curbuf->b_op_start = startpos; *************** *** 3019,3026 **** int col; char_u *buf1; char_u buf2[NUMBUFLEN]; ! int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ ! static int hexupper = FALSE; /* 0xABC */ uvarnumber_T n; uvarnumber_T oldn; char_u *ptr; --- 3012,3019 ---- int col; char_u *buf1; char_u buf2[NUMBUFLEN]; ! int pre; // 'X'/'x': hex; '0': octal; 'B'/'b': bin ! static int hexupper = FALSE; // 0xABC uvarnumber_T n; uvarnumber_T oldn; char_u *ptr; *************** *** 3085,3091 **** && vim_isxdigit(ptr[col + 1])))) { ! /* In case of binary/hexadecimal pattern overlap match, rescan */ col = pos->col; --- 3078,3084 ---- && vim_isxdigit(ptr[col + 1])))) { ! // In case of binary/hexadecimal pattern overlap match, rescan col = pos->col; *************** *** 3114,3120 **** !(*mb_head_off)(ptr, ptr + col - 1)) && vim_isbdigit(ptr[col + 1]))) { ! /* Found hexadecimal or binary number, move to its start. */ --col; if (has_mbyte) col -= (*mb_head_off)(ptr, ptr + col); --- 3107,3113 ---- !(*mb_head_off)(ptr, ptr + col - 1)) && vim_isbdigit(ptr[col + 1]))) { ! // Found hexadecimal or binary number, move to its start. --col; if (has_mbyte) col -= (*mb_head_off)(ptr, ptr + col); *************** *** 3177,3183 **** if (doalp && ASCII_ISALPHA(firstdigit)) { ! /* decrement or increment alphabetic character */ if (op_type == OP_NR_SUB) { if (CharOrd(firstdigit) < Prenum1) --- 3170,3176 ---- if (doalp && ASCII_ISALPHA(firstdigit)) { ! // decrement or increment alphabetic character if (op_type == OP_NR_SUB) { if (CharOrd(firstdigit) < Prenum1) *************** *** 3226,3236 **** !(*mb_head_off)(ptr, ptr + col - 1)) && !visual) { ! /* negative number */ --col; negative = TRUE; } ! /* get the number value (unsigned) */ if (visual && VIsual_mode != 'V') maxlen = (curbuf->b_visual.vi_curswant == MAXCOL ? (int)STRLEN(ptr) - col --- 3219,3229 ---- !(*mb_head_off)(ptr, ptr + col - 1)) && !visual) { ! // negative number --col; negative = TRUE; } ! // get the number value (unsigned) if (visual && VIsual_mode != 'V') maxlen = (curbuf->b_visual.vi_curswant == MAXCOL ? (int)STRLEN(ptr) - col *************** *** 3242,3255 **** + (dohex ? STR2NR_HEX : 0), NULL, &n, maxlen, FALSE); ! /* ignore leading '-' for hex and octal and bin numbers */ if (pre && negative) { ++col; --length; negative = FALSE; } ! /* add or subtract */ subtract = FALSE; if (op_type == OP_NR_SUB) subtract ^= TRUE; --- 3235,3248 ---- + (dohex ? STR2NR_HEX : 0), NULL, &n, maxlen, FALSE); ! // ignore leading '-' for hex and octal and bin numbers if (pre && negative) { ++col; --length; negative = FALSE; } ! // add or subtract subtract = FALSE; if (op_type == OP_NR_SUB) subtract ^= TRUE; *************** *** 3261,3267 **** n -= (uvarnumber_T)Prenum1; else n += (uvarnumber_T)Prenum1; ! /* handle wraparound for decimal numbers */ if (!pre) { if (subtract) --- 3254,3260 ---- n -= (uvarnumber_T)Prenum1; else n += (uvarnumber_T)Prenum1; ! // handle wraparound for decimal numbers if (!pre) { if (subtract) *************** *** 3274,3280 **** } else { ! /* add */ if (n < oldn) { n = (n ^ (uvarnumber_T)-1); --- 3267,3273 ---- } else { ! // add if (n < oldn) { n = (n ^ (uvarnumber_T)-1); *************** *** 3287,3293 **** if (visual && !was_positive && !negative && col > 0) { ! /* need to remove the '-' */ col--; length++; } --- 3280,3286 ---- if (visual && !was_positive && !negative && col > 0) { ! // need to remove the '-' col--; length++; } *************** *** 3316,3322 **** else hexupper = FALSE; } ! /* del_char() will mark line needing displaying */ (void)del_char(FALSE); c = gchar_cursor(); } --- 3309,3315 ---- else hexupper = FALSE; } ! // del_char() will mark line needing displaying (void)del_char(FALSE); c = gchar_cursor(); } *************** *** 3353,3359 **** int bit = 0; int bits = sizeof(uvarnumber_T) * 8; ! /* leading zeros */ for (bit = bits; bit > 0; bit--) if ((n >> (bit - 1)) & 0x1) break; --- 3346,3352 ---- int bit = 0; int bits = sizeof(uvarnumber_T) * 8; ! // leading zeros for (bit = bits; bit > 0; bit--) if ((n >> (bit - 1)) & 0x1) break; *************** *** 3387,3393 **** *ptr++ = '0'; *ptr = NUL; STRCAT(buf1, buf2); ! ins_str(buf1); /* insert the new number */ vim_free(buf1); endpos = curwin->w_cursor; if (did_change && curwin->w_cursor.col) --- 3380,3386 ---- *ptr++ = '0'; *ptr = NUL; STRCAT(buf1, buf2); ! ins_str(buf1); // insert the new number vim_free(buf1); endpos = curwin->w_cursor; if (did_change && curwin->w_cursor.col) *************** *** 3396,3402 **** if (did_change && !cmdmod.lockmarks) { ! /* set the '[ and '] marks */ curbuf->b_op_start = startpos; curbuf->b_op_end = endpos; if (curbuf->b_op_end.col > 0) --- 3389,3395 ---- if (did_change && !cmdmod.lockmarks) { ! // set the '[ and '] marks curbuf->b_op_start = startpos; curbuf->b_op_end = endpos; if (curbuf->b_op_end.col > 0) *************** *** 3460,3481 **** return; # endif ! /* Get selection to export */ if (clip_plus.owned) motion_type = clip_convert_selection(&str, &len, &clip_plus); else if (clip_star.owned) motion_type = clip_convert_selection(&str, &len, &clip_star); ! /* Check it's OK */ if (dpy != NULL && str != NULL && motion_type >= 0 && len < 1024*1024 && len > 0) { int ok = TRUE; ! /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from ! * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit ! * encoding conversion usually doesn't work, so keep the text as-is. ! */ if (has_mbyte) { vimconv_T vc; --- 3453,3473 ---- return; # endif ! // Get selection to export if (clip_plus.owned) motion_type = clip_convert_selection(&str, &len, &clip_plus); else if (clip_star.owned) motion_type = clip_convert_selection(&str, &len, &clip_star); ! // Check it's OK if (dpy != NULL && str != NULL && motion_type >= 0 && len < 1024*1024 && len > 0) { int ok = TRUE; ! // The CUT_BUFFER0 is supposed to always contain latin1. Convert from ! // 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit ! // encoding conversion usually doesn't work, so keep the text as-is. if (has_mbyte) { vimconv_T vc; *************** *** 3506,3513 **** } } ! /* Do not store the string if conversion failed. Better to use any ! * other selection than garbled text. */ if (ok) { XStoreBuffer(dpy, (char *)str, (int)len, 0); --- 3498,3505 ---- } } ! // Do not store the string if conversion failed. Better to use any ! // other selection than garbled text. if (ok) { XStoreBuffer(dpy, (char *)str, (int)len, 0); *************** *** 3518,3524 **** vim_free(str); } #endif ! #endif /* FEAT_CLIPBOARD || PROTO */ void clear_oparg(oparg_T *oap) --- 3510,3516 ---- vim_free(str); } #endif ! #endif // FEAT_CLIPBOARD || PROTO void clear_oparg(oparg_T *oap) *************** *** 3573,3579 **** words++; *wc += words; ! /* Add eol_size if the end of line was reached before hitting limit. */ if (i < limit && line[i] == NUL) { i += eol_size; --- 3565,3571 ---- words++; *wc += words; ! // Add eol_size if the end of line was reached before hitting limit. if (i < limit && line[i] == NUL) { i += eol_size; *************** *** 3649,3655 **** char_u * saved_sbr = p_sbr; char_u * saved_w_sbr = curwin->w_p_sbr; ! /* Make 'sbr' empty for a moment to get the correct size. */ p_sbr = empty_option; curwin->w_p_sbr = empty_option; #endif --- 3641,3647 ---- char_u * saved_sbr = p_sbr; char_u * saved_w_sbr = curwin->w_p_sbr; ! // Make 'sbr' empty for a moment to get the correct size. p_sbr = empty_option; curwin->w_p_sbr = empty_option; #endif *************** *** 3664,3670 **** #endif if (curwin->w_curswant == MAXCOL) oparg.end_vcol = MAXCOL; ! /* Swap the start, end vcol if needed */ if (oparg.end_vcol < oparg.start_vcol) { oparg.end_vcol += oparg.start_vcol; --- 3656,3662 ---- #endif if (curwin->w_curswant == MAXCOL) oparg.end_vcol = MAXCOL; ! // Swap the start, end vcol if needed if (oparg.end_vcol < oparg.start_vcol) { oparg.end_vcol += oparg.start_vcol; *************** *** 3677,3683 **** for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) { ! /* Check for a CTRL-C every 100000 characters. */ if (byte_count > last_check) { ui_breakcheck(); --- 3669,3675 ---- for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) { ! // Check for a CTRL-C every 100000 characters. if (byte_count > last_check) { ui_breakcheck(); *************** *** 3686,3692 **** last_check = byte_count + 100000L; } ! /* Do extra processing for VIsual mode. */ if (VIsual_active && lnum >= min_pos.lnum && lnum <= max_pos.lnum) { --- 3678,3684 ---- last_check = byte_count + 100000L; } ! // Do extra processing for VIsual mode. if (VIsual_active && lnum >= min_pos.lnum && lnum <= max_pos.lnum) { *************** *** 3731,3737 **** } else { ! /* In non-visual mode, check for the line the cursor is on */ if (lnum == curwin->w_cursor.lnum) { word_count_cursor += word_count; --- 3723,3729 ---- } else { ! // In non-visual mode, check for the line the cursor is on if (lnum == curwin->w_cursor.lnum) { word_count_cursor += word_count; *************** *** 3743,3755 **** eol_size); } } ! /* Add to the running totals */ byte_count += line_count_info(ml_get(lnum), &word_count, &char_count, (varnumber_T)MAXCOL, eol_size); } ! /* Correction for when last line doesn't have an EOL. */ if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) byte_count -= eol_size; --- 3735,3747 ---- eol_size); } } ! // Add to the running totals byte_count += line_count_info(ml_get(lnum), &word_count, &char_count, (varnumber_T)MAXCOL, eol_size); } ! // Correction for when last line doesn't have an EOL. if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) byte_count -= eol_size; *************** *** 4328,4334 **** if (cap->cmdchar == 'g' && (cap->nchar == 'n' || cap->nchar == 'N')) prep_redo(oap->regname, cap->count0, ! get_op_char(oap->op_type), get_extra_op_char(oap->op_type), oap->motion_force, cap->cmdchar, cap->nchar); else if (cap->cmdchar != ':') { --- 4320,4327 ---- if (cap->cmdchar == 'g' && (cap->nchar == 'n' || cap->nchar == 'N')) prep_redo(oap->regname, cap->count0, ! get_op_char(oap->op_type), ! get_extra_op_char(oap->op_type), oap->motion_force, cap->cmdchar, cap->nchar); else if (cap->cmdchar != ':') { *** ../vim-8.1.2391/src/option.c 2019-11-21 22:14:14.353810993 +0100 --- src/option.c 2019-12-05 20:11:19.220244022 +0100 *************** *** 81,90 **** langmap_init(); #endif ! /* Be Vi compatible by default */ p_cp = TRUE; ! /* Use POSIX compatibility when $VIM_POSIX is set. */ if (mch_getenv((char_u *)"VIM_POSIX") != NULL) { set_string_default("cpo", (char_u *)CPO_ALL); --- 81,90 ---- langmap_init(); #endif ! // Be Vi compatible by default p_cp = TRUE; ! // Use POSIX compatibility when $VIM_POSIX is set. if (mch_getenv((char_u *)"VIM_POSIX") != NULL) { set_string_default("cpo", (char_u *)CPO_ALL); *************** *** 156,162 **** p = vim_getenv((char_u *)names[n], &mustfree); if (p != NULL && *p != NUL) { ! /* First time count the NUL, otherwise count the ','. */ len = (int)STRLEN(p) + 3; if (ga_grow(&ga, len) == OK) { --- 156,162 ---- p = vim_getenv((char_u *)names[n], &mustfree); if (p != NULL && *p != NUL) { ! // First time count the NUL, otherwise count the ','. len = (int)STRLEN(p) + 3; if (ga_grow(&ga, len) == OK) { *************** *** 190,200 **** #endif { #ifdef HAVE_AVAIL_MEM ! /* Use amount of memory available at this moment. */ n = (mch_avail_mem(FALSE) >> 1); #else # ifdef HAVE_TOTAL_MEM ! /* Use amount of memory available to Vim. */ n = (mch_total_mem(FALSE) >> 1); # else n = (0x7fffffff >> 11); --- 190,200 ---- #endif { #ifdef HAVE_AVAIL_MEM ! // Use amount of memory available at this moment. n = (mch_avail_mem(FALSE) >> 1); #else # ifdef HAVE_TOTAL_MEM ! // Use amount of memory available to Vim. n = (mch_total_mem(FALSE) >> 1); # else n = (0x7fffffff >> 11); *************** *** 221,234 **** int j; int mustfree = FALSE; ! /* Initialize the 'cdpath' option's default value. */ cdpath = vim_getenv((char_u *)"CDPATH", &mustfree); if (cdpath != NULL) { buf = alloc((STRLEN(cdpath) << 1) + 2); if (buf != NULL) { ! buf[0] = ','; /* start with ",", current dir first */ j = 1; for (i = 0; cdpath[i] != NUL; ++i) { --- 221,234 ---- int j; int mustfree = FALSE; ! // Initialize the 'cdpath' option's default value. cdpath = vim_getenv((char_u *)"CDPATH", &mustfree); if (cdpath != NULL) { buf = alloc((STRLEN(cdpath) << 1) + 2); if (buf != NULL) { ! buf[0] = ','; // start with ",", current dir first j = 1; for (i = 0; cdpath[i] != NUL; ++i) { *************** *** 249,255 **** options[opt_idx].flags |= P_DEF_ALLOCED; } else ! vim_free(buf); /* cannot happen */ } if (mustfree) vim_free(cdpath); --- 249,255 ---- options[opt_idx].flags |= P_DEF_ALLOCED; } else ! vim_free(buf); // cannot happen } if (mustfree) vim_free(cdpath); *************** *** 258,264 **** #endif #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux)) ! /* Set print encoding on platforms that don't default to latin1 */ set_string_default("penc", # if defined(MSWIN) (char_u *)"cp1252" --- 258,264 ---- #endif #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux)) ! // Set print encoding on platforms that don't default to latin1 set_string_default("penc", # if defined(MSWIN) (char_u *)"cp1252" *************** *** 271,277 **** # else # ifdef MAC (char_u *)"mac-roman" ! # else /* HPUX */ (char_u *)"hp-roman8" # endif # endif --- 271,277 ---- # else # ifdef MAC (char_u *)"mac-roman" ! # else // HPUX (char_u *)"hp-roman8" # endif # endif *************** *** 281,287 **** #endif #ifdef FEAT_POSTSCRIPT ! /* 'printexpr' must be allocated to be able to evaluate it. */ set_string_default("pexpr", # if defined(MSWIN) (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)" --- 281,287 ---- #endif #ifdef FEAT_POSTSCRIPT ! // 'printexpr' must be allocated to be able to evaluate it. set_string_default("pexpr", # if defined(MSWIN) (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)" *************** *** 326,343 **** #endif curbuf->b_p_initialized = TRUE; ! curbuf->b_p_ar = -1; /* no local 'autoread' value */ curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL; check_buf_options(curbuf); check_win_options(curwin); check_options(); ! /* Must be before option_expand(), because that one needs vim_isIDc() */ didset_options(); #ifdef FEAT_SPELL ! /* Use the current chartab for the generic chartab. This is not in ! * didset_options() because it only depends on 'encoding'. */ init_spell_chartab(); #endif --- 326,343 ---- #endif curbuf->b_p_initialized = TRUE; ! curbuf->b_p_ar = -1; // no local 'autoread' value curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL; check_buf_options(curbuf); check_win_options(curwin); check_options(); ! // Must be before option_expand(), because that one needs vim_isIDc() didset_options(); #ifdef FEAT_SPELL ! // Use the current chartab for the generic chartab. This is not in ! // didset_options() because it only depends on 'encoding'. init_spell_chartab(); #endif *************** *** 360,370 **** if (p != NULL && (p = vim_strsave(p)) != NULL) { *(char_u **)options[opt_idx].var = p; ! /* VIMEXP ! * Defaults for all expanded options are currently the same for Vi ! * and Vim. When this changes, add some code here! Also need to ! * split P_DEF_ALLOCED in two. ! */ if (options[opt_idx].flags & P_DEF_ALLOCED) vim_free(options[opt_idx].def_val[VI_DEFAULT]); options[opt_idx].def_val[VI_DEFAULT] = p; --- 360,369 ---- if (p != NULL && (p = vim_strsave(p)) != NULL) { *(char_u **)options[opt_idx].var = p; ! // VIMEXP ! // Defaults for all expanded options are currently the same for Vi ! // and Vim. When this changes, add some code here! Also need to ! // split P_DEF_ALLOCED in two. if (options[opt_idx].flags & P_DEF_ALLOCED) vim_free(options[opt_idx].def_val[VI_DEFAULT]); options[opt_idx].def_val[VI_DEFAULT] = p; *************** *** 372,386 **** } } ! save_file_ff(curbuf); /* Buffer is unchanged */ #if defined(FEAT_ARABIC) ! /* Detect use of mlterm. ! * Mlterm is a terminal emulator akin to xterm that has some special ! * abilities (bidi namely). ! * NOTE: mlterm's author is being asked to 'set' a variable ! * instead of an environment variable due to inheritance. ! */ if (mch_getenv((char_u *)"MLTERM") != NULL) set_option_value((char_u *)"tbidi", 1L, NULL, 0); #endif --- 371,384 ---- } } ! save_file_ff(curbuf); // Buffer is unchanged #if defined(FEAT_ARABIC) ! // Detect use of mlterm. ! // Mlterm is a terminal emulator akin to xterm that has some special ! // abilities (bidi namely). ! // NOTE: mlterm's author is being asked to 'set' a variable ! // instead of an environment variable due to inheritance. if (mch_getenv((char_u *)"MLTERM") != NULL) set_option_value((char_u *)"tbidi", 1L, NULL, 0); #endif *************** *** 396,409 **** { char buf[20]; ! /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95. ! * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use ! * only the first two. */ n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, (LPTSTR)buf, 20); if (n >= 2 && STRNICMP(buf, "en", 2) != 0) { ! /* There are a few exceptions (probably more) */ if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0) STRCPY(buf, "zh_TW"); else if (STRNICMP(buf, "chs", 3) == 0 --- 394,407 ---- { char buf[20]; ! // Could use LOCALE_SISO639LANGNAME, but it's not in Win95. ! // LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use ! // only the first two. n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, (LPTSTR)buf, 20); if (n >= 2 && STRNICMP(buf, "en", 2) != 0) { ! // There are a few exceptions (probably more) if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0) STRCPY(buf, "zh_TW"); else if (STRNICMP(buf, "chs", 3) == 0 *************** *** 412,443 **** else if (STRNICMP(buf, "jp", 2) == 0) STRCPY(buf, "ja"); else ! buf[2] = NUL; /* truncate to two-letter code */ vim_setenv((char_u *)"LANG", (char_u *)buf); } } # else # ifdef MACOS_CONVERT ! /* Moved to os_mac_conv.c to avoid dependency problems. */ mac_lang_init(); # endif # endif ! /* enc_locale() will try to find the encoding of the current locale. */ p = enc_locale(); if (p != NULL) { char_u *save_enc; ! /* Try setting 'encoding' and check if the value is valid. ! * If not, go back to the default "latin1". */ save_enc = p_enc; p_enc = p; if (STRCMP(p_enc, "gb18030") == 0) { ! /* We don't support "gb18030", but "cp936" is a good substitute ! * for practical purposes, thus use that. It's not an alias to ! * still support conversion between gb18030 and utf-8. */ p_enc = vim_strsave((char_u *)"cp936"); vim_free(p); } --- 410,441 ---- else if (STRNICMP(buf, "jp", 2) == 0) STRCPY(buf, "ja"); else ! buf[2] = NUL; // truncate to two-letter code vim_setenv((char_u *)"LANG", (char_u *)buf); } } # else # ifdef MACOS_CONVERT ! // Moved to os_mac_conv.c to avoid dependency problems. mac_lang_init(); # endif # endif ! // enc_locale() will try to find the encoding of the current locale. p = enc_locale(); if (p != NULL) { char_u *save_enc; ! // Try setting 'encoding' and check if the value is valid. ! // If not, go back to the default "latin1". save_enc = p_enc; p_enc = p; if (STRCMP(p_enc, "gb18030") == 0) { ! // We don't support "gb18030", but "cp936" is a good substitute ! // for practical purposes, thus use that. It's not an alias to ! // still support conversion between gb18030 and utf-8. p_enc = vim_strsave((char_u *)"cp936"); vim_free(p); } *************** *** 453,461 **** #if defined(MSWIN) || defined(MACOS_X) || defined(VMS) if (STRCMP(p_enc, "latin1") == 0 || enc_utf8) { ! /* Adjust the default for 'isprint' and 'iskeyword' to match ! * latin1. Also set the defaults for when 'nocompatible' is ! * set. */ set_string_option_direct((char_u *)"isp", -1, ISP_LATIN1, OPT_FREE, SID_NONE); set_string_option_direct((char_u *)"isk", -1, --- 451,459 ---- #if defined(MSWIN) || defined(MACOS_X) || defined(VMS) if (STRCMP(p_enc, "latin1") == 0 || enc_utf8) { ! // Adjust the default for 'isprint' and 'iskeyword' to match ! // latin1. Also set the defaults for when 'nocompatible' is ! // set. set_string_option_direct((char_u *)"isp", -1, ISP_LATIN1, OPT_FREE, SID_NONE); set_string_option_direct((char_u *)"isk", -1, *************** *** 471,478 **** #endif #if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL)) ! /* Win32 console: When GetACP() returns a different value from ! * GetConsoleCP() set 'termencoding'. */ if ( # ifdef VIMDLL (!gui.in_use && !gui.starting) && --- 469,476 ---- #endif #if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL)) ! // Win32 console: When GetACP() returns a different value from ! // GetConsoleCP() set 'termencoding'. if ( # ifdef VIMDLL (!gui.in_use && !gui.starting) && *************** *** 481,488 **** { char buf[50]; ! /* Win32 console: In ConPTY, GetConsoleCP() returns zero. ! * Use an alternative value. */ if (GetConsoleCP() == 0) sprintf(buf, "cp%ld", (long)GetACP()); else --- 479,486 ---- { char buf[50]; ! // Win32 console: In ConPTY, GetConsoleCP() returns zero. ! // Use an alternative value. if (GetConsoleCP() == 0) sprintf(buf, "cp%ld", (long)GetACP()); else *************** *** 504,510 **** } #endif #if defined(MSWIN) ! /* $HOME may have characters in active code page. */ init_homedir(); #endif } --- 502,508 ---- } #endif #if defined(MSWIN) ! // $HOME may have characters in active code page. init_homedir(); #endif } *************** *** 516,522 **** } #ifdef FEAT_MULTI_LANG ! /* Set the default for 'helplang'. */ set_helplang_default(get_mess_lang()); #endif } --- 514,520 ---- } #ifdef FEAT_MULTI_LANG ! // Set the default for 'helplang'. set_helplang_default(get_mess_lang()); #endif } *************** *** 528,551 **** static void set_option_default( int opt_idx, ! int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */ ! int compatible) /* use Vi default value */ { ! char_u *varp; /* pointer to variable for current option */ ! int dvi; /* index in def_val[] */ long_u flags; long_u *flagsp; int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); flags = options[opt_idx].flags; ! if (varp != NULL) /* skip hidden option, nothing to do for it */ { dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; if (flags & P_STRING) { ! /* Use set_string_option_direct() for local options to handle ! * freeing and allocating the value. */ if (options[opt_idx].indir != PV_NONE) set_string_option_direct(NULL, opt_idx, options[opt_idx].def_val[dvi], opt_flags, 0); --- 526,549 ---- static void set_option_default( int opt_idx, ! int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL ! int compatible) // use Vi default value { ! char_u *varp; // pointer to variable for current option ! int dvi; // index in def_val[] long_u flags; long_u *flagsp; int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); flags = options[opt_idx].flags; ! if (varp != NULL) // skip hidden option, nothing to do for it { dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; if (flags & P_STRING) { ! // Use set_string_option_direct() for local options to handle ! // freeing and allocating the value. if (options[opt_idx].indir != PV_NONE) set_string_option_direct(NULL, opt_idx, options[opt_idx].def_val[dvi], opt_flags, 0); *************** *** 572,600 **** *(long *)varp = -1; else *(long *)varp = def_val; ! /* May also set global value for local option. */ if (both) *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = def_val; } } ! else /* P_BOOL */ { ! /* the cast to long is required for Manx C, long_i is needed for ! * MSVC */ *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi]; #ifdef UNIX ! /* 'modeline' defaults to off for root */ if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID) *(int *)varp = FALSE; #endif ! /* May also set global value for local option. */ if (both) *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *(int *)varp; } ! /* The default value is not insecure. */ flagsp = insecure_flag(opt_idx, opt_flags); *flagsp = *flagsp & ~P_INSECURE; } --- 570,598 ---- *(long *)varp = -1; else *(long *)varp = def_val; ! // May also set global value for local option. if (both) *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = def_val; } } ! else // P_BOOL { ! // the cast to long is required for Manx C, long_i is needed for ! // MSVC *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi]; #ifdef UNIX ! // 'modeline' defaults to off for root if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID) *(int *)varp = FALSE; #endif ! // May also set global value for local option. if (both) *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *(int *)varp; } ! // The default value is not insecure. flagsp = insecure_flag(opt_idx, opt_flags); *flagsp = *flagsp & ~P_INSECURE; } *************** *** 610,616 **** */ static void set_options_default( ! int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */ { int i; win_T *wp; --- 608,614 ---- */ static void set_options_default( ! int opt_flags) // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL { int i; win_T *wp; *************** *** 627,633 **** ))) set_option_default(i, opt_flags, p_cp); ! /* The 'scroll' option must be computed for all windows. */ FOR_ALL_TAB_WINDOWS(tp, wp) win_comp_scroll(wp); #ifdef FEAT_CINDENT --- 625,631 ---- ))) set_option_default(i, opt_flags, p_cp); ! // The 'scroll' option must be computed for all windows. FOR_ALL_TAB_WINDOWS(tp, wp) win_comp_scroll(wp); #ifdef FEAT_CINDENT *************** *** 650,656 **** p = vim_strsave_escaped(val, (char_u *)" "); else p = vim_strsave(val); ! if (p != NULL) /* we don't want a NULL */ { opt_idx = findoption((char_u *)name); if (opt_idx >= 0) --- 648,654 ---- p = vim_strsave_escaped(val, (char_u *)" "); else p = vim_strsave(val); ! if (p != NULL) // we don't want a NULL { opt_idx = findoption((char_u *)name); if (opt_idx >= 0) *************** *** 728,734 **** { if (options[i].indir == PV_NONE) { ! /* global option: free value and default value. */ if ((options[i].flags & P_ALLOCED) && options[i].var != NULL) free_string_option(*(char_u **)options[i].var); if (options[i].flags & P_DEF_ALLOCED) --- 726,732 ---- { if (options[i].indir == PV_NONE) { ! // global option: free value and default value. if ((options[i].flags & P_ALLOCED) && options[i].var != NULL) free_string_option(*(char_u **)options[i].var); if (options[i].flags & P_DEF_ALLOCED) *************** *** 736,742 **** } else if (options[i].var != VAR_WIN && (options[i].flags & P_STRING)) ! /* buffer-local option: free global value */ free_string_option(*(char_u **)options[i].var); } } --- 734,740 ---- } else if (options[i].var != VAR_WIN && (options[i].flags & P_STRING)) ! // buffer-local option: free global value free_string_option(*(char_u **)options[i].var); } } *************** *** 769,775 **** p_window = Rows - 1; set_number_default("window", Rows - 1); ! /* For DOS console the default is always black. */ #if !((defined(MSWIN)) && !defined(FEAT_GUI)) /* * If 'background' wasn't set by the user, try guessing the value, --- 767,773 ---- p_window = Rows - 1; set_number_default("window", Rows - 1); ! // For DOS console the default is always black. #if !((defined(MSWIN)) && !defined(FEAT_GUI)) /* * If 'background' wasn't set by the user, try guessing the value, *************** *** 781,800 **** && *term_bg_default() == 'd') { set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0); ! /* don't mark it as set, when starting the GUI it may be ! * changed again */ options[idx].flags &= ~P_WAS_SET; } #endif #ifdef CURSOR_SHAPE ! parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */ #endif #ifdef FEAT_MOUSESHAPE ! parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */ #endif #ifdef FEAT_PRINTER ! (void)parse_printoptions(); /* parse 'printoptions' default value */ #endif } --- 779,798 ---- && *term_bg_default() == 'd') { set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0); ! // don't mark it as set, when starting the GUI it may be ! // changed again options[idx].flags &= ~P_WAS_SET; } #endif #ifdef CURSOR_SHAPE ! parse_shape_opt(SHAPE_CURSOR); // set cursor shapes from 'guicursor' #endif #ifdef FEAT_MOUSESHAPE ! parse_shape_opt(SHAPE_MOUSE); // set mouse shapes from 'mouseshape' #endif #ifdef FEAT_PRINTER ! (void)parse_printoptions(); // parse 'printoptions' default value #endif } *************** *** 863,869 **** } } else ! /* Always use bourne shell style redirection if we reach this */ if ( fnamecmp(p, "sh") == 0 || fnamecmp(p, "ksh") == 0 || fnamecmp(p, "mksh") == 0 --- 861,867 ---- } } else ! // Always use bourne shell style redirection if we reach this if ( fnamecmp(p, "sh") == 0 || fnamecmp(p, "ksh") == 0 || fnamecmp(p, "mksh") == 0 *************** *** 926,932 **** options[idx3].def_val[VI_DEFAULT] = p_shcf; } ! /* Somehow Win32 requires the quotes around the redirection too */ idx3 = findoption((char_u *)"sxq"); if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) { --- 924,930 ---- options[idx3].def_val[VI_DEFAULT] = p_shcf; } ! // Somehow Win32 requires the quotes around the redirection too idx3 = findoption((char_u *)"sxq"); if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) { *************** *** 971,977 **** { int idx_ffs = findoption((char_u *)"ffs"); ! /* Apply the first entry of 'fileformats' to the initial buffer. */ if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET)) set_fileformat(default_fileformat(), OPT_LOCAL); } --- 969,975 ---- { int idx_ffs = findoption((char_u *)"ffs"); ! // Apply the first entry of 'fileformats' to the initial buffer. if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET)) set_fileformat(default_fileformat(), OPT_LOCAL); } *************** *** 991,997 **** { int idx; ! if (lang == NULL || STRLEN(lang) < 2) /* safety check */ return; idx = findoption((char_u *)"hlg"); if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) --- 989,995 ---- { int idx; ! if (lang == NULL || STRLEN(lang) < 2) // safety check return; idx = findoption((char_u *)"hlg"); if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) *************** *** 1085,1110 **** */ int do_set( ! char_u *arg, /* option string (may be written to!) */ int opt_flags) { int opt_idx; char *errmsg; char errbuf[80]; char_u *startarg; ! int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */ ! int nextchar; /* next non-white char after option name */ ! int afterchar; /* character just after option name */ int len; int i; varnumber_T value; int key; ! long_u flags; /* flags for current option */ ! char_u *varp = NULL; /* pointer to variable for current option */ ! int did_show = FALSE; /* already showed one value */ ! int adding; /* "opt+=arg" */ ! int prepending; /* "opt^=arg" */ ! int removing; /* "opt-=arg" */ int cp_val = 0; char_u key_name[2]; --- 1083,1108 ---- */ int do_set( ! char_u *arg, // option string (may be written to!) int opt_flags) { int opt_idx; char *errmsg; char errbuf[80]; char_u *startarg; ! int prefix; // 1: nothing, 0: "no", 2: "inv" in front of name ! int nextchar; // next non-white char after option name ! int afterchar; // character just after option name int len; int i; varnumber_T value; int key; ! long_u flags; // flags for current option ! char_u *varp = NULL; // pointer to variable for current option ! int did_show = FALSE; // already showed one value ! int adding; // "opt+=arg" ! int prepending; // "opt^=arg" ! int removing; // "opt-=arg" int cp_val = 0; char_u key_name[2]; *************** *** 1115,1124 **** goto theend; } ! while (*arg != NUL) /* loop to process all options */ { errmsg = NULL; ! startarg = arg; /* remember for error message */ if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]) && !(opt_flags & OPT_MODELINE)) --- 1113,1122 ---- goto theend; } ! while (*arg != NUL) // loop to process all options { errmsg = NULL; ! startarg = arg; // remember for error message if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]) && !(opt_flags & OPT_MODELINE)) *************** *** 1131,1137 **** if (*arg == '&') { ++arg; ! /* Only for :set command set global value of local options. */ set_options_default(OPT_FREE | opt_flags); didset_options(); didset_options2(); --- 1129,1135 ---- if (*arg == '&') { ++arg; ! // Only for :set command set global value of local options. set_options_default(OPT_FREE | opt_flags); didset_options(); didset_options2(); *************** *** 1164,1175 **** arg += 3; } ! /* find end of name */ key = 0; if (*arg == '<') { opt_idx = -1; ! /* look out for ;> */ if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4]) len = 5; else --- 1162,1173 ---- arg += 3; } ! // find end of name key = 0; if (*arg == '<') { opt_idx = -1; ! // look out for ;> if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4]) len = 5; else *************** *** 1183,1192 **** errmsg = e_invarg; goto skip; } ! arg[len] = NUL; /* put NUL after name */ ! if (arg[1] == 't' && arg[2] == '_') /* could be term code */ opt_idx = findoption(arg + 1); ! arg[len++] = '>'; /* restore '>' */ if (opt_idx == -1) key = find_key_option(arg + 1, TRUE); } --- 1181,1190 ---- errmsg = e_invarg; goto skip; } ! arg[len] = NUL; // put NUL after name ! if (arg[1] == 't' && arg[2] == '_') // could be term code opt_idx = findoption(arg + 1); ! arg[len++] = '>'; // restore '>' if (opt_idx == -1) key = find_key_option(arg + 1, TRUE); } *************** *** 1202,1218 **** while (ASCII_ISALNUM(arg[len]) || arg[len] == '_') ++len; nextchar = arg[len]; ! arg[len] = NUL; /* put NUL after name */ opt_idx = findoption(arg); ! arg[len] = nextchar; /* restore nextchar */ if (opt_idx == -1) key = find_key_option(arg, FALSE); } ! /* remember character after option name */ afterchar = arg[len]; ! /* skip white space, allow ":set ai ?" */ while (VIM_ISWHITE(arg[len])) ++len; --- 1200,1216 ---- while (ASCII_ISALNUM(arg[len]) || arg[len] == '_') ++len; nextchar = arg[len]; ! arg[len] = NUL; // put NUL after name opt_idx = findoption(arg); ! arg[len] = nextchar; // restore nextchar if (opt_idx == -1) key = find_key_option(arg, FALSE); } ! // remember character after option name afterchar = arg[len]; ! // skip white space, allow ":set ai ?" while (VIM_ISWHITE(arg[len])) ++len; *************** *** 1223,1245 **** { if (arg[len] == '+') { ! adding = TRUE; /* "+=" */ ++len; } else if (arg[len] == '^') { ! prepending = TRUE; /* "^=" */ ++len; } else if (arg[len] == '-') { ! removing = TRUE; /* "-=" */ ++len; } } nextchar = arg[len]; ! if (opt_idx == -1 && key == 0) /* found a mismatch: skip */ { errmsg = N_("E518: Unknown option"); goto skip; --- 1221,1243 ---- { if (arg[len] == '+') { ! adding = TRUE; // "+=" ++len; } else if (arg[len] == '^') { ! prepending = TRUE; // "^=" ++len; } else if (arg[len] == '-') { ! removing = TRUE; // "-=" ++len; } } nextchar = arg[len]; ! if (opt_idx == -1 && key == 0) // found a mismatch: skip { errmsg = N_("E518: Unknown option"); goto skip; *************** *** 1247,1256 **** if (opt_idx >= 0) { ! if (options[opt_idx].var == NULL) /* hidden option: skip */ { ! /* Only give an error message when requesting the value of ! * a hidden option, ignore setting it. */ if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL && (!(options[opt_idx].flags & P_BOOL) || nextchar == '?')) --- 1245,1254 ---- if (opt_idx >= 0) { ! if (options[opt_idx].var == NULL) // hidden option: skip { ! // Only give an error message when requesting the value of ! // a hidden option, ignore setting it. if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL && (!(options[opt_idx].flags & P_BOOL) || nextchar == '?')) *************** *** 1276,1293 **** } } ! /* Skip all options that are not window-local (used when showing ! * an already loaded buffer in a window). */ if ((opt_flags & OPT_WINONLY) && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) goto skip; ! /* Skip all options that are window-local (used for :vimgrep). */ if ((opt_flags & OPT_NOWIN) && opt_idx >= 0 && options[opt_idx].var == VAR_WIN) goto skip; ! /* Disallow changing some options from modelines. */ if (opt_flags & OPT_MODELINE) { if (flags & (P_SECURE | P_NO_ML)) --- 1274,1291 ---- } } ! // Skip all options that are not window-local (used when showing ! // an already loaded buffer in a window). if ((opt_flags & OPT_WINONLY) && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) goto skip; ! // Skip all options that are window-local (used for :vimgrep). if ((opt_flags & OPT_NOWIN) && opt_idx >= 0 && options[opt_idx].var == VAR_WIN) goto skip; ! // Disallow changing some options from modelines. if (opt_flags & OPT_MODELINE) { if (flags & (P_SECURE | P_NO_ML)) *************** *** 1301,1311 **** goto skip; } #ifdef FEAT_DIFF ! /* In diff mode some options are overruled. This avoids that ! * 'foldmethod' becomes "marker" instead of "diff" and that ! * "wrap" gets set. */ if (curwin->w_p_diff ! && opt_idx >= 0 /* shut up coverity warning */ && ( #ifdef FEAT_FOLDING options[opt_idx].indir == PV_FDM || --- 1299,1309 ---- goto skip; } #ifdef FEAT_DIFF ! // In diff mode some options are overruled. This avoids that ! // 'foldmethod' becomes "marker" instead of "diff" and that ! // "wrap" gets set. if (curwin->w_p_diff ! && opt_idx >= 0 // shut up coverity warning && ( #ifdef FEAT_FOLDING options[opt_idx].indir == PV_FDM || *************** *** 1316,1322 **** } #ifdef HAVE_SANDBOX ! /* Disallow changing some options in the sandbox */ if (sandbox != 0 && (flags & P_SECURE)) { errmsg = _(e_sandbox); --- 1314,1320 ---- } #ifdef HAVE_SANDBOX ! // Disallow changing some options in the sandbox if (sandbox != 0 && (flags & P_SECURE)) { errmsg = _(e_sandbox); *************** *** 1330,1341 **** cp_val = p_cp; if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i') { ! if (arg[3] == 'm') /* "opt&vim": set to Vim default */ { cp_val = FALSE; arg += 3; } ! else /* "opt&vi": set to Vi default */ { cp_val = TRUE; arg += 2; --- 1328,1339 ---- cp_val = p_cp; if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i') { ! if (arg[3] == 'm') // "opt&vim": set to Vim default { cp_val = FALSE; arg += 3; } ! else // "opt&vi": set to Vi default { cp_val = TRUE; arg += 2; *************** *** 1362,1372 **** * print value */ if (did_show) ! msg_putchar('\n'); /* cursor below last one */ else { ! gotocmdline(TRUE); /* cursor at status line */ ! did_show = TRUE; /* remember that we did a line */ } if (opt_idx >= 0) { --- 1360,1370 ---- * print value */ if (did_show) ! msg_putchar('\n'); // cursor below last one else { ! gotocmdline(TRUE); // cursor at status line ! did_show = TRUE; // remember that we did a line } if (opt_idx >= 0) { *************** *** 1374,1380 **** #ifdef FEAT_EVAL if (p_verbose > 0) { ! /* Mention where the option was last set. */ if (varp == options[opt_idx].var) last_set_msg(options[opt_idx].script_ctx); else if ((int)options[opt_idx].indir & PV_WIN) --- 1372,1378 ---- #ifdef FEAT_EVAL if (p_verbose > 0) { ! // Mention where the option was last set. if (varp == options[opt_idx].var) last_set_msg(options[opt_idx].script_ctx); else if ((int)options[opt_idx].indir & PV_WIN) *************** *** 1408,1414 **** int value_is_replaced = !prepending && !adding && !removing; int value_checked = FALSE; ! if (flags & P_BOOL) /* boolean */ { if (nextchar == '=' || nextchar == ':') { --- 1406,1412 ---- int value_is_replaced = !prepending && !adding && !removing; int value_checked = FALSE; ! if (flags & P_BOOL) // boolean { if (nextchar == '=' || nextchar == ':') { *************** *** 1429,1435 **** ? VI_DEFAULT : VIM_DEFAULT]; else if (nextchar == '<') { ! /* For 'autoread' -1 means to use global value. */ if ((int *)varp == &curbuf->b_p_ar && opt_flags == OPT_LOCAL) value = -1; --- 1427,1433 ---- ? VI_DEFAULT : VIM_DEFAULT]; else if (nextchar == '<') { ! // For 'autoread' -1 means to use global value. if ((int *)varp == &curbuf->b_p_ar && opt_flags == OPT_LOCAL) value = -1; *************** *** 1448,1454 **** errmsg = e_trailing; goto skip; } ! if (prefix == 2) /* inv */ value = *(int *)(varp) ^ 1; else value = prefix; --- 1446,1452 ---- errmsg = e_trailing; goto skip; } ! if (prefix == 2) // inv value = *(int *)(varp) ^ 1; else value = prefix; *************** *** 1457,1463 **** errmsg = set_bool_option(opt_idx, varp, (int)value, opt_flags); } ! else /* numeric or string */ { if (vim_strchr((char_u *)"=:&<", nextchar) == NULL || prefix != 1) --- 1455,1461 ---- errmsg = set_bool_option(opt_idx, varp, (int)value, opt_flags); } ! else // numeric or string { if (vim_strchr((char_u *)"=:&<", nextchar) == NULL || prefix != 1) *************** *** 1466,1472 **** goto skip; } ! if (flags & P_NUM) /* numeric */ { /* * Different ways to set a number option: --- 1464,1470 ---- goto skip; } ! if (flags & P_NUM) // numeric { /* * Different ways to set a number option: *************** *** 1484,1491 **** ? VI_DEFAULT : VIM_DEFAULT]; else if (nextchar == '<') { ! /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to ! * use the global value. */ if ((long *)varp == &curbuf->b_p_ul && opt_flags == OPT_LOCAL) value = NO_LOCAL_UNDOLEVEL; --- 1482,1489 ---- ? VI_DEFAULT : VIM_DEFAULT]; else if (nextchar == '<') { ! // For 'undolevels' NO_LOCAL_UNDOLEVEL means to ! // use the global value. if ((long *)varp == &curbuf->b_p_ul && opt_flags == OPT_LOCAL) value = NO_LOCAL_UNDOLEVEL; *************** *** 1510,1517 **** } else if (*arg == '-' || VIM_ISDIGIT(*arg)) { ! /* Allow negative (for 'undolevels'), octal and ! * hex numbers. */ vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, TRUE); if (i == 0 || (arg[i] != NUL --- 1508,1515 ---- } else if (*arg == '-' || VIM_ISDIGIT(*arg)) { ! // Allow negative (for 'undolevels'), octal and ! // hex numbers. vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, TRUE); if (i == 0 || (arg[i] != NUL *************** *** 1536,1546 **** errmsg = set_num_option(opt_idx, varp, value, errbuf, sizeof(errbuf), opt_flags); } ! else if (opt_idx >= 0) /* string */ { char_u *save_arg = NULL; char_u *s = NULL; ! char_u *oldval = NULL; /* previous value if *varp */ char_u *newval; char_u *origval = NULL; char_u *origval_l = NULL; --- 1534,1544 ---- errmsg = set_num_option(opt_idx, varp, value, errbuf, sizeof(errbuf), opt_flags); } ! else if (opt_idx >= 0) // string { char_u *save_arg = NULL; char_u *s = NULL; ! char_u *oldval = NULL; // previous value if *varp char_u *newval; char_u *origval = NULL; char_u *origval_l = NULL; *************** *** 1554,1571 **** unsigned newlen; int comma; int bs; ! int new_value_alloced; /* new string option ! was allocated */ ! /* When using ":set opt=val" for a global option ! * with a local value the local value will be ! * reset, use the global value here. */ if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 && ((int)options[opt_idx].indir & PV_BOTH)) varp = options[opt_idx].var; ! /* The old value is kept until we are sure that the ! * new value is valid. */ oldval = *(char_u **)varp; if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) --- 1552,1569 ---- unsigned newlen; int comma; int bs; ! int new_value_alloced; // new string option ! // was allocated ! // When using ":set opt=val" for a global option ! // with a local value the local value will be ! // reset, use the global value here. if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 && ((int)options[opt_idx].indir & PV_BOTH)) varp = options[opt_idx].var; ! // The old value is kept until we are sure that the ! // new value is valid. oldval = *(char_u **)varp; if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) *************** *** 1592,1605 **** else origval = oldval; ! if (nextchar == '&') /* set to default val */ { newval = options[opt_idx].def_val[ ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; if ((char_u **)varp == &p_bg) { ! /* guess the value of 'background' */ #ifdef FEAT_GUI if (gui.in_use) newval = gui_bg_default(); --- 1590,1603 ---- else origval = oldval; ! if (nextchar == '&') // set to default val { newval = options[opt_idx].def_val[ ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; if ((char_u **)varp == &p_bg) { ! // guess the value of 'background' #ifdef FEAT_GUI if (gui.in_use) newval = gui_bg_default(); *************** *** 1608,1617 **** newval = term_bg_default(); } ! /* expand environment variables and ~ (since the ! * default value was already expanded, only ! * required when an environment variable was set ! * later */ if (newval == NULL) newval = empty_option; else --- 1606,1615 ---- newval = term_bg_default(); } ! // expand environment variables and ~ (since the ! // default value was already expanded, only ! // required when an environment variable was set ! // later if (newval == NULL) newval = empty_option; else *************** *** 1623,1629 **** } new_value_alloced = TRUE; } ! else if (nextchar == '<') /* set to global val */ { newval = vim_strsave(*(char_u **)get_varp_scope( &(options[opt_idx]), OPT_GLOBAL)); --- 1621,1627 ---- } new_value_alloced = TRUE; } ! else if (nextchar == '<') // set to global val { newval = vim_strsave(*(char_u **)get_varp_scope( &(options[opt_idx]), OPT_GLOBAL)); *************** *** 1631,1637 **** } else { ! ++arg; /* jump to after the '=' or ':' */ /* * Set 'keywordprg' to ":help" if an empty --- 1629,1635 ---- } else { ! ++arg; // jump to after the '=' or ':' /* * Set 'keywordprg' to ":help" if an empty *************** *** 1696,1702 **** STRCAT(errbuf, "<,>,"); if (i & 16) STRCAT(errbuf, "[,],"); ! if (*errbuf != NUL) /* remove trailing , */ errbuf[STRLEN(errbuf) - 1] = NUL; save_arg = arg; arg = (char_u *)errbuf; --- 1694,1700 ---- STRCAT(errbuf, "<,>,"); if (i & 16) STRCAT(errbuf, "[,],"); ! if (*errbuf != NUL) // remove trailing , errbuf[STRLEN(errbuf) - 1] = NUL; save_arg = arg; arg = (char_u *)errbuf; *************** *** 1717,1728 **** * Can't use set_string_option_direct(), because * we need to remove the backslashes. */ ! /* get a bit too much */ newlen = (unsigned)STRLEN(arg) + 1; if (adding || prepending || removing) newlen += (unsigned)STRLEN(origval) + 1; newval = alloc(newlen); ! if (newval == NULL) /* out of mem, don't change */ break; s = newval; --- 1715,1726 ---- * Can't use set_string_option_direct(), because * we need to remove the backslashes. */ ! // get a bit too much newlen = (unsigned)STRLEN(arg) + 1; if (adding || prepending || removing) newlen += (unsigned)STRLEN(origval) + 1; newval = alloc(newlen); ! if (newval == NULL) // out of mem, don't change break; s = newval; *************** *** 1745,1755 **** && arg[2] != '\\'))) #endif ) ! ++arg; /* remove backslash */ if (has_mbyte && (i = (*mb_ptr2len)(arg)) > 1) { ! /* copy multibyte char */ mch_memmove(s, arg, (size_t)i); arg += i; s += i; --- 1743,1753 ---- && arg[2] != '\\'))) #endif ) ! ++arg; // remove backslash if (has_mbyte && (i = (*mb_ptr2len)(arg)) > 1) { ! // copy multibyte char mch_memmove(s, arg, (size_t)i); arg += i; s += i; *************** *** 1781,1789 **** } } ! /* locate newval[] in origval[] when removing it ! * and when adding to avoid duplicates */ ! i = 0; /* init for GCC */ if (removing || (flags & P_NODUP)) { i = (int)STRLEN(newval); --- 1779,1787 ---- } } ! // locate newval[] in origval[] when removing it ! // and when adding to avoid duplicates ! i = 0; // init for GCC if (removing || (flags & P_NODUP)) { i = (int)STRLEN(newval); *************** *** 1798,1807 **** || s[i] == ',' || s[i] == NUL)) break; ! /* Count backslashes. Only a comma with an ! * even number of backslashes or a single ! * backslash preceded by a comma before it ! * is recognized as a separator */ if ((s > origval + 1 && s[-1] == '\\' && s[-2] != ',') --- 1796,1805 ---- || s[i] == ',' || s[i] == NUL)) break; ! // Count backslashes. Only a comma with an ! // even number of backslashes or a single ! // backslash preceded by a comma before it ! // is recognized as a separator if ((s > origval + 1 && s[-1] == '\\' && s[-2] != ',') *************** *** 1813,1819 **** bs = 0; } ! /* do not add if already there */ if ((adding || prepending) && *s) { prepending = FALSE; --- 1811,1817 ---- bs = 0; } ! // do not add if already there if ((adding || prepending) && *s) { prepending = FALSE; *************** *** 1822,1829 **** } } ! /* concatenate the two strings; add a ',' if ! * needed */ if (adding || prepending) { comma = ((flags & P_COMMA) && *origval != NUL --- 1820,1827 ---- } } ! // concatenate the two strings; add a ',' if ! // needed if (adding || prepending) { comma = ((flags & P_COMMA) && *origval != NUL *************** *** 1831,1837 **** if (adding) { i = (int)STRLEN(origval); ! /* strip a trailing comma, would get 2 */ if (comma && i > 1 && (flags & P_ONECOMMA) == P_ONECOMMA && origval[i - 1] == ',' --- 1829,1835 ---- if (adding) { i = (int)STRLEN(origval); ! // strip a trailing comma, would get 2 if (comma && i > 1 && (flags & P_ONECOMMA) == P_ONECOMMA && origval[i - 1] == ',' *************** *** 1850,1874 **** newval[i] = ','; } ! /* Remove newval[] from origval[]. (Note: "i" has ! * been set above and is used here). */ if (removing) { STRCPY(newval, origval); if (*s) { ! /* may need to remove a comma */ if (flags & P_COMMA) { if (s == origval) { ! /* include comma after string */ if (s[i] == ',') ++i; } else { ! /* include comma before string */ --s; ++i; } --- 1848,1872 ---- newval[i] = ','; } ! // Remove newval[] from origval[]. (Note: "i" has ! // been set above and is used here). if (removing) { STRCPY(newval, origval); if (*s) { ! // may need to remove a comma if (flags & P_COMMA) { if (s == origval) { ! // include comma after string if (s[i] == ',') ++i; } else { ! // include comma before string --s; ++i; } *************** *** 1879,1896 **** if (flags & P_FLAGLIST) { ! /* Remove flags that appear twice. */ for (s = newval; *s;) { ! /* if options have P_FLAGLIST and ! * P_ONECOMMA such as 'whichwrap' */ if (flags & P_ONECOMMA) { if (*s != ',' && *(s + 1) == ',' && vim_strchr(s + 2, *s) != NULL) { ! /* Remove the duplicated value and ! * the next comma. */ STRMOVE(s, s + 2); continue; } --- 1877,1894 ---- if (flags & P_FLAGLIST) { ! // Remove flags that appear twice. for (s = newval; *s;) { ! // if options have P_FLAGLIST and ! // P_ONECOMMA such as 'whichwrap' if (flags & P_ONECOMMA) { if (*s != ',' && *(s + 1) == ',' && vim_strchr(s + 2, *s) != NULL) { ! // Remove the duplicated value and ! // the next comma. STRMOVE(s, s + 2); continue; } *************** *** 1908,1914 **** } } ! if (save_arg != NULL) /* number for 'whichwrap' */ arg = save_arg; new_value_alloced = TRUE; } --- 1906,1912 ---- } } ! if (save_arg != NULL) // number for 'whichwrap' arg = save_arg; new_value_alloced = TRUE; } *************** *** 1925,1935 **** # endif && origval != NULL && newval != NULL) { ! /* origval may be freed by ! * did_set_string_option(), make a copy. */ saved_origval = vim_strsave(origval); ! /* newval (and varp) may become invalid if the ! * buffer is closed by autocommands. */ saved_newval = vim_strsave(newval); if (origval_l != NULL) saved_origval_l = vim_strsave(origval_l); --- 1923,1933 ---- # endif && origval != NULL && newval != NULL) { ! // origval may be freed by ! // did_set_string_option(), make a copy. saved_origval = vim_strsave(origval); ! // newval (and varp) may become invalid if the ! // buffer is closed by autocommands. saved_newval = vim_strsave(newval); if (origval_l != NULL) saved_origval_l = vim_strsave(origval_l); *************** *** 1977,1987 **** vim_free(saved_origval_g); vim_free(saved_newval); #endif ! /* If error detected, print the error message. */ if (errmsg != NULL) goto skip; } ! else /* key code option */ { char_u *p; --- 1975,1985 ---- vim_free(saved_origval_g); vim_free(saved_newval); #endif ! // If error detected, print the error message. if (errmsg != NULL) goto skip; } ! else // key code option { char_u *p; *************** *** 1992,1998 **** } else { ! ++arg; /* jump to after the '=' or ':' */ for (p = arg; *p && !VIM_ISWHITE(*p); ++p) if (*p == '\\' && p[1] != NUL) ++p; --- 1990,1996 ---- } else { ! ++arg; // jump to after the '=' or ':' for (p = arg; *p && !VIM_ISWHITE(*p); ++p) if (*p == '\\' && p[1] != NUL) ++p; *************** *** 2036,2047 **** i = (int)STRLEN(IObuff) + 2; if (i + (arg - startarg) < IOSIZE) { ! /* append the argument with the error */ STRCAT(IObuff, ": "); mch_memmove(IObuff + i, startarg, (arg - startarg)); IObuff[i + (arg - startarg)] = NUL; } ! /* make sure all characters are printable */ trans_characters(IObuff, IOSIZE); ++no_wait_return; // wait_return done later --- 2034,2045 ---- i = (int)STRLEN(IObuff) + 2; if (i + (arg - startarg) < IOSIZE) { ! // append the argument with the error STRCAT(IObuff, ": "); mch_memmove(IObuff + i, startarg, (arg - startarg)); IObuff[i + (arg - startarg)] = NUL; } ! // make sure all characters are printable trans_characters(IObuff, IOSIZE); ++no_wait_return; // wait_return done later *************** *** 2057,2070 **** theend: if (silent_mode && did_show) { ! /* After displaying option values in silent mode. */ silent_mode = FALSE; ! info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ msg_putchar('\n'); ! cursor_on(); /* msg_start() switches it off */ out_flush(); silent_mode = TRUE; ! info_message = FALSE; /* use mch_msg(), not mch_errmsg() */ } return OK; --- 2055,2068 ---- theend: if (silent_mode && did_show) { ! // After displaying option values in silent mode. silent_mode = FALSE; ! info_message = TRUE; // use mch_msg(), not mch_errmsg() msg_putchar('\n'); ! cursor_on(); // msg_start() switches it off out_flush(); silent_mode = TRUE; ! info_message = FALSE; // use mch_msg(), not mch_errmsg() } return OK; *************** *** 2086,2094 **** options[opt_idx].flags |= P_WAS_SET; ! /* When an option is set in the sandbox, from a modeline or in secure mode ! * set the P_INSECURE flag. Otherwise, if a new value is stored reset the ! * flag. */ p = insecure_flag(opt_idx, opt_flags); if (!value_checked && (secure #ifdef HAVE_SANDBOX --- 2084,2092 ---- options[opt_idx].flags |= P_WAS_SET; ! // When an option is set in the sandbox, from a modeline or in secure mode ! // set the P_INSECURE flag. Otherwise, if a new value is stored reset the ! // flag. p = insecure_flag(opt_idx, opt_flags); if (!value_checked && (secure #ifdef HAVE_SANDBOX *************** *** 2143,2149 **** set_options_bin( int oldval, int newval, ! int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */ { /* * The option values that are changed when 'bin' changes are --- 2141,2147 ---- set_options_bin( int oldval, int newval, ! int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL { /* * The option values that are changed when 'bin' changes are *************** *** 2151,2157 **** */ if (newval) { ! if (!oldval) /* switched on */ { if (!(opt_flags & OPT_GLOBAL)) { --- 2149,2155 ---- */ if (newval) { ! if (!oldval) // switched on { if (!(opt_flags & OPT_GLOBAL)) { *************** *** 2171,2180 **** if (!(opt_flags & OPT_GLOBAL)) { ! curbuf->b_p_tw = 0; /* no automatic line wrap */ ! curbuf->b_p_wm = 0; /* no automatic line wrap */ ! curbuf->b_p_ml = 0; /* no modelines */ ! curbuf->b_p_et = 0; /* no expandtab */ } if (!(opt_flags & OPT_LOCAL)) { --- 2169,2178 ---- if (!(opt_flags & OPT_GLOBAL)) { ! curbuf->b_p_tw = 0; // no automatic line wrap ! curbuf->b_p_wm = 0; // no automatic line wrap ! curbuf->b_p_ml = 0; // no modelines ! curbuf->b_p_et = 0; // no expandtab } if (!(opt_flags & OPT_LOCAL)) { *************** *** 2182,2191 **** p_wm = 0; p_ml = FALSE; p_et = FALSE; ! p_bin = TRUE; /* needed when called for the "-b" argument */ } } ! else if (oldval) /* switched off */ { if (!(opt_flags & OPT_GLOBAL)) { --- 2180,2189 ---- p_wm = 0; p_ml = FALSE; p_et = FALSE; ! p_bin = TRUE; // needed when called for the "-b" argument } } ! else if (oldval) // switched off { if (!(opt_flags & OPT_GLOBAL)) { *************** *** 2213,2224 **** static char_u * option_expand(int opt_idx, char_u *val) { ! /* if option doesn't need expansion nothing to do */ if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL) return NULL; ! /* If val is longer than MAXPATHL no meaningful expansion can be done, ! * expand_env() would truncate the string. */ if (val != NULL && STRLEN(val) > MAXPATHL) return NULL; --- 2211,2222 ---- static char_u * option_expand(int opt_idx, char_u *val) { ! // if option doesn't need expansion nothing to do if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL) return NULL; ! // If val is longer than MAXPATHL no meaningful expansion can be done, ! // expand_env() would truncate the string. if (val != NULL && STRLEN(val) > MAXPATHL) return NULL; *************** *** 2237,2243 **** (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" : #endif NULL); ! if (STRCMP(NameBuff, val) == 0) /* they are the same */ return NULL; return NameBuff; --- 2235,2241 ---- (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" : #endif NULL); ! if (STRCMP(NameBuff, val) == 0) // they are the same return NULL; return NameBuff; *************** *** 2250,2256 **** static void didset_options(void) { ! /* initialize the table for 'iskeyword' et.al. */ (void)init_chartab(); didset_string_options(); --- 2248,2254 ---- static void didset_options(void) { ! // initialize the table for 'iskeyword' et.al. (void)init_chartab(); didset_string_options(); *************** *** 2266,2272 **** (void)check_cedit(); #endif #ifdef FEAT_LINEBREAK ! /* initialize the table for 'breakat'. */ fill_breakat_flags(); #endif after_copy_winopt(curwin); --- 2264,2270 ---- (void)check_cedit(); #endif #ifdef FEAT_LINEBREAK ! // initialize the table for 'breakat'. fill_breakat_flags(); #endif after_copy_winopt(curwin); *************** *** 2278,2295 **** static void didset_options2(void) { ! /* Initialize the highlight_attr[] table. */ (void)highlight_changed(); ! /* Parse default for 'wildmode' */ check_opt_wim(); (void)set_chars_option(&p_lcs); ! /* Parse default for 'fillchars'. */ (void)set_chars_option(&p_fcs); #ifdef FEAT_CLIPBOARD ! /* Parse default for 'clipboard' */ (void)check_clipboard_option(); #endif #ifdef FEAT_VARTABS --- 2276,2293 ---- static void didset_options2(void) { ! // Initialize the highlight_attr[] table. (void)highlight_changed(); ! // Parse default for 'wildmode' check_opt_wim(); (void)set_chars_option(&p_lcs); ! // Parse default for 'fillchars'. (void)set_chars_option(&p_fcs); #ifdef FEAT_CLIPBOARD ! // Parse default for 'clipboard' (void)check_clipboard_option(); #endif #ifdef FEAT_VARTABS *************** *** 2394,2400 **** #endif } ! /* Nothing special, return global flags field. */ return &options[opt_idx].flags; } #endif --- 2392,2398 ---- #endif } ! // Nothing special, return global flags field. return &options[opt_idx].flags; } #endif *************** *** 2439,2446 **** new_script_ctx.sc_lnum += sourcing_lnum; ! /* Remember where the option was set. For local options need to do that ! * in the buffer or window structure. */ if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0) options[opt_idx].script_ctx = new_script_ctx; if (both || (opt_flags & OPT_LOCAL)) --- 2437,2444 ---- new_script_ctx.sc_lnum += sourcing_lnum; ! // Remember where the option was set. For local options need to do that ! // in the buffer or window structure. if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0) options[opt_idx].script_ctx = new_script_ctx; if (both || (opt_flags & OPT_LOCAL)) *************** *** 2485,2501 **** */ static char * set_bool_option( ! int opt_idx, /* index in options[] table */ ! char_u *varp, /* pointer to the option variable */ ! int value, /* new value */ ! int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */ { int old_value = *(int *)varp; #if defined(FEAT_EVAL) int old_global_value = 0; #endif ! /* Disallow changing some options from secure mode */ if ((secure #ifdef HAVE_SANDBOX || sandbox != 0 --- 2483,2499 ---- */ static char * set_bool_option( ! int opt_idx, // index in options[] table ! char_u *varp, // pointer to the option variable ! int value, // new value ! int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL { int old_value = *(int *)varp; #if defined(FEAT_EVAL) int old_global_value = 0; #endif ! // Disallow changing some options from secure mode if ((secure #ifdef HAVE_SANDBOX || sandbox != 0 *************** *** 2512,2520 **** OPT_GLOBAL); #endif ! *(int *)varp = value; /* set the new value */ #ifdef FEAT_EVAL ! /* Remember where the option was set. */ set_option_sctx_idx(opt_idx, opt_flags, current_sctx); #endif --- 2510,2518 ---- OPT_GLOBAL); #endif ! *(int *)varp = value; // set the new value #ifdef FEAT_EVAL ! // Remember where the option was set. set_option_sctx_idx(opt_idx, opt_flags, current_sctx); #endif *************** *** 2522,2528 **** need_mouse_correct = TRUE; #endif ! /* May set global value for local option. */ if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value; --- 2520,2526 ---- need_mouse_correct = TRUE; #endif ! // May set global value for local option. if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value; *************** *** 2530,2545 **** * Handle side effects of changing a bool option. */ ! /* 'compatible' */ if ((int *)varp == &p_cp) compatible_set(); #ifdef FEAT_LANGMAP if ((int *)varp == &p_lrm) ! /* 'langremap' -> !'langnoremap' */ p_lnr = !p_lrm; else if ((int *)varp == &p_lnr) ! /* 'langnoremap' -> !'langremap' */ p_lrm = !p_lnr; #endif --- 2528,2543 ---- * Handle side effects of changing a bool option. */ ! // 'compatible' if ((int *)varp == &p_cp) compatible_set(); #ifdef FEAT_LANGMAP if ((int *)varp == &p_lrm) ! // 'langremap' -> !'langnoremap' p_lnr = !p_lrm; else if ((int *)varp == &p_lnr) ! // 'langnoremap' -> !'langremap' p_lrm = !p_lnr; #endif *************** *** 2549,2560 **** #endif #ifdef FEAT_PERSISTENT_UNDO ! /* 'undofile' */ else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf) { ! /* Only take action when the option was set. When reset we do not ! * delete the undo file, the option may be set again without making ! * any changes in between. */ if (curbuf->b_p_udf || p_udf) { char_u hash[UNDO_HASH_SIZE]; --- 2547,2558 ---- #endif #ifdef FEAT_PERSISTENT_UNDO ! // 'undofile' else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf) { ! // Only take action when the option was set. When reset we do not ! // delete the undo file, the option may be set again without making ! // any changes in between. if (curbuf->b_p_udf || p_udf) { char_u hash[UNDO_HASH_SIZE]; *************** *** 2562,2571 **** FOR_ALL_BUFFERS(curbuf) { ! /* When 'undofile' is set globally: for every buffer, otherwise ! * only for the current buffer: Try to read in the undofile, ! * if one exists, the buffer wasn't changed and the buffer was ! * loaded */ if ((curbuf == save_curbuf || (opt_flags & OPT_GLOBAL) || opt_flags == 0) && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL) --- 2560,2569 ---- FOR_ALL_BUFFERS(curbuf) { ! // When 'undofile' is set globally: for every buffer, otherwise ! // only for the current buffer: Try to read in the undofile, ! // if one exists, the buffer wasn't changed and the buffer was ! // loaded if ((curbuf == save_curbuf || (opt_flags & OPT_GLOBAL) || opt_flags == 0) && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL) *************** *** 2581,2591 **** else if ((int *)varp == &curbuf->b_p_ro) { ! /* when 'readonly' is reset globally, also reset readonlymode */ if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0) readonlymode = FALSE; ! /* when 'readonly' is set may give W10 again */ if (curbuf->b_p_ro) curbuf->b_did_warn = FALSE; --- 2579,2589 ---- else if ((int *)varp == &curbuf->b_p_ro) { ! // when 'readonly' is reset globally, also reset readonlymode if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0) readonlymode = FALSE; ! // when 'readonly' is set may give W10 again if (curbuf->b_p_ro) curbuf->b_did_warn = FALSE; *************** *** 2602,2612 **** } #endif ! /* when 'modifiable' is changed, redraw the window title */ else if ((int *)varp == &curbuf->b_p_ma) { # ifdef FEAT_TERMINAL ! /* Cannot set 'modifiable' when in Terminal mode. */ if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf) && curbuf->b_term != NULL && !term_is_finished(curbuf)))) { --- 2600,2610 ---- } #endif ! // when 'modifiable' is changed, redraw the window title else if ((int *)varp == &curbuf->b_p_ma) { # ifdef FEAT_TERMINAL ! // Cannot set 'modifiable' when in Terminal mode. if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf) && curbuf->b_term != NULL && !term_is_finished(curbuf)))) { *************** *** 2619,2642 **** # endif } #ifdef FEAT_TITLE ! /* when 'endofline' is changed, redraw the window title */ else if ((int *)varp == &curbuf->b_p_eol) { redraw_titles(); } ! /* when 'fixeol' is changed, redraw the window title */ else if ((int *)varp == &curbuf->b_p_fixeol) { redraw_titles(); } ! /* when 'bomb' is changed, redraw the window title and tab page text */ else if ((int *)varp == &curbuf->b_p_bomb) { redraw_titles(); } #endif ! /* when 'bin' is set also set some other options */ else if ((int *)varp == &curbuf->b_p_bin) { set_options_bin(old_value, curbuf->b_p_bin, opt_flags); --- 2617,2640 ---- # endif } #ifdef FEAT_TITLE ! // when 'endofline' is changed, redraw the window title else if ((int *)varp == &curbuf->b_p_eol) { redraw_titles(); } ! // when 'fixeol' is changed, redraw the window title else if ((int *)varp == &curbuf->b_p_fixeol) { redraw_titles(); } ! // when 'bomb' is changed, redraw the window title and tab page text else if ((int *)varp == &curbuf->b_p_bomb) { redraw_titles(); } #endif ! // when 'bin' is set also set some other options else if ((int *)varp == &curbuf->b_p_bin) { set_options_bin(old_value, curbuf->b_p_bin, opt_flags); *************** *** 2645,2694 **** #endif } ! /* when 'buflisted' changes, trigger autocommands */ else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl) { apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE, NULL, NULL, TRUE, curbuf); } ! /* when 'swf' is set, create swapfile, when reset remove swapfile */ else if ((int *)varp == &curbuf->b_p_swf) { if (curbuf->b_p_swf && p_uc) ! ml_open_file(curbuf); /* create the swap file */ else ! /* no need to reset curbuf->b_may_swap, ml_open_file() will check ! * buf->b_p_swf */ ! mf_close_file(curbuf, TRUE); /* remove the swap file */ } ! /* when 'terse' is set change 'shortmess' */ else if ((int *)varp == &p_terse) { char_u *p; p = vim_strchr(p_shm, SHM_SEARCH); ! /* insert 's' in p_shm */ if (p_terse && p == NULL) { STRCPY(IObuff, p_shm); STRCAT(IObuff, "s"); set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0); } ! /* remove 's' from p_shm */ else if (!p_terse && p != NULL) STRMOVE(p, p + 1); } ! /* when 'paste' is set or reset also change other options */ else if ((int *)varp == &p_paste) { paste_option_changed(); } ! /* when 'insertmode' is set from an autocommand need to do work here */ else if ((int *)varp == &p_im) { if (p_im) --- 2643,2692 ---- #endif } ! // when 'buflisted' changes, trigger autocommands else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl) { apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE, NULL, NULL, TRUE, curbuf); } ! // when 'swf' is set, create swapfile, when reset remove swapfile else if ((int *)varp == &curbuf->b_p_swf) { if (curbuf->b_p_swf && p_uc) ! ml_open_file(curbuf); // create the swap file else ! // no need to reset curbuf->b_may_swap, ml_open_file() will check ! // buf->b_p_swf ! mf_close_file(curbuf, TRUE); // remove the swap file } ! // when 'terse' is set change 'shortmess' else if ((int *)varp == &p_terse) { char_u *p; p = vim_strchr(p_shm, SHM_SEARCH); ! // insert 's' in p_shm if (p_terse && p == NULL) { STRCPY(IObuff, p_shm); STRCAT(IObuff, "s"); set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0); } ! // remove 's' from p_shm else if (!p_terse && p != NULL) STRMOVE(p, p + 1); } ! // when 'paste' is set or reset also change other options else if ((int *)varp == &p_paste) { paste_option_changed(); } ! // when 'insertmode' is set from an autocommand need to do work here else if ((int *)varp == &p_im) { if (p_im) *************** *** 2697,2729 **** need_start_insertmode = TRUE; stop_insert_mode = FALSE; } ! /* only reset if it was set previously */ else if (old_value) { need_start_insertmode = FALSE; stop_insert_mode = TRUE; if (restart_edit != 0 && mode_displayed) ! clear_cmdline = TRUE; /* remove "(insert)" */ restart_edit = 0; } } ! /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */ else if ((int *)varp == &p_ic && p_hls) { redraw_all_later(SOME_VALID); } #ifdef FEAT_SEARCH_EXTRA ! /* when 'hlsearch' is set or reset: reset no_hlsearch */ else if ((int *)varp == &p_hls) { set_no_hlsearch(FALSE); } #endif ! /* when 'scrollbind' is set: snapshot the current position to avoid a jump ! * at the end of normal_cmd() */ else if ((int *)varp == &curwin->w_p_scb) { if (curwin->w_p_scb) --- 2695,2727 ---- need_start_insertmode = TRUE; stop_insert_mode = FALSE; } ! // only reset if it was set previously else if (old_value) { need_start_insertmode = FALSE; stop_insert_mode = TRUE; if (restart_edit != 0 && mode_displayed) ! clear_cmdline = TRUE; // remove "(insert)" restart_edit = 0; } } ! // when 'ignorecase' is set or reset and 'hlsearch' is set, redraw else if ((int *)varp == &p_ic && p_hls) { redraw_all_later(SOME_VALID); } #ifdef FEAT_SEARCH_EXTRA ! // when 'hlsearch' is set or reset: reset no_hlsearch else if ((int *)varp == &p_hls) { set_no_hlsearch(FALSE); } #endif ! // when 'scrollbind' is set: snapshot the current position to avoid a jump ! // at the end of normal_cmd() else if ((int *)varp == &curwin->w_p_scb) { if (curwin->w_p_scb) *************** *** 2734,2740 **** } #if defined(FEAT_QUICKFIX) ! /* There can be only one window with 'previewwindow' set. */ else if ((int *)varp == &curwin->w_p_pvw) { if (curwin->w_p_pvw) --- 2732,2738 ---- } #if defined(FEAT_QUICKFIX) ! // There can be only one window with 'previewwindow' set. else if ((int *)varp == &curwin->w_p_pvw) { if (curwin->w_p_pvw) *************** *** 2751,2763 **** } #endif ! /* when 'textmode' is set or reset also change 'fileformat' */ else if ((int *)varp == &curbuf->b_p_tx) { set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags); } ! /* when 'textauto' is set or reset also change 'fileformats' */ else if ((int *)varp == &p_ta) { set_string_option_direct((char_u *)"ffs", -1, --- 2749,2761 ---- } #endif ! // when 'textmode' is set or reset also change 'fileformat' else if ((int *)varp == &curbuf->b_p_tx) { set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags); } ! // when 'textauto' is set or reset also change 'fileformats' else if ((int *)varp == &p_ta) { set_string_option_direct((char_u *)"ffs", -1, *************** *** 2772,2783 **** #ifdef FEAT_LISP else if (varp == (char_u *)&(curbuf->b_p_lisp)) { ! (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */ } #endif #ifdef FEAT_TITLE ! /* when 'title' changed, may need to change the title; same for 'icon' */ else if ((int *)varp == &p_title || (int *)varp == &p_icon) { did_set_title(); --- 2770,2781 ---- #ifdef FEAT_LISP else if (varp == (char_u *)&(curbuf->b_p_lisp)) { ! (void)buf_init_chartab(curbuf, FALSE); // ignore errors } #endif #ifdef FEAT_TITLE ! // when 'title' changed, may need to change the title; same for 'icon' else if ((int *)varp == &p_title || (int *)varp == &p_icon) { did_set_title(); *************** *** 2787,2793 **** else if ((int *)varp == &curbuf->b_changed) { if (!value) ! save_file_ff(curbuf); /* Buffer is unchanged */ #ifdef FEAT_TITLE redraw_titles(); #endif --- 2785,2791 ---- else if ((int *)varp == &curbuf->b_changed) { if (!value) ! save_file_ff(curbuf); // Buffer is unchanged #ifdef FEAT_TITLE redraw_titles(); #endif *************** *** 2810,2816 **** pseps[0] = '\\'; } ! /* need to adjust the file name arguments and buffer names. */ buflist_slash_adjust(); alist_slash_adjust(); # ifdef FEAT_EVAL --- 2808,2814 ---- pseps[0] = '\\'; } ! // need to adjust the file name arguments and buffer names. buflist_slash_adjust(); alist_slash_adjust(); # ifdef FEAT_EVAL *************** *** 2819,2825 **** } #endif ! /* If 'wrap' is set, set w_leftcol to zero. */ else if ((int *)varp == &curwin->w_p_wrap) { if (curwin->w_p_wrap) --- 2817,2823 ---- } #endif ! // If 'wrap' is set, set w_leftcol to zero. else if ((int *)varp == &curwin->w_p_wrap) { if (curwin->w_p_wrap) *************** *** 2867,2882 **** #ifdef FEAT_AUTOCHDIR else if ((int *)varp == &p_acd) { ! /* Change directories when the 'acd' option is set now. */ DO_AUTOCHDIR; } #endif #ifdef FEAT_DIFF ! /* 'diff' */ else if ((int *)varp == &curwin->w_p_diff) { ! /* May add or remove the buffer from the list of diff buffers. */ diff_buf_adjust(curwin); # ifdef FEAT_FOLDING if (foldmethodIsDiff(curwin)) --- 2865,2880 ---- #ifdef FEAT_AUTOCHDIR else if ((int *)varp == &p_acd) { ! // Change directories when the 'acd' option is set now. DO_AUTOCHDIR; } #endif #ifdef FEAT_DIFF ! // 'diff' else if ((int *)varp == &curwin->w_p_diff) { ! // May add or remove the buffer from the list of diff buffers. diff_buf_adjust(curwin); # ifdef FEAT_FOLDING if (foldmethodIsDiff(curwin)) *************** *** 2886,2906 **** #endif #ifdef HAVE_INPUT_METHOD ! /* 'imdisable' */ else if ((int *)varp == &p_imdisable) { ! /* Only de-activate it here, it will be enabled when changing mode. */ if (p_imdisable) im_set_active(FALSE); else if (State & INSERT) ! /* When the option is set from an autocommand, it may need to take ! * effect right away. */ im_set_active(curbuf->b_p_iminsert == B_IMODE_IM); } #endif #ifdef FEAT_SPELL ! /* 'spell' */ else if ((int *)varp == &curwin->w_p_spell) { if (curwin->w_p_spell) --- 2884,2904 ---- #endif #ifdef HAVE_INPUT_METHOD ! // 'imdisable' else if ((int *)varp == &p_imdisable) { ! // Only de-activate it here, it will be enabled when changing mode. if (p_imdisable) im_set_active(FALSE); else if (State & INSERT) ! // When the option is set from an autocommand, it may need to take ! // effect right away. im_set_active(curbuf->b_p_iminsert == B_IMODE_IM); } #endif #ifdef FEAT_SPELL ! // 'spell' else if ((int *)varp == &curwin->w_p_spell) { if (curwin->w_p_spell) *************** *** 2923,2936 **** */ if (!p_tbidi) { ! /* set rightleft mode */ if (!curwin->w_p_rl) { curwin->w_p_rl = TRUE; changed_window_setting(); } ! /* Enable Arabic shaping (major part of what Arabic requires) */ if (!p_arshape) { p_arshape = TRUE; --- 2921,2934 ---- */ if (!p_tbidi) { ! // set rightleft mode if (!curwin->w_p_rl) { curwin->w_p_rl = TRUE; changed_window_setting(); } ! // Enable Arabic shaping (major part of what Arabic requires) if (!p_arshape) { p_arshape = TRUE; *************** *** 2938,2945 **** } } ! /* Arabic requires a utf-8 encoding, inform the user if its not ! * set. */ if (STRCMP(p_enc, "utf-8") != 0) { static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"); --- 2936,2943 ---- } } ! // Arabic requires a utf-8 encoding, inform the user if its not ! // set. if (STRCMP(p_enc, "utf-8") != 0) { static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"); *************** *** 2951,2961 **** #endif } ! /* set 'delcombine' */ p_deco = TRUE; # ifdef FEAT_KEYMAP ! /* Force-set the necessary keymap for arabic */ set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic", OPT_LOCAL); # endif --- 2949,2959 ---- #endif } ! // set 'delcombine' p_deco = TRUE; # ifdef FEAT_KEYMAP ! // Force-set the necessary keymap for arabic set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic", OPT_LOCAL); # endif *************** *** 2967,2988 **** */ if (!p_tbidi) { ! /* reset rightleft mode */ if (curwin->w_p_rl) { curwin->w_p_rl = FALSE; changed_window_setting(); } ! /* 'arabicshape' isn't reset, it is a global option and ! * another window may still need it "on". */ } ! /* 'delcombine' isn't reset, it is a global option and another ! * window may still want it "on". */ # ifdef FEAT_KEYMAP ! /* Revert to the default keymap */ curbuf->b_p_iminsert = B_IMODE_NONE; curbuf->b_p_imsearch = B_IMODE_USE_INSERT; # endif --- 2965,2986 ---- */ if (!p_tbidi) { ! // reset rightleft mode if (curwin->w_p_rl) { curwin->w_p_rl = FALSE; changed_window_setting(); } ! // 'arabicshape' isn't reset, it is a global option and ! // another window may still need it "on". } ! // 'delcombine' isn't reset, it is a global option and another ! // window may still want it "on". # ifdef FEAT_KEYMAP ! // Revert to the default keymap curbuf->b_p_iminsert = B_IMODE_NONE; curbuf->b_p_imsearch = B_IMODE_USE_INSERT; # endif *************** *** 3010,3020 **** #endif #ifdef FEAT_TERMGUICOLORS ! /* 'termguicolors' */ else if ((int *)varp == &p_tgc) { # ifdef FEAT_VTP ! /* Do not turn on 'tgc' when 24-bit colors are not supported. */ if ( # ifdef VIMDLL !gui.in_use && !gui.starting && --- 3008,3018 ---- #endif #ifdef FEAT_TERMGUICOLORS ! // 'termguicolors' else if ((int *)varp == &p_tgc) { # ifdef FEAT_VTP ! // Do not turn on 'tgc' when 24-bit colors are not supported. if ( # ifdef VIMDLL !gui.in_use && !gui.starting && *************** *** 3032,3038 **** # endif highlight_gui_started(); # ifdef FEAT_VTP ! /* reset t_Co */ if (is_term_win32()) { control_console_color_rgb(); --- 3030,3036 ---- # endif highlight_gui_started(); # ifdef FEAT_VTP ! // reset t_Co if (is_term_win32()) { control_console_color_rgb(); *************** *** 3047,3053 **** * End of handling side effects for bool options. */ ! /* after handling side effects, call autocommand */ options[opt_idx].flags |= P_WAS_SET; --- 3045,3051 ---- * End of handling side effects for bool options. */ ! // after handling side effects, call autocommand options[opt_idx].flags |= P_WAS_SET; *************** *** 3093,3099 **** } #endif ! comp_col(); /* in case 'ruler' or 'showcmd' changed */ if (curwin->w_curswant != MAXCOL && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) curwin->w_set_curswant = TRUE; --- 3091,3097 ---- } #endif ! comp_col(); // in case 'ruler' or 'showcmd' changed if (curwin->w_curswant != MAXCOL && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) curwin->w_set_curswant = TRUE; *************** *** 3108,3120 **** */ static char * set_num_option( ! int opt_idx, /* index in options[] table */ ! char_u *varp, /* pointer to the option variable */ ! long value, /* new value */ ! char *errbuf, /* buffer for error messages */ ! size_t errbuflen, /* length of "errbuf" */ ! int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and ! OPT_MODELINE */ { char *errmsg = NULL; long old_value = *(long *)varp; --- 3106,3118 ---- */ static char * set_num_option( ! int opt_idx, // index in options[] table ! char_u *varp, // pointer to the option variable ! long value, // new value ! char *errbuf, // buffer for error messages ! size_t errbuflen, // length of "errbuf" ! int opt_flags) // OPT_LOCAL, OPT_GLOBAL and ! // OPT_MODELINE { char *errmsg = NULL; long old_value = *(long *)varp; *************** *** 3126,3132 **** long old_Columns = Columns; // remember old Columns long *pp = (long *)varp; ! /* Disallow changing some options from secure mode. */ if ((secure #ifdef HAVE_SANDBOX || sandbox != 0 --- 3124,3130 ---- long old_Columns = Columns; // remember old Columns long *pp = (long *)varp; ! // Disallow changing some options from secure mode. if ((secure #ifdef HAVE_SANDBOX || sandbox != 0 *************** *** 3145,3151 **** *pp = value; #ifdef FEAT_EVAL ! /* Remember where the option was set. */ set_option_sctx_idx(opt_idx, opt_flags, current_sctx); #endif #ifdef FEAT_GUI --- 3143,3149 ---- *pp = value; #ifdef FEAT_EVAL ! // Remember where the option was set. set_option_sctx_idx(opt_idx, opt_flags, current_sctx); #endif #ifdef FEAT_GUI *************** *** 3187,3193 **** p_hh = 0; } ! /* Change window height NOW */ if (!ONE_WINDOW) { if (pp == &p_wh && curwin->w_height < p_wh) --- 3185,3191 ---- p_hh = 0; } ! // Change window height NOW if (!ONE_WINDOW) { if (pp == &p_wh && curwin->w_height < p_wh) *************** *** 3225,3231 **** p_wiw = p_wmw; } ! /* Change window width NOW */ if (!ONE_WINDOW && curwin->w_width < p_wiw) win_setwidth((int)p_wiw); } --- 3223,3229 ---- p_wiw = p_wmw; } ! // Change window width NOW if (!ONE_WINDOW && curwin->w_width < p_wiw) win_setwidth((int)p_wiw); } *************** *** 3245,3274 **** win_setminwidth(); } ! /* (re)set last window status line */ else if (pp == &p_ls) { last_status(FALSE); } ! /* (re)set tab page line */ else if (pp == &p_stal) { ! shell_new_rows(); /* recompute window positions and heights */ } #ifdef FEAT_GUI else if (pp == &p_linespace) { ! /* Recompute gui.char_height and resize the Vim window to keep the ! * same number of lines. */ if (gui.in_use && gui_mch_adjust_charheight() == OK) gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); } #endif #ifdef FEAT_FOLDING ! /* 'foldlevel' */ else if (pp == &curwin->w_p_fdl) { if (curwin->w_p_fdl < 0) --- 3243,3272 ---- win_setminwidth(); } ! // (re)set last window status line else if (pp == &p_ls) { last_status(FALSE); } ! // (re)set tab page line else if (pp == &p_stal) { ! shell_new_rows(); // recompute window positions and heights } #ifdef FEAT_GUI else if (pp == &p_linespace) { ! // Recompute gui.char_height and resize the Vim window to keep the ! // same number of lines. if (gui.in_use && gui_mch_adjust_charheight() == OK) gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); } #endif #ifdef FEAT_FOLDING ! // 'foldlevel' else if (pp == &curwin->w_p_fdl) { if (curwin->w_p_fdl < 0) *************** *** 3276,3295 **** newFoldLevel(); } ! /* 'foldminlines' */ else if (pp == &curwin->w_p_fml) { foldUpdateAll(curwin); } ! /* 'foldnestmax' */ else if (pp == &curwin->w_p_fdn) { if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) foldUpdateAll(curwin); } ! /* 'foldcolumn' */ else if (pp == &curwin->w_p_fdc) { if (curwin->w_p_fdc < 0) --- 3274,3293 ---- newFoldLevel(); } ! // 'foldminlines' else if (pp == &curwin->w_p_fml) { foldUpdateAll(curwin); } ! // 'foldnestmax' else if (pp == &curwin->w_p_fdn) { if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) foldUpdateAll(curwin); } ! // 'foldcolumn' else if (pp == &curwin->w_p_fdc) { if (curwin->w_p_fdc < 0) *************** *** 3303,3312 **** curwin->w_p_fdc = 12; } } ! #endif /* FEAT_FOLDING */ #if defined(FEAT_FOLDING) || defined(FEAT_CINDENT) ! /* 'shiftwidth' or 'tabstop' */ else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts) { # ifdef FEAT_FOLDING --- 3301,3310 ---- curwin->w_p_fdc = 12; } } ! #endif // FEAT_FOLDING #if defined(FEAT_FOLDING) || defined(FEAT_CINDENT) ! // 'shiftwidth' or 'tabstop' else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts) { # ifdef FEAT_FOLDING *************** *** 3314,3335 **** foldUpdateAll(curwin); # endif # ifdef FEAT_CINDENT ! /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes: ! * parse 'cinoptions'. */ if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) parse_cino(curbuf); # endif } #endif ! /* 'maxcombine' */ else if (pp == &p_mco) { if (p_mco > MAX_MCO) p_mco = MAX_MCO; else if (p_mco < 0) p_mco = 0; ! screenclear(); /* will re-allocate the screen */ } else if (pp == &curbuf->b_p_iminsert) --- 3312,3333 ---- foldUpdateAll(curwin); # endif # ifdef FEAT_CINDENT ! // When 'shiftwidth' changes, or it's zero and 'tabstop' changes: ! // parse 'cinoptions'. if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) parse_cino(curbuf); # endif } #endif ! // 'maxcombine' else if (pp == &p_mco) { if (p_mco > MAX_MCO) p_mco = MAX_MCO; else if (p_mco < 0) p_mco = 0; ! screenclear(); // will re-allocate the screen } else if (pp == &curbuf->b_p_iminsert) *************** *** 3340,3355 **** curbuf->b_p_iminsert = B_IMODE_NONE; } p_iminsert = curbuf->b_p_iminsert; ! if (termcap_active) /* don't do this in the alternate screen */ showmode(); #if defined(FEAT_KEYMAP) ! /* Show/unshow value of 'keymap' in status lines. */ status_redraw_curbuf(); #endif } #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) ! /* 'imstyle' */ else if (pp == &p_imst) { if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT) --- 3338,3353 ---- curbuf->b_p_iminsert = B_IMODE_NONE; } p_iminsert = curbuf->b_p_iminsert; ! if (termcap_active) // don't do this in the alternate screen showmode(); #if defined(FEAT_KEYMAP) ! // Show/unshow value of 'keymap' in status lines. status_redraw_curbuf(); #endif } #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) ! // 'imstyle' else if (pp == &p_imst) { if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT) *************** *** 3376,3382 **** } #ifdef FEAT_TITLE ! /* if 'titlelen' has changed, redraw the title */ else if (pp == &p_titlelen) { if (p_titlelen < 0) --- 3374,3380 ---- } #ifdef FEAT_TITLE ! // if 'titlelen' has changed, redraw the title else if (pp == &p_titlelen) { if (p_titlelen < 0) *************** *** 3389,3395 **** } #endif ! /* if p_ch changed value, change the command line height */ else if (pp == &p_ch) { if (p_ch < 1) --- 3387,3393 ---- } #endif ! // if p_ch changed value, change the command line height else if (pp == &p_ch) { if (p_ch < 1) *************** *** 3400,3407 **** if (p_ch > Rows - min_rows() + 1) p_ch = Rows - min_rows() + 1; ! /* Only compute the new window layout when startup has been ! * completed. Otherwise the frame sizes may be wrong. */ if (p_ch != old_value && full_screen #ifdef FEAT_GUI && !gui.starting --- 3398,3405 ---- if (p_ch > Rows - min_rows() + 1) p_ch = Rows - min_rows() + 1; ! // Only compute the new window layout when startup has been ! // completed. Otherwise the frame sizes may be wrong. if (p_ch != old_value && full_screen #ifdef FEAT_GUI && !gui.starting *************** *** 3410,3416 **** command_height(); } ! /* when 'updatecount' changes from zero to non-zero, open swap files */ else if (pp == &p_uc) { if (p_uc < 0) --- 3408,3414 ---- command_height(); } ! // when 'updatecount' changes from zero to non-zero, open swap files else if (pp == &p_uc) { if (p_uc < 0) *************** *** 3442,3448 **** #endif #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) ! /* 'pyxversion' */ else if (pp == &p_pyx) { if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3) --- 3440,3446 ---- #endif #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) ! // 'pyxversion' else if (pp == &p_pyx) { if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3) *************** *** 3450,3473 **** } #endif ! /* sync undo before 'undolevels' changes */ else if (pp == &p_ul) { ! /* use the old value, otherwise u_sync() may not work properly */ p_ul = old_value; u_sync(TRUE); p_ul = value; } else if (pp == &curbuf->b_p_ul) { ! /* use the old value, otherwise u_sync() may not work properly */ curbuf->b_p_ul = old_value; u_sync(TRUE); curbuf->b_p_ul = value; } #ifdef FEAT_LINEBREAK ! /* 'numberwidth' must be positive */ else if (pp == &curwin->w_p_nuw) { if (curwin->w_p_nuw < 1) --- 3448,3471 ---- } #endif ! // sync undo before 'undolevels' changes else if (pp == &p_ul) { ! // use the old value, otherwise u_sync() may not work properly p_ul = old_value; u_sync(TRUE); p_ul = value; } else if (pp == &curbuf->b_p_ul) { ! // use the old value, otherwise u_sync() may not work properly curbuf->b_p_ul = old_value; u_sync(TRUE); curbuf->b_p_ul = value; } #ifdef FEAT_LINEBREAK ! // 'numberwidth' must be positive else if (pp == &curwin->w_p_nuw) { if (curwin->w_p_nuw < 1) *************** *** 3480,3486 **** errmsg = e_invarg; curwin->w_p_nuw = 20; } ! curwin->w_nrwidth_line_count = 0; /* trigger a redraw */ } #endif --- 3478,3484 ---- errmsg = e_invarg; curwin->w_p_nuw = 20; } ! curwin->w_nrwidth_line_count = 0; // trigger a redraw } #endif *************** *** 3533,3539 **** */ if (old_Rows != Rows || old_Columns != Columns) { ! /* Changing the screen size is not allowed while updating the screen. */ if (updating_screen) *pp = old_value; else if (full_screen --- 3531,3537 ---- */ if (old_Rows != Rows || old_Columns != Columns) { ! // Changing the screen size is not allowed while updating the screen. if (updating_screen) *pp = old_value; else if (full_screen *************** *** 3544,3551 **** set_shellsize((int)Columns, (int)Rows, TRUE); else { ! /* Postpone the resizing; check the size and cmdline position for ! * messages. */ check_shellsize(); if (cmdline_row > Rows - p_ch && Rows > p_ch) cmdline_row = Rows - p_ch; --- 3542,3549 ---- set_shellsize((int)Columns, (int)Rows, TRUE); else { ! // Postpone the resizing; check the size and cmdline position for ! // messages. check_shellsize(); if (cmdline_row > Rows - p_ch && Rows > p_ch) cmdline_row = Rows - p_ch; *************** *** 3575,3585 **** errmsg = e_scroll; win_comp_scroll(curwin); } ! /* If 'scroll' became invalid because of a side effect silently adjust ! * it. */ else if (curwin->w_p_scr <= 0) curwin->w_p_scr = 1; ! else /* curwin->w_p_scr > curwin->w_height */ curwin->w_p_scr = curwin->w_height; } if (p_hi < 0) --- 3573,3583 ---- errmsg = e_scroll; win_comp_scroll(curwin); } ! // If 'scroll' became invalid because of a side effect silently adjust ! // it. else if (curwin->w_p_scr <= 0) curwin->w_p_scr = 1; ! else // curwin->w_p_scr > curwin->w_height curwin->w_p_scr = curwin->w_height; } if (p_hi < 0) *************** *** 3604,3610 **** } if ((p_sj < -100 || p_sj >= Rows) && full_screen) { ! if (Rows != old_Rows) /* Rows changed, just adjust p_sj */ p_sj = Rows / 2; else { --- 3602,3608 ---- } if ((p_sj < -100 || p_sj >= Rows) && full_screen) { ! if (Rows != old_Rows) // Rows changed, just adjust p_sj p_sj = Rows / 2; else { *************** *** 3640,3646 **** p_ss = 0; } ! /* May set global value for local option. */ if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; --- 3638,3644 ---- p_ss = 0; } ! // May set global value for local option. if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; *************** *** 3685,3691 **** } #endif ! comp_col(); /* in case 'columns' or 'ls' changed */ if (curwin->w_curswant != MAXCOL && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) curwin->w_set_curswant = TRUE; --- 3683,3689 ---- } #endif ! comp_col(); // in case 'columns' or 'ls' changed if (curwin->w_curswant != MAXCOL && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) curwin->w_set_curswant = TRUE; *************** *** 3700,3710 **** void check_redraw(long_u flags) { ! /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */ int doclear = (flags & P_RCLR) == P_RCLR; int all = ((flags & P_RALL) == P_RALL || doclear); ! if ((flags & P_RSTAT) || all) /* mark all status lines dirty */ status_redraw_all(); if ((flags & P_RBUF) || (flags & P_RWIN) || all) --- 3698,3708 ---- void check_redraw(long_u flags) { ! // Careful: P_RCLR and P_RALL are a combination of other P_ flags int doclear = (flags & P_RCLR) == P_RCLR; int all = ((flags & P_RALL) == P_RALL || doclear); ! if ((flags & P_RSTAT) || all) // mark all status lines dirty status_redraw_all(); if ((flags & P_RBUF) || (flags & P_RWIN) || all) *************** *** 3728,3734 **** { int opt_idx; char *s, *p; ! static short quick_tab[27] = {0, 0}; /* quick access table */ int is_term_opt; /* --- 3726,3732 ---- { int opt_idx; char *s, *p; ! static short quick_tab[27] = {0, 0}; // quick access table int is_term_opt; /* *************** *** 3769,3775 **** opt_idx = quick_tab[CharOrdLow(arg[0])]; for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++) { ! if (STRCMP(arg, s) == 0) /* match full name */ break; } if (s == NULL && !is_term_opt) --- 3767,3773 ---- opt_idx = quick_tab[CharOrdLow(arg[0])]; for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++) { ! if (STRCMP(arg, s) == 0) // match full name break; } if (s == NULL && !is_term_opt) *************** *** 3778,3784 **** for ( ; options[opt_idx].fullname != NULL; opt_idx++) { s = options[opt_idx].shortname; ! if (s != NULL && STRCMP(arg, s) == 0) /* match short name */ break; s = NULL; } --- 3776,3782 ---- for ( ; options[opt_idx].fullname != NULL; opt_idx++) { s = options[opt_idx].shortname; ! if (s != NULL && STRCMP(arg, s) == 0) // match short name break; s = NULL; } *************** *** 3803,3816 **** get_option_value( char_u *name, long *numval, ! char_u **stringval, /* NULL when only checking existence */ int opt_flags) { int opt_idx; char_u *varp; opt_idx = findoption(name); ! if (opt_idx < 0) /* unknown option */ { int key; --- 3801,3814 ---- get_option_value( char_u *name, long *numval, ! char_u **stringval, // NULL when only checking existence int opt_flags) { int opt_idx; char_u *varp; opt_idx = findoption(name); ! if (opt_idx < 0) // unknown option { int key; *************** *** 3845,3856 **** if (options[opt_idx].flags & P_STRING) { ! if (varp == NULL) /* hidden option */ return -2; if (stringval != NULL) { #ifdef FEAT_CRYPT ! /* never return the value of the crypt key */ if ((char_u **)varp == &curbuf->b_p_key && **(char_u **)(varp) != NUL) *stringval = vim_strsave((char_u *)"*****"); --- 3843,3854 ---- if (options[opt_idx].flags & P_STRING) { ! if (varp == NULL) // hidden option return -2; if (stringval != NULL) { #ifdef FEAT_CRYPT ! // never return the value of the crypt key if ((char_u **)varp == &curbuf->b_p_key && **(char_u **)(varp) != NUL) *stringval = vim_strsave((char_u *)"*****"); *************** *** 3861,3874 **** return 0; } ! if (varp == NULL) /* hidden option */ return -1; if (options[opt_idx].flags & P_NUM) *numval = *(long *)varp; else { ! /* Special case: 'modified' is b_changed, but we also want to consider ! * it set when 'ff' or 'fenc' changed. */ if ((int *)varp == &curbuf->b_changed) *numval = curbufIsChanged(); else --- 3859,3872 ---- return 0; } ! if (varp == NULL) // hidden option return -1; if (options[opt_idx].flags & P_NUM) *numval = *(long *)varp; else { ! // Special case: 'modified' is b_changed, but we also want to consider ! // it set when 'ff' or 'fenc' changed. if ((int *)varp == &curbuf->b_changed) *numval = curbufIsChanged(); else *************** *** 3901,3907 **** get_option_value_strict( char_u *name, long *numval, ! char_u **stringval, /* NULL when only obtaining attributes */ int opt_type, void *from) { --- 3899,3905 ---- get_option_value_strict( char_u *name, long *numval, ! char_u **stringval, // NULL when only obtaining attributes int opt_type, void *from) { *************** *** 3916,3922 **** p = &(options[opt_idx]); ! /* Hidden option */ if (p->var == NULL) return 0; --- 3914,3920 ---- p = &(options[opt_idx]); ! // Hidden option if (p->var == NULL) return 0; *************** *** 3932,3957 **** if (opt_type == SREQ_GLOBAL) r |= SOPT_GLOBAL; else ! return 0; /* Did not request global-only option */ } else { if (p->indir & PV_BOTH) r |= SOPT_GLOBAL; else if (opt_type == SREQ_GLOBAL) ! return 0; /* Requested global option */ if (p->indir & PV_WIN) { if (opt_type == SREQ_BUF) ! return 0; /* Did not request window-local option */ else r |= SOPT_WIN; } else if (p->indir & PV_BUF) { if (opt_type == SREQ_WIN) ! return 0; /* Did not request buffer-local option */ else r |= SOPT_BUF; } --- 3930,3955 ---- if (opt_type == SREQ_GLOBAL) r |= SOPT_GLOBAL; else ! return 0; // Did not request global-only option } else { if (p->indir & PV_BOTH) r |= SOPT_GLOBAL; else if (opt_type == SREQ_GLOBAL) ! return 0; // Requested global option if (p->indir & PV_WIN) { if (opt_type == SREQ_BUF) ! return 0; // Did not request window-local option else r |= SOPT_WIN; } else if (p->indir & PV_BUF) { if (opt_type == SREQ_WIN) ! return 0; // Did not request buffer-local option else r |= SOPT_BUF; } *************** *** 3966,3973 **** { if (opt_type == SREQ_BUF) { ! /* Special case: 'modified' is b_changed, but we also want to ! * consider it set when 'ff' or 'fenc' changed. */ if (p->indir == PV_MOD) { *numval = bufIsChanged((buf_T *)from); --- 3964,3971 ---- { if (opt_type == SREQ_BUF) { ! // Special case: 'modified' is b_changed, but we also want to ! // consider it set when 'ff' or 'fenc' changed. if (p->indir == PV_MOD) { *numval = bufIsChanged((buf_T *)from); *************** *** 3976,3982 **** #ifdef FEAT_CRYPT else if (p->indir == PV_KEY) { ! /* never return the value of the crypt key */ *stringval = NULL; varp = NULL; } --- 3974,3980 ---- #ifdef FEAT_CRYPT else if (p->indir == PV_KEY) { ! // never return the value of the crypt key *stringval = NULL; varp = NULL; } *************** *** 4050,4056 **** ret = ((struct vimoption *) (*option)); ! /* Hidden option */ if (ret->var == NULL) { ret = NULL; --- 4048,4054 ---- ret = ((struct vimoption *) (*option)); ! // Hidden option if (ret->var == NULL) { ret = NULL; *************** *** 4168,4174 **** char_u *name, long number, char_u *string, ! int opt_flags) /* OPT_LOCAL or 0 (both) */ { int opt_idx; char_u *varp; --- 4166,4172 ---- char_u *name, long number, char_u *string, ! int opt_flags) // OPT_LOCAL or 0 (both) { int opt_idx; char_u *varp; *************** *** 4207,4213 **** { flags = options[opt_idx].flags; #ifdef HAVE_SANDBOX ! /* Disallow changing some options in the sandbox */ if (sandbox > 0 && (flags & P_SECURE)) { emsg(_(e_sandbox)); --- 4205,4211 ---- { flags = options[opt_idx].flags; #ifdef HAVE_SANDBOX ! // Disallow changing some options in the sandbox if (sandbox > 0 && (flags & P_SECURE)) { emsg(_(e_sandbox)); *************** *** 4219,4242 **** else { varp = get_varp_scope(&(options[opt_idx]), opt_flags); ! if (varp != NULL) /* hidden option is not changed */ { if (number == 0 && string != NULL) { int idx; ! /* Either we are given a string or we are setting option ! * to zero. */ for (idx = 0; string[idx] == '0'; ++idx) ; if (string[idx] != NUL || idx == 0) { ! /* There's another character after zeros or the string ! * is empty. In both cases, we are trying to set a ! * num option using a string. */ semsg(_("E521: Number required: &%s = '%s'"), name, string); ! return NULL; /* do nothing as we hit an error */ } } --- 4217,4240 ---- else { varp = get_varp_scope(&(options[opt_idx]), opt_flags); ! if (varp != NULL) // hidden option is not changed { if (number == 0 && string != NULL) { int idx; ! // Either we are given a string or we are setting option ! // to zero. for (idx = 0; string[idx] == '0'; ++idx) ; if (string[idx] != NUL || idx == 0) { ! // There's another character after zeros or the string ! // is empty. In both cases, we are trying to set a ! // num option using a string. semsg(_("E521: Number required: &%s = '%s'"), name, string); ! return NULL; // do nothing as we hit an error } } *************** *** 4317,4326 **** key = TERMCAP2KEY(arg[2], arg[3]); else if (has_lt) { ! --arg; /* put arg at the '<' */ modifiers = 0; key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE, TRUE, NULL); ! if (modifiers) /* can't handle modifiers here */ key = 0; } return key; --- 4315,4324 ---- key = TERMCAP2KEY(arg[2], arg[3]); else if (has_lt) { ! --arg; // put arg at the '<' modifiers = 0; key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE, TRUE, NULL); ! if (modifiers) // can't handle modifiers here key = 0; } return key; *************** *** 4334,4340 **** static void showoptions( int all, ! int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */ { struct vimoption *p; int col; --- 4332,4338 ---- static void showoptions( int all, ! int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL { struct vimoption *p; int col; *************** *** 4355,4361 **** if (items == NULL) return; ! /* Highlight title */ if (all == 2) msg_puts_title(_("\n--- Terminal codes ---")); else if (opt_flags & OPT_GLOBAL) --- 4353,4359 ---- if (items == NULL) return; ! // Highlight title if (all == 2) msg_puts_title(_("\n--- Terminal codes ---")); else if (opt_flags & OPT_GLOBAL) *************** *** 4397,4403 **** || (all == 0 && !optval_default(p, varp, p_cp)))) { if (p->flags & P_BOOL) ! len = 1; /* a toggle option fits always */ else { option_value2string(p, opt_flags); --- 4395,4401 ---- || (all == 0 && !optval_default(p, varp, p_cp)))) { if (p->flags & P_BOOL) ! len = 1; // a toggle option fits always else { option_value2string(p, opt_flags); *************** *** 4419,4435 **** cols = 1; rows = (item_count + cols - 1) / cols; } ! else /* run == 2 */ rows = item_count; for (row = 0; row < rows && !got_int; ++row) { ! msg_putchar('\n'); /* go to next line */ ! if (got_int) /* 'q' typed in more */ break; col = 0; for (i = row; i < item_count; i += rows) { ! msg_col = col; /* make columns */ showoneopt(items[i], opt_flags); col += INC; } --- 4417,4433 ---- cols = 1; rows = (item_count + cols - 1) / cols; } ! else // run == 2 rows = item_count; for (row = 0; row < rows && !got_int; ++row) { ! msg_putchar('\n'); // go to next line ! if (got_int) // 'q' typed in more break; col = 0; for (i = row; i < item_count; i += rows) { ! msg_col = col; // make columns showoneopt(items[i], opt_flags); col += INC; } *************** *** 4449,4463 **** int dvi; if (varp == NULL) ! return TRUE; /* hidden option is always at default */ dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; if (p->flags & P_NUM) return (*(long *)varp == (long)(long_i)p->def_val[dvi]); if (p->flags & P_BOOL) ! /* the cast to long is required for Manx C, long_i is ! * needed for MSVC */ return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]); ! /* P_STRING */ return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0); } --- 4447,4461 ---- int dvi; if (varp == NULL) ! return TRUE; // hidden option is always at default dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; if (p->flags & P_NUM) return (*(long *)varp == (long)(long_i)p->def_val[dvi]); if (p->flags & P_BOOL) ! // the cast to long is required for Manx C, long_i is ! // needed for MSVC return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]); ! // P_STRING return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0); } *************** *** 4468,4484 **** static void showoneopt( struct vimoption *p, ! int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */ { char_u *varp; int save_silent = silent_mode; silent_mode = FALSE; ! info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ varp = get_varp_scope(p, opt_flags); ! /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */ if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed ? !curbufIsChanged() : !*(int *)varp)) msg_puts("no"); --- 4466,4482 ---- static void showoneopt( struct vimoption *p, ! int opt_flags) // OPT_LOCAL or OPT_GLOBAL { char_u *varp; int save_silent = silent_mode; silent_mode = FALSE; ! info_message = TRUE; // use mch_msg(), not mch_errmsg() varp = get_varp_scope(p, opt_flags); ! // for 'modified' we also need to check if 'ff' or 'fenc' changed. if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed ? !curbufIsChanged() : !*(int *)varp)) msg_puts("no"); *************** *** 4490,4496 **** if (!(p->flags & P_BOOL)) { msg_putchar('='); ! /* put value string in NameBuff */ option_value2string(p, opt_flags); msg_outtrans(NameBuff); } --- 4488,4494 ---- if (!(p->flags & P_BOOL)) { msg_putchar('='); ! // put value string in NameBuff option_value2string(p, opt_flags); msg_outtrans(NameBuff); } *************** *** 4525,4533 **** makeset(FILE *fd, int opt_flags, int local_only) { struct vimoption *p; ! char_u *varp; /* currently used value */ ! char_u *varp_fresh; /* local value */ ! char_u *varp_local = NULL; /* fresh value */ char *cmd; int round; int pri; --- 4523,4531 ---- makeset(FILE *fd, int opt_flags, int local_only) { struct vimoption *p; ! char_u *varp; // currently used value ! char_u *varp_fresh; // local value ! char_u *varp_local = NULL; // fresh value char *cmd; int round; int pri; *************** *** 4545,4560 **** && !istermoption(p) && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) { ! /* skip global option when only doing locals */ if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL)) continue; ! /* Do not store options like 'bufhidden' and 'syntax' in a vimrc ! * file, they are always buffer-specific. */ if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB)) continue; ! /* Global values are only written when not at the default value. */ varp = get_varp_scope(p, opt_flags); if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp)) continue; --- 4543,4558 ---- && !istermoption(p) && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) { ! // skip global option when only doing locals if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL)) continue; ! // Do not store options like 'bufhidden' and 'syntax' in a vimrc ! // file, they are always buffer-specific. if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB)) continue; ! // Global values are only written when not at the default value. varp = get_varp_scope(p, opt_flags); if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp)) continue; *************** *** 4564,4574 **** { if (p->var == VAR_WIN) { ! /* skip window-local option when only doing globals */ if (!(opt_flags & OPT_LOCAL)) continue; ! /* When fresh value of window-local option is not at the ! * default, need to write it too. */ if (!(opt_flags & OPT_GLOBAL) && !local_only) { varp_fresh = get_varp_scope(p, OPT_GLOBAL); --- 4562,4572 ---- { if (p->var == VAR_WIN) { ! // skip window-local option when only doing globals if (!(opt_flags & OPT_LOCAL)) continue; ! // When fresh value of window-local option is not at the ! // default, need to write it too. if (!(opt_flags & OPT_GLOBAL) && !local_only) { varp_fresh = get_varp_scope(p, OPT_GLOBAL); *************** *** 4582,4589 **** } } ! /* Round 1: fresh value for window-local options. ! * Round 2: other values */ for ( ; round <= 2; varp = varp_local, ++round) { if (round == 1 || (opt_flags & OPT_GLOBAL)) --- 4580,4587 ---- } } ! // Round 1: fresh value for window-local options. ! // Round 2: other values for ( ; round <= 2; varp = varp_local, ++round) { if (round == 1 || (opt_flags & OPT_GLOBAL)) *************** *** 4601,4612 **** if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL) return FAIL; } ! else /* P_STRING */ { int do_endif = FALSE; ! /* Don't set 'syntax' and 'filetype' again if the value is ! * already right, avoids reloading the syntax file. */ if ( #if defined(FEAT_SYN_HL) p->indir == PV_SYN || --- 4599,4610 ---- if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL) return FAIL; } ! else // P_STRING { int do_endif = FALSE; ! // Don't set 'syntax' and 'filetype' again if the value is ! // already right, avoids reloading the syntax file. if ( #if defined(FEAT_SYN_HL) p->indir == PV_SYN || *************** *** 4679,4687 **** return FAIL; if (*valuep != NULL) { ! /* Output 'pastetoggle' as key names. For other ! * options some characters have to be escaped with ! * CTRL-V or backslash */ if (valuep == &p_pt) { s = *valuep; --- 4677,4685 ---- return FAIL; if (*valuep != NULL) { ! // Output 'pastetoggle' as key names. For other ! // options some characters have to be escaped with ! // CTRL-V or backslash if (valuep == &p_pt) { s = *valuep; *************** *** 4761,4767 **** return FAIL; if (wc_use_keyname((char_u *)valuep, &wc)) { ! /* print 'wildchar' and 'wildcharm' as a key name */ if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0) return FAIL; } --- 4759,4765 ---- return FAIL; if (wc_use_keyname((char_u *)valuep, &wc)) { ! // print 'wildchar' and 'wildcharm' as a key name if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0) return FAIL; } *************** *** 4779,4785 **** char *name, int value) { ! if (value < 0) /* global/local option using global value */ return OK; if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0 || put_eol(fd) < 0) --- 4777,4783 ---- char *name, int value) { ! if (value < 0) // global/local option using global value return OK; if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0 || put_eol(fd) < 0) *************** *** 4802,4816 **** */ mch_setmouse(FALSE); // switch mouse off #ifdef FEAT_TITLE ! mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */ #endif #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI) ! /* When starting the GUI close the display opened for the clipboard. ! * After restoring the title, because that will need the display. */ if (gui.starting) clear_xterm_clip(); #endif ! stoptermcap(); /* stop termcap mode */ free_termoptions(); } --- 4800,4814 ---- */ mch_setmouse(FALSE); // switch mouse off #ifdef FEAT_TITLE ! mch_restore_title(SAVE_RESTORE_BOTH); // restore window titles #endif #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI) ! // When starting the GUI close the display opened for the clipboard. ! // After restoring the title, because that will need the display. if (gui.starting) clear_xterm_clip(); #endif ! stoptermcap(); // stop termcap mode free_termoptions(); } *************** *** 4881,4887 **** if (p->flags & P_ALLOCED) { p->flags |= P_DEF_ALLOCED; ! p->flags &= ~P_ALLOCED; /* don't free the value now */ } } } --- 4879,4885 ---- if (p->flags & P_ALLOCED) { p->flags |= P_DEF_ALLOCED; ! p->flags &= ~P_ALLOCED; // don't free the value now } } } *************** *** 4923,4929 **** switch ((int)p->indir) { ! /* global option with local value: use local value if it's been set */ case PV_EP: clear_string_option(&buf->b_p_ep); break; --- 4921,4927 ---- switch ((int)p->indir) { ! // global option with local value: use local value if it's been set case PV_EP: clear_string_option(&buf->b_p_ep); break; *************** *** 5071,5077 **** case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); case PV_MENC: return (char_u *)&(curbuf->b_p_menc); } ! return NULL; /* "cannot happen" */ } return get_varp(p); } --- 5069,5075 ---- case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); case PV_MENC: return (char_u *)&(curbuf->b_p_menc); } ! return NULL; // "cannot happen" } return get_varp(p); } *************** *** 5092,5098 **** static char_u * get_varp(struct vimoption *p) { ! /* hidden option, always return NULL */ if (p->var == NULL) return NULL; --- 5090,5096 ---- static char_u * get_varp(struct vimoption *p) { ! // hidden option, always return NULL if (p->var == NULL) return NULL; *************** *** 5100,5106 **** { case PV_NONE: return p->var; ! /* global option with local value: use local value if it's been set */ case PV_EP: return *curbuf->b_p_ep != NUL ? (char_u *)&curbuf->b_p_ep : p->var; case PV_KP: return *curbuf->b_p_kp != NUL --- 5098,5104 ---- { case PV_NONE: return p->var; ! // global option with local value: use local value if it's been set case PV_EP: return *curbuf->b_p_ep != NUL ? (char_u *)&curbuf->b_p_ep : p->var; case PV_KP: return *curbuf->b_p_kp != NUL *************** *** 5335,5341 **** #endif default: iemsg(_("E356: get_varp ERROR")); } ! /* always return a valid pointer to avoid a crash! */ return (char_u *)&(curbuf->b_p_wm); } --- 5333,5339 ---- #endif default: iemsg(_("E356: get_varp ERROR")); } ! // always return a valid pointer to avoid a crash! return (char_u *)&(curbuf->b_p_wm); } *************** *** 5486,5492 **** mch_memmove(to->wo_script_ctx, from->wo_script_ctx, sizeof(to->wo_script_ctx)); #endif ! check_winopt(to); /* don't want NULL pointers */ } /* --- 5484,5490 ---- mch_memmove(to->wo_script_ctx, from->wo_script_ctx, sizeof(to->wo_script_ctx)); #endif ! check_winopt(to); // don't want NULL pointers } /* *************** *** 5627,5633 **** buf_copy_options(buf_T *buf, int flags) { int should_copy = TRUE; ! char_u *save_p_isk = NULL; /* init for GCC */ int dont_do_help; int did_isk = FALSE; --- 5625,5631 ---- buf_copy_options(buf_T *buf, int flags) { int should_copy = TRUE; ! char_u *save_p_isk = NULL; // init for GCC int dont_do_help; int did_isk = FALSE; *************** *** 5678,5684 **** if (!buf->b_p_initialized) { free_buf_options(buf, TRUE); ! buf->b_p_ro = FALSE; /* don't copy readonly */ buf->b_p_tx = p_tx; buf->b_p_fenc = vim_strsave(p_fenc); switch (*p_ffs) --- 5676,5682 ---- if (!buf->b_p_initialized) { free_buf_options(buf, TRUE); ! buf->b_p_ro = FALSE; // don't copy readonly buf->b_p_tx = p_tx; buf->b_p_fenc = vim_strsave(p_fenc); switch (*p_ffs) *************** *** 5809,5815 **** COPY_OPT_SCTX(buf, BV_LISP); #endif #ifdef FEAT_SYN_HL ! /* Don't copy 'syntax', it must be set */ buf->b_p_syn = empty_option; buf->b_p_smc = p_smc; COPY_OPT_SCTX(buf, BV_SMC); --- 5807,5813 ---- COPY_OPT_SCTX(buf, BV_LISP); #endif #ifdef FEAT_SYN_HL ! // Don't copy 'syntax', it must be set buf->b_p_syn = empty_option; buf->b_p_smc = p_smc; COPY_OPT_SCTX(buf, BV_SMC); *************** *** 5852,5866 **** buf->b_p_twsl = p_twsl; COPY_OPT_SCTX(buf, BV_TWSL); #endif ! /* This isn't really an option, but copying the langmap and IME ! * state from the current buffer is better than resetting it. */ buf->b_p_iminsert = p_iminsert; COPY_OPT_SCTX(buf, BV_IMI); buf->b_p_imsearch = p_imsearch; COPY_OPT_SCTX(buf, BV_IMS); ! /* options that are normally global but also have a local value ! * are not copied, start using the global value */ buf->b_p_ar = -1; buf->b_p_ul = NO_LOCAL_UNDOLEVEL; buf->b_p_bkc = empty_option; --- 5850,5864 ---- buf->b_p_twsl = p_twsl; COPY_OPT_SCTX(buf, BV_TWSL); #endif ! // This isn't really an option, but copying the langmap and IME ! // state from the current buffer is better than resetting it. buf->b_p_iminsert = p_iminsert; COPY_OPT_SCTX(buf, BV_IMI); buf->b_p_imsearch = p_imsearch; COPY_OPT_SCTX(buf, BV_IMS); ! // options that are normally global but also have a local value ! // are not copied, start using the global value buf->b_p_ar = -1; buf->b_p_ul = NO_LOCAL_UNDOLEVEL; buf->b_p_bkc = empty_option; *************** *** 5951,5957 **** buf->b_p_initialized = TRUE; } ! check_buf_options(buf); /* make sure we don't have NULLs */ if (did_isk) (void)buf_init_chartab(buf, FALSE); } --- 5949,5955 ---- buf->b_p_initialized = TRUE; } ! check_buf_options(buf); // make sure we don't have NULLs if (did_isk) (void)buf_init_chartab(buf, FALSE); } *************** *** 5997,6007 **** set_context_in_set_cmd( expand_T *xp, char_u *arg, ! int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */ { int nextchar; ! long_u flags = 0; /* init for GCC */ ! int opt_idx = 0; /* init for GCC */ char_u *p; char_u *s; int is_term_option = FALSE; --- 5995,6005 ---- set_context_in_set_cmd( expand_T *xp, char_u *arg, ! int opt_flags) // OPT_GLOBAL and/or OPT_LOCAL { int nextchar; ! long_u flags = 0; // init for GCC ! int opt_idx = 0; // init for GCC char_u *p; char_u *s; int is_term_option = FALSE; *************** *** 6024,6036 **** while (p > arg) { s = p; ! /* count number of backslashes before ' ' or ',' */ if (*p == ' ' || *p == ',') { while (s > arg && *(s - 1) == '\\') --s; } ! /* break at a space with an even number of backslashes */ if (*p == ' ' && ((p - s) & 1) == 0) { ++p; --- 6022,6034 ---- while (p > arg) { s = p; ! // count number of backslashes before ' ' or ',' if (*p == ' ' || *p == ',') { while (s > arg && *(s - 1) == '\\') --s; } ! // break at a space with an even number of backslashes if (*p == ' ' && ((p - s) & 1) == 0) { ++p; *************** *** 6052,6061 **** if (*arg == '<') { while (*p != '>') ! if (*p++ == NUL) /* expand terminal option name */ return; key = get_special_key_code(arg + 1); ! if (key == 0) /* unknown name */ { xp->xp_context = EXPAND_NOTHING; return; --- 6050,6059 ---- if (*arg == '<') { while (*p != '>') ! if (*p++ == NUL) // expand terminal option name return; key = get_special_key_code(arg + 1); ! if (key == 0) // unknown name { xp->xp_context = EXPAND_NOTHING; return; *************** *** 6073,6079 **** if (*p != NUL) ++p; if (*p == NUL) ! return; /* expand option name */ nextchar = *++p; is_term_option = TRUE; expand_option_name[2] = p[-2]; --- 6071,6077 ---- if (*p != NUL) ++p; if (*p == NUL) ! return; // expand option name nextchar = *++p; is_term_option = TRUE; expand_option_name[2] = p[-2]; *************** *** 6081,6087 **** } else { ! /* Allow * wildcard */ while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') p++; if (*p == NUL) --- 6079,6085 ---- } else { ! // Allow * wildcard while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') p++; if (*p == NUL) *************** *** 6103,6109 **** } } } ! /* handle "-=" and "+=" */ if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=') { ++p; --- 6101,6107 ---- } } } ! // handle "-=" and "+=" if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=') { ++p; *************** *** 6160,6166 **** else { xp->xp_context = EXPAND_FILES; ! /* for 'tags' need three backslashes for a space */ if (p == (char_u *)&p_tags) xp->xp_backslash = XP_BS_THREE; else --- 6158,6164 ---- else { xp->xp_context = EXPAND_FILES; ! // for 'tags' need three backslashes for a space if (p == (char_u *)&p_tags) xp->xp_backslash = XP_BS_THREE; else *************** *** 6168,6178 **** } } ! /* For an option that is a list of file names, find the start of the ! * last file name. */ for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p) { ! /* count number of backslashes before ' ' or ',' */ if (*p == ' ' || *p == ',') { s = p; --- 6166,6176 ---- } } ! // For an option that is a list of file names, find the start of the ! // last file name. for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p) { ! // count number of backslashes before ' ' or ',' if (*p == ' ' || *p == ',') { s = p; *************** *** 6187,6193 **** } #ifdef FEAT_SPELL ! /* for 'spellsuggest' start at "file:" */ if (options[opt_idx].var == (char_u *)&p_sps && STRNCMP(p, "file:", 5) == 0) { --- 6185,6191 ---- } #ifdef FEAT_SPELL ! // for 'spellsuggest' start at "file:" if (options[opt_idx].var == (char_u *)&p_sps && STRNCMP(p, "file:", 5) == 0) { *************** *** 6207,6214 **** int *num_file, char_u ***file) { ! int num_normal = 0; /* Nr of matching non-term-code settings */ ! int num_term = 0; /* Nr of matching terminal code settings */ int opt_idx; int match; int count = 0; --- 6205,6212 ---- int *num_file, char_u ***file) { ! int num_normal = 0; // Nr of matching non-term-code settings ! int num_term = 0; // Nr of matching terminal code settings int opt_idx; int match; int count = 0; *************** *** 6217,6228 **** int is_term_opt; char_u name_buf[MAX_KEY_NAME_LEN]; static char *(names[]) = {"all", "termcap"}; ! int ic = regmatch->rm_ic; /* remember the ignore-case flag */ ! /* do this loop twice: ! * loop == 0: count the number of matching options ! * loop == 1: copy the matching options into allocated memory ! */ for (loop = 0; loop <= 1; ++loop) { regmatch->rm_ic = ic; --- 6215,6225 ---- int is_term_opt; char_u name_buf[MAX_KEY_NAME_LEN]; static char *(names[]) = {"all", "termcap"}; ! int ic = regmatch->rm_ic; // remember the ignore-case flag ! // do this loop twice: ! // loop == 0: count the number of matching options ! // loop == 1: copy the matching options into allocated memory for (loop = 0; loop <= 1; ++loop) { regmatch->rm_ic = ic; *************** *** 6327,6333 **** /* * Check special key names. */ ! regmatch->rm_ic = TRUE; /* ignore case here */ for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++) { name_buf[0] = '<'; --- 6324,6330 ---- /* * Check special key names. */ ! regmatch->rm_ic = TRUE; // ignore case here for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++) { name_buf[0] = '<'; *************** *** 6365,6371 **** int ExpandOldSetting(int *num_file, char_u ***file) { ! char_u *var = NULL; /* init for GCC */ char_u *buf; *num_file = 0; --- 6362,6368 ---- int ExpandOldSetting(int *num_file, char_u ***file) { ! char_u *var = NULL; // init for GCC char_u *buf; *num_file = 0; *************** *** 6385,6399 **** if (expand_option_idx >= 0) { ! /* put string of option value in NameBuff */ option_value2string(&options[expand_option_idx], expand_option_flags); var = NameBuff; } else if (var == NULL) var = (char_u *)""; ! /* A backslash is required before some characters. This is the reverse of ! * what happens in do_set(). */ buf = vim_strsave_escaped(var, escape_chars); if (buf == NULL) --- 6382,6396 ---- if (expand_option_idx >= 0) { ! // put string of option value in NameBuff option_value2string(&options[expand_option_idx], expand_option_flags); var = NameBuff; } else if (var == NULL) var = (char_u *)""; ! // A backslash is required before some characters. This is the reverse of ! // what happens in do_set(). buf = vim_strsave_escaped(var, escape_chars); if (buf == NULL) *************** *** 6403,6410 **** } #ifdef BACKSLASH_IN_FILENAME ! /* For MS-Windows et al. we don't double backslashes at the start and ! * before a file name character. */ for (var = buf; *var != NUL; MB_PTR_ADV(var)) if (var[0] == '\\' && var[1] == '\\' && expand_option_idx >= 0 --- 6400,6407 ---- } #ifdef BACKSLASH_IN_FILENAME ! // For MS-Windows et al. we don't double backslashes at the start and ! // before a file name character. for (var = buf; *var != NUL; MB_PTR_ADV(var)) if (var[0] == '\\' && var[1] == '\\' && expand_option_idx >= 0 *************** *** 6426,6432 **** static void option_value2string( struct vimoption *opp, ! int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */ { char_u *varp; --- 6423,6429 ---- static void option_value2string( struct vimoption *opp, ! int opt_flags) // OPT_GLOBAL and/or OPT_LOCAL { char_u *varp; *************** *** 6443,6461 **** else sprintf((char *)NameBuff, "%ld", *(long *)varp); } ! else /* P_STRING */ { varp = *(char_u **)(varp); ! if (varp == NULL) /* just in case */ NameBuff[0] = NUL; #ifdef FEAT_CRYPT ! /* don't show the actual value of 'key', only that it's set */ else if (opp->var == (char_u *)&p_key && *varp) STRCPY(NameBuff, "*****"); #endif else if (opp->flags & P_EXPAND) home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE); ! /* Translate 'pastetoggle' into special key names */ else if ((char_u **)opp->var == &p_pt) str2specialbuf(p_pt, NameBuff, MAXPATHL); else --- 6440,6458 ---- else sprintf((char *)NameBuff, "%ld", *(long *)varp); } ! else // P_STRING { varp = *(char_u **)(varp); ! if (varp == NULL) // just in case NameBuff[0] = NUL; #ifdef FEAT_CRYPT ! // don't show the actual value of 'key', only that it's set else if (opp->var == (char_u *)&p_key && *varp) STRCPY(NameBuff, "*****"); #endif else if (opp->flags & P_EXPAND) home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE); ! // Translate 'pastetoggle' into special key names else if ((char_u **)opp->var == &p_pt) str2specialbuf(p_pt, NameBuff, MAXPATHL); else *************** *** 6531,6537 **** */ if (!old_p_paste) { ! /* save options for each buffer */ FOR_ALL_BUFFERS(buf) { buf->b_p_tw_nopaste = buf->b_p_tw; --- 6528,6534 ---- */ if (!old_p_paste) { ! // save options for each buffer FOR_ALL_BUFFERS(buf) { buf->b_p_tw_nopaste = buf->b_p_tw; *************** *** 6547,6553 **** #endif } ! /* save global options */ save_sm = p_sm; save_sta = p_sta; #ifdef FEAT_CMDL_INFO --- 6544,6550 ---- #endif } ! // save global options save_sm = p_sm; save_sta = p_sta; #ifdef FEAT_CMDL_INFO *************** *** 6557,6563 **** save_ri = p_ri; save_hkmap = p_hkmap; #endif ! /* save global values for local buffer options */ p_ai_nopaste = p_ai; p_et_nopaste = p_et; p_sts_nopaste = p_sts; --- 6554,6560 ---- save_ri = p_ri; save_hkmap = p_hkmap; #endif ! // save global values for local buffer options p_ai_nopaste = p_ai; p_et_nopaste = p_et; p_sts_nopaste = p_sts; *************** *** 6574,6587 **** * Always set the option values, also when 'paste' is set when it is * already on. */ ! /* set options for each buffer */ FOR_ALL_BUFFERS(buf) { ! buf->b_p_tw = 0; /* textwidth is 0 */ ! buf->b_p_wm = 0; /* wrapmargin is 0 */ ! buf->b_p_sts = 0; /* softtabstop is 0 */ ! buf->b_p_ai = 0; /* no auto-indent */ ! buf->b_p_et = 0; /* no expandtab */ #ifdef FEAT_VARTABS if (buf->b_p_vsts) free_string_option(buf->b_p_vsts); --- 6571,6584 ---- * Always set the option values, also when 'paste' is set when it is * already on. */ ! // set options for each buffer FOR_ALL_BUFFERS(buf) { ! buf->b_p_tw = 0; // textwidth is 0 ! buf->b_p_wm = 0; // wrapmargin is 0 ! buf->b_p_sts = 0; // softtabstop is 0 ! buf->b_p_ai = 0; // no auto-indent ! buf->b_p_et = 0; // no expandtab #ifdef FEAT_VARTABS if (buf->b_p_vsts) free_string_option(buf->b_p_vsts); *************** *** 6592,6610 **** #endif } ! /* set global options */ ! p_sm = 0; /* no showmatch */ ! p_sta = 0; /* no smarttab */ #ifdef FEAT_CMDL_INFO if (p_ru) ! status_redraw_all(); /* redraw to remove the ruler */ ! p_ru = 0; /* no ruler */ #endif #ifdef FEAT_RIGHTLEFT ! p_ri = 0; /* no reverse insert */ ! p_hkmap = 0; /* no Hebrew keyboard */ #endif ! /* set global values for local buffer options */ p_tw = 0; p_wm = 0; p_sts = 0; --- 6589,6607 ---- #endif } ! // set global options ! p_sm = 0; // no showmatch ! p_sta = 0; // no smarttab #ifdef FEAT_CMDL_INFO if (p_ru) ! status_redraw_all(); // redraw to remove the ruler ! p_ru = 0; // no ruler #endif #ifdef FEAT_RIGHTLEFT ! p_ri = 0; // no reverse insert ! p_hkmap = 0; // no Hebrew keyboard #endif ! // set global values for local buffer options p_tw = 0; p_wm = 0; p_sts = 0; *************** *** 6621,6627 **** */ else if (old_p_paste) { ! /* restore options for each buffer */ FOR_ALL_BUFFERS(buf) { buf->b_p_tw = buf->b_p_tw_nopaste; --- 6618,6624 ---- */ else if (old_p_paste) { ! // restore options for each buffer FOR_ALL_BUFFERS(buf) { buf->b_p_tw = buf->b_p_tw_nopaste; *************** *** 6643,6661 **** #endif } ! /* restore global options */ p_sm = save_sm; p_sta = save_sta; #ifdef FEAT_CMDL_INFO if (p_ru != save_ru) ! status_redraw_all(); /* redraw to draw the ruler */ p_ru = save_ru; #endif #ifdef FEAT_RIGHTLEFT p_ri = save_ri; p_hkmap = save_hkmap; #endif ! /* set global values for local buffer options */ p_ai = p_ai_nopaste; p_et = p_et_nopaste; p_sts = p_sts_nopaste; --- 6640,6658 ---- #endif } ! // restore global options p_sm = save_sm; p_sta = save_sta; #ifdef FEAT_CMDL_INFO if (p_ru != save_ru) ! status_redraw_all(); // redraw to draw the ruler p_ru = save_ru; #endif #ifdef FEAT_RIGHTLEFT p_ri = save_ri; p_hkmap = save_hkmap; #endif ! // set global values for local buffer options p_ai = p_ai_nopaste; p_et = p_et_nopaste; p_sts = p_sts_nopaste; *************** *** 6701,6707 **** p = vim_getenv(envname, &dofree); if (p == NULL) { ! /* Set $MYVIMRC to the first vimrc file found. */ p = FullName_save(fname, FALSE); if (p != NULL) { --- 6698,6704 ---- p = vim_getenv(envname, &dofree); if (p == NULL) { ! // Set $MYVIMRC to the first vimrc file found. p = FullName_save(fname, FALSE); if (p != NULL) { *************** *** 6742,6748 **** int idx; idx = findoption(name); ! if (idx < 0) /* unknown option */ return FALSE; if (options[idx].flags & P_WAS_SET) return TRUE; --- 6739,6745 ---- int idx; idx = findoption(name); ! if (idx < 0) // unknown option return FALSE; if (options[idx].flags & P_WAS_SET) return TRUE; *************** *** 6811,6817 **** */ int can_bs( ! int what) /* BS_INDENT, BS_EOL or BS_START */ { #ifdef FEAT_JOB_CHANNEL if (what == BS_START && bt_prompt(curbuf)) --- 6808,6814 ---- */ int can_bs( ! int what) // BS_INDENT, BS_EOL or BS_START { #ifdef FEAT_JOB_CHANNEL if (what == BS_START && bt_prompt(curbuf)) *** ../vim-8.1.2391/src/version.c 2019-12-05 18:35:40.587297645 +0100 --- src/version.c 2019-12-05 20:12:02.292099050 +0100 *************** *** 744,745 **** --- 744,747 ---- { /* Add new patch number below this line */ + /**/ + 2392, /**/ -- hundred-and-one symptoms of being an internet addict: 195. Your cat has its own home page. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///