>From 753e76e0014bbae917f0659ab967a0ddb0ba39c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Sat, 8 Dec 2018 04:03:19 -0200 Subject: [PATCH 1/2] linter: allow lint navigation when not in lint mode. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement navigation of lints even when not in lint mode. Signed-off-by: Marco Diego Aurélio Mesquita --- src/global.c | 8 ++ src/proto.h | 2 + src/text.c | 281 ++++++++++++++++++++++++++++++++++++----------------------- 3 files changed, 183 insertions(+), 108 deletions(-) diff --git a/src/global.c b/src/global.c index a0d088c8..736039bc 100644 --- a/src/global.c +++ b/src/global.c @@ -983,6 +983,10 @@ void shortcut_init(void) add_to_funcs(zap_text, MMAIN, N_("Zap Text"), WITHORSANS(zap_gist), BLANKAFTER, NOVIEW); + add_to_funcs(prev_lint, MMAIN, + N_("Previous lint"), WITHORSANS(prevlint_gist), TOGETHER, VIEW); + add_to_funcs(next_lint, MMAIN, + N_("Next lint"), WITHORSANS(prevlint_gist), BLANKAFTER, VIEW); #ifdef ENABLE_COLOR if (!ISSET(RESTRICTED)) add_to_funcs(do_linter, MMAIN, @@ -1485,6 +1489,10 @@ sc *strtosc(const char *input) #ifdef ENABLE_COLOR else if (!strcasecmp(input, "linter")) s->func = do_linter; + else if (!strcasecmp(input, "prevlint")) + s->func = prev_lint; + else if (!strcasecmp(input, "nextlint")) + s->func = next_lint; #endif else if (!strcasecmp(input, "curpos")) s->func = do_cursorpos_void; diff --git a/src/proto.h b/src/proto.h index 5923670f..d65cd6d1 100644 --- a/src/proto.h +++ b/src/proto.h @@ -253,6 +253,8 @@ void do_cut_text_void(void); void do_copy_text(void); void do_cut_till_eof(void); void zap_text(void); +void prev_lint(void); +void next_lint(void); #endif void do_uncut_text(void); diff --git a/src/text.c b/src/text.c index 7190de5e..4bf761b8 100644 --- a/src/text.c +++ b/src/text.c @@ -47,6 +47,8 @@ static completion_word *list_of_completions; /* A linked list of the completions that have been attempted. */ #endif +static lintstruct *lints = NULL, *curlint = NULL, *tmplint = NULL; + #ifndef NANO_TINY /* Toggle the mark. */ void do_mark(void) @@ -62,6 +64,7 @@ void do_mark(void) refresh_needed = TRUE; } } + #endif /* !NANO_TINY */ #if defined(ENABLE_COLOR) || defined(ENABLE_SPELLER) @@ -2814,6 +2817,159 @@ void do_spell(void) #endif /* ENABLE_SPELLER */ #ifdef ENABLE_COLOR + +/* 0 - normal + 1 - break + 2 - continue + 3 - return*/ +int display_lint(void) +{ + struct stat lintfileinfo; + if (curlint == NULL) { + statusbar(_("No lint to view.")); + return 0; + } + + if (stat(curlint->filename, &lintfileinfo) != -1 && + (openfile->current_stat == NULL || + openfile->current_stat->st_ino != lintfileinfo.st_ino)) { +#ifdef ENABLE_MULTIBUFFER + const openfilestruct *started_at = openfile; + + openfile = openfile->next; + while (openfile != started_at && (openfile->current_stat == NULL || + openfile->current_stat->st_ino != lintfileinfo.st_ino)) + openfile = openfile->next; + + if (openfile->current_stat == NULL || + openfile->current_stat->st_ino != lintfileinfo.st_ino) { + char *msg = charalloc(1024 + strlen(curlint->filename)); + int i; + + sprintf(msg, _("This message is for unopened file %s," + " open it in a new buffer?"), curlint->filename); + i = do_yesno_prompt(FALSE, msg); + currmenu = MLINTER; + free(msg); + + if (i == -1) { + statusbar(_("Cancelled")); + return 1; + } else if (i == 1) { + open_buffer(curlint->filename, TRUE); + } else { +#endif + char *dontwantfile = mallocstrcpy(NULL, curlint->filename); + lintstruct *restlint = NULL; + + while (curlint != NULL) { + if (strcmp(curlint->filename, dontwantfile) == 0) { + if (curlint == lints) + lints = curlint->next; + else + curlint->prev->next = curlint->next; + if (curlint->next != NULL) + curlint->next->prev = curlint->prev; + tmplint = curlint; + curlint = curlint->next; + free(tmplint->msg); + free(tmplint->filename); + free(tmplint); + } else { + if (restlint == NULL) + restlint = curlint; + curlint = curlint->next; + } + } + + free(dontwantfile); + + if (restlint == NULL) { + statusbar(_("No messages for this file")); + return 1; + } else { + curlint = restlint; + return 2; + } +#ifdef ENABLE_MULTIBUFFER + } + } +#endif + } + + if (tmplint != curlint) { + goto_line_posx(curlint->lineno, curlint->colno - 1); + titlebar(NULL); + adjust_viewport(CENTERING); +#ifdef ENABLE_LINENUMBERS + confirm_margin(); +#endif + edit_refresh(); + statusline(NOTICE, curlint->msg); + bottombars(MLINTER); + } + + /* Place the cursor to indicate the affected line. */ + place_the_cursor(); + wnoutrefresh(edit); + tmplint = curlint; + return 0; +} + +void goto_prev_lint(void) +{ + static time_t last_wait = 0; + if (curlint == NULL) { + statusbar(_("No lint to view.")); + return; + } + + if (curlint->prev != NULL) + curlint = curlint->prev; + else if (last_wait != time(NULL)) { + statusbar(_("At first message")); + napms(600); + last_wait = time(NULL); + statusline(NOTICE, curlint->msg); + } +} + +void goto_next_lint(void) +{ + static time_t last_wait = 0; + if (curlint == NULL) { + statusbar(_("No lint to view.")); + return; + } + + if (curlint->next != NULL) + curlint = curlint->next; + else if (last_wait != time(NULL)) { + statusbar(_("At last message")); + napms(600); + last_wait = time(NULL); + statusline(NOTICE, curlint->msg); + } +} + +/* Go to next lint. */ +void next_lint(void) +{ + lintstruct *was_curlint = curlint; + goto_next_lint(); + if(display_lint() != 0) + curlint = was_curlint; +} + +/* Go to previous lint. */ +void prev_lint(void) +{ + lintstruct *was_curlint = curlint; + goto_prev_lint(); + if(display_lint() != 0) + curlint = was_curlint; +} + /* Run a linting program on the current buffer. Return NULL for normal * termination, and the error string otherwise. */ void do_linter(void) @@ -2825,8 +2981,16 @@ void do_linter(void) pid_t pid_lint; bool helpless = ISSET(NO_HELP); static char **lintargs = NULL; - lintstruct *lints = NULL, *tmplint = NULL, *curlint = NULL; - time_t last_wait = 0; + + for (curlint = lints; curlint != NULL;) { + tmplint = curlint; + curlint = curlint->next; + free(tmplint->msg); + free(tmplint->filename); + free(tmplint); + } + curlint = NULL; + lints = NULL; if (ISSET(RESTRICTED)) { show_restricted_warning(); @@ -3013,90 +3177,14 @@ void do_linter(void) while (TRUE) { int kbinput; functionptrtype func; - struct stat lintfileinfo; - - if (stat(curlint->filename, &lintfileinfo) != -1 && - (openfile->current_stat == NULL || - openfile->current_stat->st_ino != lintfileinfo.st_ino)) { -#ifdef ENABLE_MULTIBUFFER - const openfilestruct *started_at = openfile; - - openfile = openfile->next; - while (openfile != started_at && (openfile->current_stat == NULL || - openfile->current_stat->st_ino != lintfileinfo.st_ino)) - openfile = openfile->next; - - if (openfile->current_stat == NULL || - openfile->current_stat->st_ino != lintfileinfo.st_ino) { - char *msg = charalloc(1024 + strlen(curlint->filename)); - int i; - - sprintf(msg, _("This message is for unopened file %s," - " open it in a new buffer?"), curlint->filename); - i = do_yesno_prompt(FALSE, msg); - currmenu = MLINTER; - free(msg); - - if (i == -1) { - statusbar(_("Cancelled")); - break; - } else if (i == 1) { - open_buffer(curlint->filename, TRUE); - } else { -#endif - char *dontwantfile = mallocstrcpy(NULL, curlint->filename); - lintstruct *restlint = NULL; - - while (curlint != NULL) { - if (strcmp(curlint->filename, dontwantfile) == 0) { - if (curlint == lints) - lints = curlint->next; - else - curlint->prev->next = curlint->next; - if (curlint->next != NULL) - curlint->next->prev = curlint->prev; - tmplint = curlint; - curlint = curlint->next; - free(tmplint->msg); - free(tmplint->filename); - free(tmplint); - } else { - if (restlint == NULL) - restlint = curlint; - curlint = curlint->next; - } - } - free(dontwantfile); + int display_ret = display_lint(); - if (restlint == NULL) { - statusbar(_("No messages for this file")); - break; - } else { - curlint = restlint; - continue; - } -#ifdef ENABLE_MULTIBUFFER - } - } -#endif - } - - if (tmplint != curlint) { - goto_line_posx(curlint->lineno, curlint->colno - 1); - titlebar(NULL); - adjust_viewport(CENTERING); -#ifdef ENABLE_LINENUMBERS - confirm_margin(); -#endif - edit_refresh(); - statusline(NOTICE, curlint->msg); - bottombars(MLINTER); - } + if (display_ret == 1) + break; - /* Place the cursor to indicate the affected line. */ - place_the_cursor(); - wnoutrefresh(edit); + if (display_ret == 2) + continue; kbinput = get_kbinput(bottomwin, VISIBLE); @@ -3105,7 +3193,6 @@ void do_linter(void) continue; #endif func = func_from_key(&kbinput); - tmplint = curlint; if (func == do_cancel || func == do_enter) { wipe_statusbar(); @@ -3114,34 +3201,12 @@ void do_linter(void) tmplint = NULL; do_help_void(); } else if (func == do_page_up || func == do_prev_block) { - if (curlint->prev != NULL) - curlint = curlint->prev; - else if (last_wait != time(NULL)) { - statusbar(_("At first message")); - napms(600); - last_wait = time(NULL); - statusline(NOTICE, curlint->msg); - } + goto_prev_lint(); } else if (func == do_page_down || func == do_next_block) { - if (curlint->next != NULL) - curlint = curlint->next; - else if (last_wait != time(NULL)) { - statusbar(_("At last message")); - napms(600); - last_wait = time(NULL); - statusline(NOTICE, curlint->msg); - } + goto_next_lint(); } } - for (curlint = lints; curlint != NULL;) { - tmplint = curlint; - curlint = curlint->next; - free(tmplint->msg); - free(tmplint->filename); - free(tmplint); - } - if (helpless) { SET(NO_HELP); window_init(); -- 2.11.0