From a566e529522940f011aa1fa08d44753b6bea9562 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Wed, 3 Feb 2021 16:48:04 -0500 Subject: change cwd to directory of last buffer --- keywords.h | 6 +++--- keywords.py | 9 ++++++--- main.c | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) mode change 100644 => 100755 keywords.py diff --git a/keywords.h b/keywords.h index 77291bd..56417c4 100644 --- a/keywords.h +++ b/keywords.h @@ -134,18 +134,18 @@ static Keyword const syntax_keywords_python_B[6] = {{"BaseException", SYNTAX_BUI static Keyword const syntax_keywords_python_C[6] = {{"ChildProcessError", SYNTAX_BUILTIN},{"ConnectionAbortedError", SYNTAX_BUILTIN},{"ConnectionError", SYNTAX_BUILTIN},{"ConnectionRefusedError", SYNTAX_BUILTIN},{"ConnectionResetError", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_D[2] = {{"DeprecationWarning", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_E[5] = {{"EOFError", SYNTAX_BUILTIN},{"Ellipsis", SYNTAX_BUILTIN},{"EnvironmentError", SYNTAX_BUILTIN},{"Exception", SYNTAX_BUILTIN}}; -static Keyword const syntax_keywords_python_F[7] = {{"False", SYNTAX_CONSTANT},{"False", SYNTAX_BUILTIN},{"FileExistsError", SYNTAX_BUILTIN},{"FileNotFoundError", SYNTAX_BUILTIN},{"FloatingPointError", SYNTAX_BUILTIN},{"FutureWarning", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_python_F[6] = {{"False", SYNTAX_BUILTIN},{"FileExistsError", SYNTAX_BUILTIN},{"FileNotFoundError", SYNTAX_BUILTIN},{"FloatingPointError", SYNTAX_BUILTIN},{"FutureWarning", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_G[2] = {{"GeneratorExit", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_I[8] = {{"IOError", SYNTAX_BUILTIN},{"ImportError", SYNTAX_BUILTIN},{"ImportWarning", SYNTAX_BUILTIN},{"IndentationError", SYNTAX_BUILTIN},{"IndexError", SYNTAX_BUILTIN},{"InterruptedError", SYNTAX_BUILTIN},{"IsADirectoryError", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_K[3] = {{"KeyError", SYNTAX_BUILTIN},{"KeyboardInterrupt", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_L[2] = {{"LookupError", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_M[3] = {{"MemoryError", SYNTAX_BUILTIN},{"ModuleNotFoundError", SYNTAX_BUILTIN}}; -static Keyword const syntax_keywords_python_N[7] = {{"None", SYNTAX_CONSTANT},{"NameError", SYNTAX_BUILTIN},{"None", SYNTAX_BUILTIN},{"NotADirectoryError", SYNTAX_BUILTIN},{"NotImplemented", SYNTAX_BUILTIN},{"NotImplementedError", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_python_N[6] = {{"NameError", SYNTAX_BUILTIN},{"None", SYNTAX_BUILTIN},{"NotADirectoryError", SYNTAX_BUILTIN},{"NotImplemented", SYNTAX_BUILTIN},{"NotImplementedError", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_O[3] = {{"OSError", SYNTAX_BUILTIN},{"OverflowError", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_P[4] = {{"PendingDeprecationWarning", SYNTAX_BUILTIN},{"PermissionError", SYNTAX_BUILTIN},{"ProcessLookupError", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_R[6] = {{"RecursionError", SYNTAX_BUILTIN},{"ReferenceError", SYNTAX_BUILTIN},{"ResourceWarning", SYNTAX_BUILTIN},{"RuntimeError", SYNTAX_BUILTIN},{"RuntimeWarning", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_S[7] = {{"StopAsyncIteration", SYNTAX_BUILTIN},{"StopIteration", SYNTAX_BUILTIN},{"SyntaxError", SYNTAX_BUILTIN},{"SyntaxWarning", SYNTAX_BUILTIN},{"SystemError", SYNTAX_BUILTIN},{"SystemExit", SYNTAX_BUILTIN}}; -static Keyword const syntax_keywords_python_T[6] = {{"True", SYNTAX_CONSTANT},{"TabError", SYNTAX_BUILTIN},{"TimeoutError", SYNTAX_BUILTIN},{"True", SYNTAX_BUILTIN},{"TypeError", SYNTAX_BUILTIN}}; +static Keyword const syntax_keywords_python_T[5] = {{"TabError", SYNTAX_BUILTIN},{"TimeoutError", SYNTAX_BUILTIN},{"True", SYNTAX_BUILTIN},{"TypeError", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_U[8] = {{"UnboundLocalError", SYNTAX_BUILTIN},{"UnicodeDecodeError", SYNTAX_BUILTIN},{"UnicodeEncodeError", SYNTAX_BUILTIN},{"UnicodeError", SYNTAX_BUILTIN},{"UnicodeTranslateError", SYNTAX_BUILTIN},{"UnicodeWarning", SYNTAX_BUILTIN},{"UserWarning", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_V[2] = {{"ValueError", SYNTAX_BUILTIN}}; static Keyword const syntax_keywords_python_W[3] = {{"Warning", SYNTAX_BUILTIN},{"WindowsError", SYNTAX_BUILTIN}}; diff --git a/keywords.py b/keywords.py old mode 100644 new mode 100755 index 199912f..cbe704e --- a/keywords.py +++ b/keywords.py @@ -1,3 +1,4 @@ +#!/usr/bin/python3 import ast types = [ @@ -153,7 +154,9 @@ keywords_cpp = [ def cant_overlap(*args): for i in range(len(args)): for j in range(i): - assert not set(args[i]).intersection(args[j]) + intersection = set(args[i]).intersection(args[j]) + if intersection: + raise ValueError("Argument {} intersects with {}: {}".format(i, j, intersection)) cant_overlap(keywords_c, keywords_cpp) keywords_rust = [ @@ -186,7 +189,6 @@ constants_rust = ['false', 'true'] -constants_python = ['False', 'None', 'True'] keywords_python = ['await', 'else', 'import', 'pass', 'break', 'except', 'in', 'raise', 'class', 'finally', 'is', 'return', 'and', 'continue', 'for', 'lambda', 'try', 'as', 'def', 'from', 'nonlocal', 'while', 'assert', 'del', 'global', 'not', 'with', 'async', 'elif', 'if', 'or', 'yield', @@ -225,6 +227,7 @@ def label(kwds, l): cant_overlap(keywords_c, constants_c, builtins_c) cant_overlap(keywords_rust, builtins_rust, constants_rust) +cant_overlap(keywords_python, builtins_python) c_things = label(keywords_c, SYNTAX_KEYWORD) + label(constants_c, SYNTAX_CONSTANT) + label(builtins_c, SYNTAX_BUILTIN) output_keywords(file, c_things, 'c') cpp_things = c_things + label(keywords_cpp, SYNTAX_KEYWORD) @@ -232,5 +235,5 @@ cpp_things.remove((SYNTAX_BUILTIN, 'bool')) cpp_things.remove((SYNTAX_BUILTIN, 'wchar_t')) output_keywords(file, cpp_things, 'cpp') output_keywords(file, label(keywords_rust, SYNTAX_KEYWORD) + label(builtins_rust, SYNTAX_BUILTIN) + label(constants_rust, SYNTAX_CONSTANT), 'rust') -output_keywords(file, label(keywords_python, SYNTAX_KEYWORD) + label(builtins_python, SYNTAX_BUILTIN) + label(constants_python, SYNTAX_CONSTANT), 'python') +output_keywords(file, label(keywords_python, SYNTAX_KEYWORD) + label(builtins_python, SYNTAX_BUILTIN), 'python') file.close() diff --git a/main.c b/main.c index 12e9549..894ed85 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,5 @@ // @TODO: +// - ensure buffer->filename never contains / on windows // - split // - Windows installation #include "base.h" @@ -435,6 +436,24 @@ int main(int argc, char **argv) { ted->drag_buffer = NULL; } + { // ted->cwd should be the directory containing the last active buffer + TextBuffer *buffer = ted->active_buffer; + if (buffer) { + char const *buffer_path = buffer_get_filename(buffer); + if (buffer_path && !buffer_is_untitled(buffer)) { + assert(*buffer_path); + char *last_sep = strrchr(buffer_path, PATH_SEPARATOR); + if (last_sep) { + size_t dirname_len = (size_t)(last_sep - buffer_path); + if (dirname_len == 0) dirname_len = 1; // make sure "/x" sets our cwd to "/", not "" + // set cwd to buffer's directory + memcpy(ted->cwd, buffer_path, dirname_len); + ted->cwd[dirname_len] = 0; + } + } + } + } + u32 key_modifier = (u32)ctrl_down << KEY_MODIFIER_CTRL_BIT | (u32)shift_down << KEY_MODIFIER_SHIFT_BIT -- cgit v1.2.3