diff options
author | rafa_99 <raroma09@gmail.com> | 2021-09-24 18:39:25 +0100 |
---|---|---|
committer | rafa_99 <raroma09@gmail.com> | 2021-09-24 18:39:25 +0100 |
commit | 7947b3823de36feb13036ac282240a2c954337eb (patch) | |
tree | 7bfca0eb244ed7fc2abbcd9515d62115170080dd /src | |
parent | 837ff3653c1d1ef51b7981fa75e1176bda5291a8 (diff) |
Removed History and Last Opened History
Diffstat (limited to 'src')
-rw-r--r-- | src/autocmd.c | 4 | ||||
-rw-r--r-- | src/command.c | 6 | ||||
-rw-r--r-- | src/ex.c | 129 | ||||
-rw-r--r-- | src/ex.h | 2 | ||||
-rw-r--r-- | src/history.c | 278 | ||||
-rw-r--r-- | src/history.h | 40 | ||||
-rw-r--r-- | src/main.c | 19 | ||||
-rw-r--r-- | src/main.h | 8 | ||||
-rw-r--r-- | src/normal.c | 7 | ||||
-rw-r--r-- | src/setting.c | 2 |
10 files changed, 11 insertions, 484 deletions
diff --git a/src/autocmd.c b/src/autocmd.c index 860a92f..4f4aa5f 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -275,10 +275,6 @@ gboolean autocmd_run(Client *c, AuEvent event, const char *uri, const char *grou if (uri && !util_wildmatch(cmd->pattern, uri)) { continue; } - /* run the command */ - /* TODO shoult the result be tested for RESULT_COMPLETE? */ - /* run command and make sure it's not writte to command history */ - ex_run_string(c, cmd->excmd, false); } } diff --git a/src/command.c b/src/command.c index bb5b560..614c094 100644 --- a/src/command.c +++ b/src/command.c @@ -29,7 +29,6 @@ #include "bookmark.h" #endif #include "command.h" -#include "history.h" #include "util.h" #include "main.h" @@ -88,11 +87,10 @@ gboolean command_search(Client *c, const Arg *arg, bool commit) direction = c->state.search.direction; } - /* Only committed search strings adjust registers and are recorded in - * history, intermediate strings (while using incsearch) don't. */ + /* Only committed search strings adjust registers + * intermediate strings (while using incsearch) don't. */ if (commit) { if (query) { - history_add(c, HISTORY_SEARCH, query, NULL); vb_register_add(c, '/', query); } else { /* Committed search without string re-searches last string. */ @@ -34,7 +34,6 @@ #include "ex.h" #include "handler.h" #include "hints.h" -#include "history.h" #include "main.h" #include "map.h" #include "setting.h" @@ -122,7 +121,7 @@ static struct { } info = {'\0', PHASE_START}; static void input_activate(Client *c); -static gboolean parse(Client *c, const char **input, ExArg *arg, gboolean *nohist); +static gboolean parse(Client *c, const char **input, ExArg *arg); static gboolean parse_count(const char **input, ExArg *arg); static gboolean parse_command_name(Client *c, const char **input, ExArg *arg); static gboolean parse_bang(const char **input, ExArg *arg); @@ -160,8 +159,6 @@ static VbCmdResult ex_handlers(Client *c, const ExArg *arg); static gboolean complete(Client *c, short direction); static void completion_select(Client *c, char *match); -static gboolean history(Client *c, gboolean prev); -static void history_rewind(void); /* The order of following command names is significant. If there exists * ambiguous commands matching to the users input, the first defined will be @@ -218,12 +215,6 @@ static struct { char *token; /* initial filter content */ } excomp; -static struct { - char *prefix; /* prefix that is prepended to the history item to for the complete command */ - char *query; /* part of input text to match the history items */ - GList *active; -} exhist; - extern struct Vimb vb; /** @@ -296,16 +287,6 @@ VbResult ex_keypress(Client *c, int key) complete(c, -1); break; - case KEY_UP: /* fall through */ - case CTRL('P'): - history(c, TRUE); - break; - - case KEY_DOWN: /* fall through */ - case CTRL('N'): - history(c, FALSE); - break; - case KEY_CR: input_activate(c); break; @@ -484,7 +465,7 @@ VbCmdResult ex_run_file(Client *c, const char *filename) if (*line == '#' || !*line) { continue; } - if ((ex_run_string(c, line, FALSE) & ~CMD_KEEPINPUT) == CMD_ERROR) { + if ((ex_run_string(c, line) & ~CMD_KEEPINPUT) == CMD_ERROR) { res = CMD_ERROR | CMD_KEEPINPUT; g_warning("Invalid command in %s: '%s'", filename, line); } @@ -494,27 +475,20 @@ VbCmdResult ex_run_file(Client *c, const char *filename) return res; } -VbCmdResult ex_run_string(Client *c, const char *input, gboolean enable_history) +VbCmdResult ex_run_string(Client *c, const char *input) { - /* copy to have original command for history */ const char *in = input; - gboolean nohist = FALSE; VbCmdResult res = CMD_ERROR | CMD_KEEPINPUT; ExArg *arg = g_slice_new0(ExArg); arg->lhs = g_string_new(""); arg->rhs = g_string_new(""); while (in && *in) { - if (!parse(c, &in, arg, &nohist) || !(res = execute(c, arg))) { + if (!parse(c, &in, arg) || !(res = execute(c, arg))) { break; } } - if (enable_history && !nohist) { - history_add(c, HISTORY_COMMAND, input, NULL); - vb_register_add(c, ':', input); - } - free_cmdarg(arg); return res; @@ -548,7 +522,7 @@ static void input_activate(Client *c) case ':': vb_enter(c, 'n'); - res = ex_run_string(c, cmd, TRUE); + res = ex_run_string(c, cmd); if (!(res & CMD_KEEPINPUT)) { /* clear input on success if this is not explicit ommited */ vb_input_set_text(c, ""); @@ -562,7 +536,7 @@ static void input_activate(Client *c) /** * Parses given input string into given ExArg pointer. */ -static gboolean parse(Client *c, const char **input, ExArg *arg, gboolean *nohist) +static gboolean parse(Client *c, const char **input, ExArg *arg) { if (!*input || !**input) { return FALSE; @@ -575,9 +549,6 @@ static gboolean parse(Client *c, const char **input, ExArg *arg, gboolean *nohis /* remove leading whitespace and : */ while (**input && (**input == ':' || VB_IS_SPACE(**input))) { (*input)++; - /* Command started with additional ':' or whitespce - don't record it - * in history or registry. */ - *nohist = TRUE; } parse_count(input, arg); @@ -1304,8 +1275,6 @@ static gboolean complete(Client *c, short direction) sort = FALSE; if (*token == '!') { found = bookmark_fill_completion(store, token + 1); - } else { - found = history_fill_completion(store, HISTORY_URL, token); } break; @@ -1365,13 +1334,6 @@ static gboolean complete(Client *c, short direction) } } free_cmdarg(arg); - } else if (*in == '/' || *in == '?') { - if (history_fill_completion(store, HISTORY_SEARCH, in + 1)) { - OVERWRITE_STRING(excomp.token, in + 1); - OVERWRITE_NSTRING(excomp.prefix, in, 1); - found = TRUE; - sort = FALSE; - } } /* if the input could be parsed and the tree view could be filled */ @@ -1405,82 +1367,3 @@ static void completion_select(Client *c, char *match) } vb_input_set_text(c, excomp.current); } - -static gboolean history(Client *c, gboolean prev) -{ - char *input; - GList *new = NULL; - - input = vb_input_get_text(c); - if (exhist.active) { - /* calculate the actual content of the inpubox from history data, if - * the theoretical content and the actual given input are different - * rewind the history to recreate it later new */ - char *current = g_strconcat(exhist.prefix, (char*)exhist.active->data, NULL); - if (strcmp(input, current)) { - history_rewind(); - } - g_free(current); - } - - /* create the history list if the lookup is started or input was changed */ - if (!exhist.active) { - int type; - char prefix[2] = {0}; - const char *in = (const char*)input; - - skip_whitespace(&in); - - /* save the first char as prefix - this should be : / or ? */ - prefix[0] = *in; - - /* check which type of history we should use */ - if (*in == ':') { - type = INPUT_COMMAND; - } else if (*in == '/' || *in == '?') { - /* the history does not distinguish between forward and backward - * search, so we don't need the backward search here too */ - type = INPUT_SEARCH_FORWARD; - } else { - goto failed; - } - - exhist.active = history_get_list(type, in + 1); - if (!exhist.active) { - goto failed; - } - OVERWRITE_STRING(exhist.prefix, prefix); - } - - if (prev) { - if ((new = g_list_next(exhist.active))) { - exhist.active = new; - } - } else if ((new = g_list_previous(exhist.active))) { - exhist.active = new; - } - - if (!exhist.active) { - goto failed; - } - - vb_echo_force(c, MSG_NORMAL, FALSE, "%s%s", exhist.prefix, (char*)exhist.active->data); - - g_free(input); - return TRUE; - -failed: - g_free(input); - return FALSE; -} - -static void history_rewind(void) -{ - if (exhist.active) { - /* free temporary used history list */ - g_list_free_full(exhist.active, (GDestroyNotify)g_free); - exhist.active = NULL; - - OVERWRITE_STRING(exhist.prefix, NULL); - } -} @@ -29,6 +29,6 @@ VbResult ex_keypress(Client *c, int key); void ex_input_changed(Client *c, const char *text); gboolean ex_fill_completion(GtkListStore *store, const char *input); VbCmdResult ex_run_file(Client *c, const char *filename); -VbCmdResult ex_run_string(Client *c, const char *input, gboolean enable_history); +VbCmdResult ex_run_string(Client *c, const char *input); #endif /* end of include guard: _EX_H */ diff --git a/src/history.c b/src/history.c deleted file mode 100644 index 250333b..0000000 --- a/src/history.c +++ /dev/null @@ -1,278 +0,0 @@ -/** - * vimb - a webkit based vim like browser. - * - * Copyright (C) 2012-2018 Daniel Carl - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. - */ - -#include <fcntl.h> -#include <glib.h> -#include <sys/file.h> - -#include "ascii.h" -#include "completion.h" -#include "config.h" -#include "history.h" -#include "main.h" -#include "util.h" -#include "file-storage.h" - -#define HIST_STORAGE(t) (vb.storage[storage_map[t]]) -typedef struct { - char *first; - char *second; -} History; - -static gboolean history_item_contains_all_tags(History *item, char **query, guint qlen); -static void free_history(History *item); -static History *line_to_history(const char *uri, const char *title); -static GList *load(FileStorage *s); -static void write_to_file(GList *list, const char *file); - -/* map history types to files */ -static const int storage_map[HISTORY_LAST] = { - STORAGE_COMMAND, - STORAGE_SEARCH, - STORAGE_HISTORY -}; -extern struct Vimb vb; - -/** - * Write a new history entry to the end of history file. - */ -void history_add(Client *c, HistoryType type, const char *value, const char *additional) -{ - FileStorage *s; - - /* Don't write a history entry if the history max size is set to 0. */ - if (!vb.config.history_max) { - return; - } - - s = HIST_STORAGE(type); - if (additional) { - file_storage_append(s, "%s\t%s\n", value, additional); - } else { - file_storage_append(s, "%s\n", value); - } -} - -/** - * Makes all history items unique and force them to fit the maximum history - * size and writes all entries of the different history types to file. - */ -void history_cleanup(void) -{ - FileStorage *s; - GList *list; - - /* don't cleanup the history file if history max size is 0 */ - if (!vb.config.history_max) { - return; - } - - for (HistoryType i = HISTORY_FIRST; i < HISTORY_LAST; i++) { - s = HIST_STORAGE(i); - if (!file_storage_is_readonly(s)) { - list = load(s); - write_to_file(list, file_storage_get_path(s)); - g_list_free_full(list, (GDestroyNotify)free_history); - } - } -} - -gboolean history_fill_completion(GtkListStore *store, HistoryType type, const char *input) -{ - char **parts; - unsigned int len; - gboolean found = FALSE; - GList *src = NULL; - GtkTreeIter iter; - History *item; - - src = load(HIST_STORAGE(type)); - src = g_list_reverse(src); - if (!input || !*input) { - /* without any tags return all items */ - for (GList *l = src; l; l = l->next) { - item = l->data; - gtk_list_store_append(store, &iter); - gtk_list_store_set( - store, &iter, - COMPLETION_STORE_FIRST, item->first, -#ifdef FEATURE_TITLE_IN_COMPLETION - COMPLETION_STORE_SECOND, item->second, -#endif - -1 - ); - found = TRUE; - } - } else if (HISTORY_URL == type) { - parts = g_strsplit(input, " ", 0); - len = g_strv_length(parts); - - for (GList *l = src; l; l = l->next) { - item = l->data; - if (history_item_contains_all_tags(item, parts, len)) { - gtk_list_store_append(store, &iter); - gtk_list_store_set( - store, &iter, - COMPLETION_STORE_FIRST, item->first, -#ifdef FEATURE_TITLE_IN_COMPLETION - COMPLETION_STORE_SECOND, item->second, -#endif - -1 - ); - found = TRUE; - } - } - g_strfreev(parts); - } else { - for (GList *l = src; l; l = l->next) { - item = l->data; - if (g_str_has_prefix(item->first, input)) { - gtk_list_store_append(store, &iter); - gtk_list_store_set( - store, &iter, - COMPLETION_STORE_FIRST, item->first, -#ifdef FEATURE_TITLE_IN_COMPLETION - COMPLETION_STORE_SECOND, item->second, -#endif - -1 - ); - found = TRUE; - } - } - } - g_list_free_full(src, (GDestroyNotify)free_history); - - return found; -} - -/** - * Retrieves the list of matching history items. - * The list must be freed. - */ -GList *history_get_list(VbInputType type, const char *query) -{ - GList *result = NULL, *src = NULL; - - switch (type) { - case INPUT_COMMAND: - src = load(HIST_STORAGE(HISTORY_COMMAND)); - break; - - case INPUT_SEARCH_FORWARD: - case INPUT_SEARCH_BACKWARD: - src = load(HIST_STORAGE(HISTORY_SEARCH)); - break; - - default: - return NULL; - } - - /* generate new history list with the matching items */ - for (GList *l = src; l; l = l->next) { - History *item = l->data; - if (g_str_has_prefix(item->first, query)) { - result = g_list_prepend(result, g_strdup(item->first)); - } - } - g_list_free_full(src, (GDestroyNotify)free_history); - - /* Prepend the original query as own item like done in vim to have the - * original input string in input box if we step before the first real - * item. */ - result = g_list_prepend(result, g_strdup(query)); - - return result; -} - -/** - * Checks if the given array of tags are all found in history item. - */ -static gboolean history_item_contains_all_tags(History *item, char **query, guint qlen) -{ - unsigned int i; - if (!qlen) { - return TRUE; - } - - /* iterate over all query parts */ - for (i = 0; i < qlen; i++) { - if (!(util_strcasestr(item->first, query[i]) - || (item->second && util_strcasestr(item->second, query[i]))) - ) { - return FALSE; - } - } - - return TRUE; -} - -static void free_history(History *item) -{ - g_free(item->first); - g_free(item->second); - g_slice_free(History, item); -} - -static History *line_to_history(const char *uri, const char *title) -{ - History *item = g_slice_new0(History); - - item->first = g_strdup(uri); - item->second = g_strdup(title); - - return item; -} - -/** - * Loads history items form file but eliminate duplicates in FIFO order. - * - * Returned list must be freed with (GDestroyNotify)free_history. - */ -static GList *load(FileStorage *s) -{ - return util_strv_to_unique_list( - file_storage_get_lines(s), - (Util_Content_Func)line_to_history, - vb.config.history_max - ); -} - -/** - * Loads the entries from file, make them unique and write them back to file. - */ -static void write_to_file(GList *list, const char *file) -{ - FILE *f; - if ((f = fopen(file, "w"))) { - flock(fileno(f), LOCK_EX); - - /* overwrite the history file with new unique history items */ - for (GList *link = list; link; link = link->next) { - History *item = link->data; - if (item->second) { - fprintf(f, "%s\t%s\n", item->first, item->second); - } else { - fprintf(f, "%s\n", item->first); - } - } - - flock(fileno(f), LOCK_UN); - fclose(f); - } -} diff --git a/src/history.h b/src/history.h deleted file mode 100644 index 688bbb2..0000000 --- a/src/history.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * vimb - a webkit based vim like browser. - * - * Copyright (C) 2012-2018 Daniel Carl - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. - */ - -#ifndef _HISTORY_H -#define _HISTORY_H - -#include <glib.h> - -#include "main.h" - -typedef enum { - HISTORY_FIRST = 0, - HISTORY_COMMAND = 0, - HISTORY_SEARCH, - HISTORY_URL, - HISTORY_LAST -} HistoryType; - -void history_add(Client *c, HistoryType type, const char *value, const char *additional); -void history_cleanup(void); -gboolean history_fill_completion(GtkListStore *store, HistoryType type, const char *input); -GList *history_get_list(VbInputType type, const char *query); - -#endif /* end of include guard: _HISTORY_H */ @@ -38,7 +38,6 @@ #include "ex.h" #include "ext-proxy.h" #include "handler.h" -#include "history.h" #include "input.h" #include "js.h" #include "main.h" @@ -689,14 +688,6 @@ static void client_destroy(Client *c) Client *p; webkit_web_view_stop_loading(c->webview); - /* Write last URL into file for recreation. - * The URL is only stored if the closed-max-items is not 0 and the file - * exists. */ - if (c->state.uri && vb.config.closed_max && vb.files[FILES_CLOSED]) { - util_file_prepend_line(vb.files[FILES_CLOSED], c->state.uri, - vb.config.closed_max); - } - gtk_widget_destroy(c->window); /* Look for the client in the list, if we searched through the list and @@ -1538,9 +1529,6 @@ static void on_webview_load_changed(WebKitWebView *webview, autocmd_run(c, AU_LOAD_FINISHED, raw_uri, NULL); #endif c->state.progress = 100; - if (uri && strncmp(uri, "about:", 6)) { - history_add(c, HISTORY_URL, uri, webkit_web_view_get_title(webview)); - } break; } @@ -1768,7 +1756,7 @@ static void update_title(Client *c) /** * Update the contents of the url bar on the left of the statu bar according - * to current opened url and position in back forward history. + * to current opened url and position. */ static void update_urlbar(Client *c) { @@ -1783,7 +1771,6 @@ static void update_urlbar(Client *c) g_string_append_printf(str, "%s", c->state.uri); - /* show history indicator only if there is something to show */ back = webkit_web_view_can_go_back(c->webview); fwd = webkit_web_view_can_go_forward(c->webview); if (back || fwd) { @@ -1848,13 +1835,11 @@ static void vimb_setup(void) /* Prepare files in XDG_DATA_HOME */ dataPath = util_get_data_dir(); if (!vb.incognito) { - vb.files[FILES_CLOSED] = g_build_filename(dataPath, "closed", NULL); vb.files[FILES_COOKIE] = g_build_filename(dataPath, "cookies.db", NULL); } vb.files[FILES_BOOKMARK] = g_build_filename(dataPath, "bookmark", NULL); vb.files[FILES_QUEUE] = g_build_filename(dataPath, "queue", NULL); - vb.storage[STORAGE_HISTORY] = file_storage_new(dataPath, "history", vb.incognito); vb.storage[STORAGE_COMMAND] = file_storage_new(dataPath, "command", vb.incognito); vb.storage[STORAGE_SEARCH] = file_storage_new(dataPath, "search", vb.incognito); g_free(dataPath); @@ -2250,7 +2235,7 @@ int main(int argc, char* argv[]) /* process the --cmd if this was given */ for (GSList *l = vb.cmdargs; l; l = l->next) { - ex_run_string(c, l->data, false); + ex_run_string(c, l->data); } if (argc <= 1) { vb_load_uri(c, &(Arg){TARGET_CURRENT, NULL}); @@ -66,7 +66,6 @@ #define REG_CHARS "\"" USER_REG ":%/;" #define REG_SIZE (sizeof(REG_CHARS) - 1) -#define FILE_CLOSED "closed" #define FILE_COOKIES "cookies" enum { TARGET_CURRENT, TARGET_RELATED, TARGET_NEW }; @@ -107,7 +106,6 @@ typedef enum { enum { FILES_BOOKMARK, - FILES_CLOSED, FILES_CONFIG, FILES_COOKIE, FILES_QUEUE, @@ -117,10 +115,8 @@ enum { }; enum { - STORAGE_CLOSED, STORAGE_COMMAND, STORAGE_CONFIG, - STORAGE_HISTORY, STORAGE_SEARCH, STORAGE_LAST }; @@ -283,10 +279,6 @@ struct Vimb { FileStorage *storage[STORAGE_LAST]; char *profile; /* profile name */ GSList *cmdargs; /* ex commands given asl --command, -C option */ - struct { - guint history_max; - guint closed_max; - } config; GtkCssProvider *style_provider; gboolean no_maximize; gboolean incognito; diff --git a/src/normal.c b/src/normal.c index 1cf6364..a2da1ad 100644 --- a/src/normal.c +++ b/src/normal.c @@ -654,15 +654,8 @@ static VbResult normal_open_clipboard(Client *c, const NormalCmdInfo *info) static VbResult normal_open(Client *c, const NormalCmdInfo *info) { Arg a; - if (!vb.files[FILES_CLOSED]) { - return RESULT_ERROR; - } a.i = info->key == 'U' ? TARGET_NEW : TARGET_CURRENT; - a.s = util_file_pop_line(vb.files[FILES_CLOSED], NULL); - if (!a.s) { - return RESULT_ERROR; - } vb_load_uri(c, &a); g_free(a.s); diff --git a/src/setting.c b/src/setting.c index ab61eaf..43cfe46 100644 --- a/src/setting.c +++ b/src/setting.c @@ -149,7 +149,6 @@ void setting_init(Client *c) setting_add(c, "home-page", TYPE_CHAR, &SETTING_HOME_PAGE, NULL, 0, NULL); i = 2000; /* TODO should be global and not overwritten by a new client */ - setting_add(c, "history-max-items", TYPE_INTEGER, &i, internal, 0, &vb.config.history_max); setting_add(c, "editor-command", TYPE_CHAR, &"x-terminal-emulator -e -vi '%s'", NULL, 0, NULL); setting_add(c, "strict-ssl", TYPE_BOOLEAN, &on, tls_policy, 0, NULL); setting_add(c, "status-bar", TYPE_BOOLEAN, &on, statusbar, 0, NULL); @@ -166,7 +165,6 @@ void setting_init(Client *c) setting_add(c, "incsearch", TYPE_BOOLEAN, &off, internal, 0, &c->config.incsearch); i = 10; /* TODO should be global and not overwritten by a new client */ - setting_add(c, "closed-max-items", TYPE_INTEGER, &i, internal, 0, &vb.config.closed_max); setting_add(c, "x-hint-command", TYPE_CHAR, &":o <C-R>;", NULL, 0, NULL); setting_add(c, "spell-checking", TYPE_BOOLEAN, &off, webkit_spell_checking, 0, NULL); setting_add(c, "spell-checking-languages", TYPE_CHAR, &"en_US", webkit_spell_checking_language, FLAG_LIST|FLAG_NODUP, NULL); |