Transfer all patches to a Git branch.
This commit is contained in:
parent
2a6ba9e18a
commit
00768c45eb
@ -1,63 +0,0 @@
|
|||||||
From 57574a037b4faff9a3f36df12519d2ee4b479824 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Silvan Jegen <s.jegen@gmail.com>
|
|
||||||
Date: Sun, 26 Feb 2017 16:47:12 +0100
|
|
||||||
Subject: [PATCH 1/6] vis: reimplement `gf` and `<C-w>gf` functionality in lua
|
|
||||||
|
|
||||||
The functionality is not exactly identical since both bindings open the
|
|
||||||
file name under the cursor in a new window. The older implementation
|
|
||||||
opened the file in the same window with `gf` and in a new one with
|
|
||||||
`<C-w>gf`.
|
|
||||||
---
|
|
||||||
lua/plugins/open-file-under-cursor.lua | 38 +++++++++++++++++++++++++++++++++
|
|
||||||
lua/vis-std.lua | 2 +
|
|
||||||
2 files changed, 40 insertions(+)
|
|
||||||
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/lua/plugins/open-file-under-cursor.lua
|
|
||||||
@@ -0,0 +1,38 @@
|
|
||||||
+-- open file at primary cursor location
|
|
||||||
+
|
|
||||||
+local lpeg = vis.lpeg
|
|
||||||
+local l = vis.lexers
|
|
||||||
+local dq_str = l.delimited_range('"', true)
|
|
||||||
+local sq_str = l.delimited_range("'", true)
|
|
||||||
+local include = l.delimited_range("<>", true, true, true)
|
|
||||||
+local filename = dq_str + sq_str + include + (1 - lpeg.S('"\'\t\v\f\r()[]{} \n'))^1
|
|
||||||
+
|
|
||||||
+vis:map(vis.modes.NORMAL, "gf", function(keys)
|
|
||||||
+ local mstart, mend = vis.win.file:match_at(filename, vis.win.selection.pos, 200)
|
|
||||||
+ if not mstart or not mend then
|
|
||||||
+ vis:info("No filename found under the cursor.")
|
|
||||||
+ return #keys
|
|
||||||
+ end
|
|
||||||
+ local fnoffstr = vis.win.file:content(mstart, mend-mstart)
|
|
||||||
+ local offsetcmd
|
|
||||||
+ local fn = fnoffstr
|
|
||||||
+ local offset = fnoffstr:find(":")
|
|
||||||
+ if not offset then
|
|
||||||
+ local offset = fnoffstr:find("/")
|
|
||||||
+ end
|
|
||||||
+ if offset then
|
|
||||||
+ offsetcmd = fnoffstr:sub(offset)
|
|
||||||
+ fn = fnoffstr:sub(1, offset-1)
|
|
||||||
+ end
|
|
||||||
+ local ok = vis:command(string.format("open %s", fn))
|
|
||||||
+ if not ok then
|
|
||||||
+ vis:info("Could not open file " .. fn)
|
|
||||||
+ return #keys
|
|
||||||
+ end
|
|
||||||
+ if offsetcmd then
|
|
||||||
+ vis:command(offsetcmd)
|
|
||||||
+ end
|
|
||||||
+ return #keys
|
|
||||||
+end, "Open file under cursor in a new window")
|
|
||||||
+
|
|
||||||
+vis:map(vis.modes.NORMAL, "<C-w>gf", "gf")
|
|
||||||
--- a/lua/vis-std.lua
|
|
||||||
+++ b/lua/vis-std.lua
|
|
||||||
@@ -165,3 +165,5 @@ require('plugins/digraph')
|
|
||||||
require('plugins/number-inc-dec')
|
|
||||||
require('plugins/complete-word')
|
|
||||||
require('plugins/complete-filename')
|
|
||||||
+require('plugins/open-file-under-cursor')
|
|
||||||
+
|
|
@ -1,160 +0,0 @@
|
|||||||
From 207fc803e1ceffb384ef9d0c6b2f2614bc8fdb67 Mon Sep 17 00:00:00 2001
|
|
||||||
From: "David B. Lamkins" <david@lamkins.net>
|
|
||||||
Date: Sun, 1 Oct 2017 10:43:56 -0700
|
|
||||||
Subject: [PATCH] Add vis-highlight command.
|
|
||||||
|
|
||||||
---
|
|
||||||
README.md | 2 +
|
|
||||||
man/vis-highlight.1 | 41 +++++++++++++++++++++++
|
|
||||||
vis-highlight | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
3 files changed, 132 insertions(+)
|
|
||||||
create mode 100644 man/vis-highlight.1
|
|
||||||
create mode 100755 vis-highlight
|
|
||||||
|
|
||||||
--- a/README.md
|
|
||||||
+++ b/README.md
|
|
||||||
@@ -53,6 +53,8 @@ compatible environment as well as:
|
|
||||||
* [Lua](http://www.lua.org/) >= 5.2 (optional)
|
|
||||||
* [LPeg](http://www.inf.puc-rio.br/~roberto/lpeg/) >= 0.12
|
|
||||||
(optional runtime dependency required for syntax highlighting)
|
|
||||||
+ * [lua-term](https://github.com/hoelzro/lua-term) >= 0.07
|
|
||||||
+ (optional runtime dependency required for CLI highlighting using vis-highlight)
|
|
||||||
* [TRE](http://laurikari.net/tre/) (optional for more memory efficient regex search)
|
|
||||||
|
|
||||||
Assuming these dependencies are met, execute:
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/man/vis-highlight.1
|
|
||||||
@@ -0,0 +1,41 @@
|
|
||||||
+.Dd October 1, 2017
|
|
||||||
+.Dt VIS-HIGHLIGHT 1
|
|
||||||
+.Os Vis VERSION
|
|
||||||
+.
|
|
||||||
+.Sh NAME
|
|
||||||
+.Nm vis-highlight
|
|
||||||
+.Nd Highlight files using vis' lexers
|
|
||||||
+.
|
|
||||||
+.Sh SYNOPSIS
|
|
||||||
+.Nm vis-highlight
|
|
||||||
+.Ar lexer
|
|
||||||
+.Ar files
|
|
||||||
+.
|
|
||||||
+.Sh DESCRIPTION
|
|
||||||
+.Nm vis-highlight
|
|
||||||
+applies a vis lexer to highlight one or more files to standard output.
|
|
||||||
+.
|
|
||||||
+.Sh ENVIRONMENT
|
|
||||||
+.
|
|
||||||
+The following environment variables affect the operation of
|
|
||||||
+.Nm vis-highlight :
|
|
||||||
+.
|
|
||||||
+.Bl -tag -width Ev
|
|
||||||
+.It Ev VIS_PATH
|
|
||||||
+The default path to use to load Lua support files.
|
|
||||||
+.El
|
|
||||||
+.
|
|
||||||
+.Sh EXIT STATUS
|
|
||||||
+.Ex -std vis-highlight
|
|
||||||
+.
|
|
||||||
+.Sh EXAMPLES
|
|
||||||
+Highlight the visrc.lua file:
|
|
||||||
+.Bd -literal -offset indent
|
|
||||||
+vis-highlight lua ~/.config/vis/visrc.lua
|
|
||||||
+.Ed
|
|
||||||
+.
|
|
||||||
+.Sh BUGS
|
|
||||||
+An ANSI-compatible terminal is assumed.
|
|
||||||
+.
|
|
||||||
+.Sh SEE ALSO
|
|
||||||
+.Xr vis 1
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/vis-highlight
|
|
||||||
@@ -0,0 +1,89 @@
|
|
||||||
+#! /usr/bin/env lua
|
|
||||||
+
|
|
||||||
+-- Standalone syntax highlighter uses the lexers provided by `vis`.
|
|
||||||
+
|
|
||||||
+if #arg < 2 then
|
|
||||||
+ print('usage: ' .. arg[0] .. ' LEXER-NAME FILE...')
|
|
||||||
+ return 1
|
|
||||||
+end
|
|
||||||
+
|
|
||||||
+vis_path = os.getenv('VIS_PATH')
|
|
||||||
+if vis_path ~= nil then
|
|
||||||
+ package.path = package.path .. ';' .. vis_path .. '/?.lua'
|
|
||||||
+end
|
|
||||||
+package.path = package.path .. ';/usr/local/share/vis/?.lua'
|
|
||||||
+package.path = package.path .. ';/usr/share/vis/?.lua'
|
|
||||||
+
|
|
||||||
+local syntax = arg[1]
|
|
||||||
+local lexers = require('lexer')
|
|
||||||
+local lexer = lexers.load(syntax)
|
|
||||||
+
|
|
||||||
+if not lexer then
|
|
||||||
+ print(string.format('Failed to load lexer: `%s`', syntax))
|
|
||||||
+ return 1
|
|
||||||
+end
|
|
||||||
+
|
|
||||||
+local term = require('term')
|
|
||||||
+local colors = term.colors
|
|
||||||
+
|
|
||||||
+local token_styles = {
|
|
||||||
+ -- bold => bright
|
|
||||||
+ -- italics => underscore
|
|
||||||
+ ['default'] = colors.default .. colors.onblack .. colors.white,
|
|
||||||
+ ['nothing'] = colors.default .. colors.onblack,
|
|
||||||
+ ['class'] = colors.default .. colors.yellow .. colors.bright,
|
|
||||||
+ ['comment'] = colors.default .. colors.blue .. colors.bright,
|
|
||||||
+ ['constant'] = colors.default .. colors.cyan .. colors.bright,
|
|
||||||
+ ['definition'] = colors.default .. colors.blue .. colors.bright,
|
|
||||||
+ ['error'] = colors.default .. colors.red .. colors.underscore,
|
|
||||||
+ ['function'] = colors.default .. colors.blue .. colors.bright,
|
|
||||||
+ ['keyword'] = colors.default .. colors.yellow .. colors.bright,
|
|
||||||
+ ['label'] = colors.default .. colors.green .. colors.bright,
|
|
||||||
+ ['number'] = colors.default .. colors.red .. colors.bright,
|
|
||||||
+ ['operator'] = colors.default .. colors.cyan .. colors.bright,
|
|
||||||
+ ['regex'] = colors.default .. colors.green .. colors.bright,
|
|
||||||
+ ['string'] = colors.default .. colors.red .. colors.bright,
|
|
||||||
+ ['preprocessor'] = colors.default .. colors.magenta .. colors.bright,
|
|
||||||
+ ['tag'] = colors.default .. colors.red .. colors.bright,
|
|
||||||
+ ['type'] = colors.default .. colors.green .. colors.bright,
|
|
||||||
+ ['variable'] = colors.default .. colors.blue .. colors.bright,
|
|
||||||
+ ['whitespace'] = '',
|
|
||||||
+ ['embedded'] = colors.default .. colors.onblue .. colors.bright,
|
|
||||||
+ ['identifier'] = colors.default .. colors.white,
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+for i = 2, #arg do
|
|
||||||
+ local filename = arg[i]
|
|
||||||
+ local file = assert(io.open(filename, 'r'))
|
|
||||||
+ local text = file:read('*all')
|
|
||||||
+ file:close()
|
|
||||||
+ local tokens = lexer:lex(text, 1)
|
|
||||||
+ local token_start = 1
|
|
||||||
+ local last = ''
|
|
||||||
+
|
|
||||||
+ for i = 1, #tokens, 2 do
|
|
||||||
+ local token_end = tokens[i+1] - 1
|
|
||||||
+ local name = tokens[i]
|
|
||||||
+ local style = token_styles[name]
|
|
||||||
+ if style ~= nil then
|
|
||||||
+ -- Whereas the lexer reports all other syntaxes over
|
|
||||||
+ -- the entire span of a token, it reports 'default'
|
|
||||||
+ -- byte-by-byte. We emit only the first 'default' of
|
|
||||||
+ -- a series in order to properly display multibyte
|
|
||||||
+ -- UTF-8 characters.
|
|
||||||
+ if not (last == 'default' and name == 'default') then
|
|
||||||
+ io.write(tostring(style))
|
|
||||||
+ end
|
|
||||||
+ last = name
|
|
||||||
+ end
|
|
||||||
+ local token = text:sub(token_start, token_end)
|
|
||||||
+ if style ~= nil then
|
|
||||||
+ -- Replicate the style after every newline within
|
|
||||||
+ -- the token, because less -R forgets attributes
|
|
||||||
+ -- with each newline.
|
|
||||||
+ token = token:gsub("\n", "\n" .. tostring(style))
|
|
||||||
+ end
|
|
||||||
+ io.write(token)
|
|
||||||
+ token_start = token_end + 1
|
|
||||||
+ end
|
|
||||||
+end
|
|
@ -1,418 +0,0 @@
|
|||||||
---
|
|
||||||
Makefile | 1
|
|
||||||
lua/vis.lua | 2
|
|
||||||
vis-lua.c | 82 +++++++++++++++++++++++++
|
|
||||||
vis-lua.h | 4 -
|
|
||||||
vis-subprocess.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
vis-subprocess.h | 23 +++++++
|
|
||||||
vis.c | 5 +
|
|
||||||
7 files changed, 291 insertions(+), 2 deletions(-)
|
|
||||||
|
|
||||||
--- a/Makefile
|
|
||||||
+++ b/Makefile
|
|
||||||
@@ -26,6 +26,7 @@ SRC = array.c \
|
|
||||||
vis-prompt.c \
|
|
||||||
vis-registers.c \
|
|
||||||
vis-text-objects.c \
|
|
||||||
+ vis-subprocess.c \
|
|
||||||
$(REGEX_SRC)
|
|
||||||
|
|
||||||
ELF = vis vis-menu vis-digraph
|
|
||||||
--- a/lua/vis.lua
|
|
||||||
+++ b/lua/vis.lua
|
|
||||||
@@ -152,6 +152,7 @@ local events = {
|
|
||||||
WIN_OPEN = "Event::WIN_OPEN", -- see @{win_open}
|
|
||||||
WIN_STATUS = "Event::WIN_STATUS", -- see @{win_status}
|
|
||||||
TERM_CSI = "Event::TERM_CSI", -- see @{term_csi}
|
|
||||||
+ PROCESS_RESPONSE = "Event::PROCESS_RESPONSE", -- see @{process_response}
|
|
||||||
}
|
|
||||||
|
|
||||||
events.file_close = function(...) events.emit(events.FILE_CLOSE, ...) end
|
|
||||||
@@ -167,6 +168,7 @@ events.win_highlight = function(...) eve
|
|
||||||
events.win_open = function(...) events.emit(events.WIN_OPEN, ...) end
|
|
||||||
events.win_status = function(...) events.emit(events.WIN_STATUS, ...) end
|
|
||||||
events.term_csi = function(...) events.emit(events.TERM_CSI, ...) end
|
|
||||||
+events.process_response = function(...) events.emit(events.PROCESS_RESPONSE, ...) end
|
|
||||||
|
|
||||||
local handlers = {}
|
|
||||||
|
|
||||||
--- a/vis-lua.c
|
|
||||||
+++ b/vis-lua.c
|
|
||||||
@@ -23,6 +23,7 @@
|
|
||||||
|
|
||||||
#include "vis-lua.h"
|
|
||||||
#include "vis-core.h"
|
|
||||||
+#include "vis-subprocess.h"
|
|
||||||
#include "text-motions.h"
|
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
@@ -52,6 +53,13 @@
|
|
||||||
#define debug(...) do { } while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+typedef struct {
|
|
||||||
+ /* Lua stream structure for the process input stream */
|
|
||||||
+ FILE *f;
|
|
||||||
+ lua_CFunction closef;
|
|
||||||
+ Process *handler;
|
|
||||||
+} ProcessStream;
|
|
||||||
+
|
|
||||||
static void window_status_update(Vis *vis, Win *win) {
|
|
||||||
char left_parts[4][255] = { "", "", "", "" };
|
|
||||||
char right_parts[4][32] = { "", "", "", "" };
|
|
||||||
@@ -162,6 +170,9 @@ void vis_lua_win_close(Vis *vis, Win *wi
|
|
||||||
void vis_lua_win_highlight(Vis *vis, Win *win) { }
|
|
||||||
void vis_lua_win_status(Vis *vis, Win *win) { window_status_update(vis, win); }
|
|
||||||
void vis_lua_term_csi(Vis *vis, const long *csi) { }
|
|
||||||
+void vis_lua_process_response(Vis *vis, const char *name,
|
|
||||||
+ char *buffer, size_t len, ResponseType rtype) { }
|
|
||||||
+
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
@@ -1372,6 +1383,47 @@ static int redraw(lua_State *L) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/***
|
|
||||||
+ * Closes a stream returned by @{Vis.communicate}.
|
|
||||||
+ *
|
|
||||||
+ * @function close
|
|
||||||
+ * @tparam io.file inputfd the stream to be closed
|
|
||||||
+ * @treturn bool the same with @{io.close}
|
|
||||||
+ */
|
|
||||||
+static int close_subprocess(lua_State *L) {
|
|
||||||
+ luaL_Stream *file = luaL_checkudata(L, -1, "FILE*");
|
|
||||||
+ int result = fclose(file->f);
|
|
||||||
+ if (result == 0) {
|
|
||||||
+ file->f = NULL;
|
|
||||||
+ file->closef = NULL;
|
|
||||||
+ }
|
|
||||||
+ return luaL_fileresult(L, result == 0, NULL);
|
|
||||||
+}
|
|
||||||
+/***
|
|
||||||
+ * Open new process and return its input handler.
|
|
||||||
+ * When the process will quit or will output anything to stdout or stderr,
|
|
||||||
+ * the @{process_response} event will be fired.
|
|
||||||
+ *
|
|
||||||
+ * The editor core won't be blocked while the external process is running.
|
|
||||||
+ *
|
|
||||||
+ * @function communicate
|
|
||||||
+ * @tparam string name the name of subprocess (to distinguish processes in the @{process_response} event)
|
|
||||||
+ * @tparam string command the command to execute
|
|
||||||
+ * @return the file handle to write data to the process, in case of error the return values are equivalent to @{io.open} error values.
|
|
||||||
+ */
|
|
||||||
+static int communicate_func(lua_State *L) {
|
|
||||||
+ Vis *vis = obj_ref_check(L, 1, "vis");
|
|
||||||
+ const char *name = luaL_checkstring(L, 2);
|
|
||||||
+ const char *cmd = luaL_checkstring(L, 3);
|
|
||||||
+ ProcessStream *inputfd = (ProcessStream *)lua_newuserdata(L, sizeof(ProcessStream));
|
|
||||||
+ luaL_setmetatable(L, LUA_FILEHANDLE);
|
|
||||||
+ inputfd->handler = vis_process_communicate(vis, name, cmd, (void **)(&(inputfd->closef)));
|
|
||||||
+ if (inputfd->handler) {
|
|
||||||
+ inputfd->f = fdopen(inputfd->handler->inpfd, "w");
|
|
||||||
+ inputfd->closef = &close_subprocess;
|
|
||||||
+ }
|
|
||||||
+ return inputfd->f ? 1 : luaL_fileresult(L, inputfd->f != NULL, name);
|
|
||||||
+}
|
|
||||||
+/***
|
|
||||||
* Currently active window.
|
|
||||||
* @tfield Window win
|
|
||||||
* @see windows
|
|
||||||
@@ -1528,6 +1580,7 @@ static const struct luaL_Reg vis_lua[] =
|
|
||||||
{ "exit", exit_func },
|
|
||||||
{ "pipe", pipe_func },
|
|
||||||
{ "redraw", redraw },
|
|
||||||
+ { "communicate", communicate_func },
|
|
||||||
{ "__index", vis_index },
|
|
||||||
{ "__newindex", vis_newindex },
|
|
||||||
{ NULL, NULL },
|
|
||||||
@@ -3139,5 +3192,34 @@ void vis_lua_term_csi(Vis *vis, const lo
|
|
||||||
}
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
|
||||||
+/***
|
|
||||||
+ * The response received from the process started via @{Vis:communicate}.
|
|
||||||
+ * @function process_response
|
|
||||||
+ * @tparam string name the name of process given to @{Vis:communicate}
|
|
||||||
+ * @tparam string response_type can be "STDOUT" or "STDERR" if new output was received in corresponding channel, "SIGNAL" if the process was terminated by a signal or "EXIT" when the process terminated normally
|
|
||||||
+ * @tparam string|int buffer the available content sent by process; it becomes the exit code number if response\_type is "EXIT", or the signal number if response\_type is "SIGNAL"
|
|
||||||
+ */
|
|
||||||
+void vis_lua_process_response(Vis *vis, const char *name,
|
|
||||||
+ char *buffer, size_t len, ResponseType rtype) {
|
|
||||||
+ lua_State *L = vis->lua;
|
|
||||||
+ if (!L)
|
|
||||||
+ return;
|
|
||||||
+ vis_lua_event_get(L, "process_response");
|
|
||||||
+ if (lua_isfunction(L, -1)) {
|
|
||||||
+ lua_pushstring(L, name);
|
|
||||||
+ if (rtype == EXIT || rtype == SIGNAL)
|
|
||||||
+ lua_pushinteger(L, len);
|
|
||||||
+ else
|
|
||||||
+ lua_pushlstring(L, buffer, len);
|
|
||||||
+ switch (rtype){
|
|
||||||
+ case STDOUT: lua_pushstring(L, "STDOUT"); break;
|
|
||||||
+ case STDERR: lua_pushstring(L, "STDERR"); break;
|
|
||||||
+ case SIGNAL: lua_pushstring(L, "SIGNAL"); break;
|
|
||||||
+ case EXIT: lua_pushstring(L, "EXIT"); break;
|
|
||||||
+ }
|
|
||||||
+ pcall(vis, L, 3, 0);
|
|
||||||
+ }
|
|
||||||
+ lua_pop(L, 1);
|
|
||||||
+}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
--- a/vis-lua.h
|
|
||||||
+++ b/vis-lua.h
|
|
||||||
@@ -7,10 +7,11 @@
|
|
||||||
#include <lauxlib.h>
|
|
||||||
#else
|
|
||||||
typedef struct lua_State lua_State;
|
|
||||||
+typedef void* lua_CFunction;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "vis.h"
|
|
||||||
-
|
|
||||||
+#include "vis-subprocess.h"
|
|
||||||
/* add a directory to consider when loading lua files */
|
|
||||||
bool vis_lua_path_add(Vis*, const char *path);
|
|
||||||
/* get semicolon separated list of paths to load lua files
|
|
||||||
@@ -38,5 +39,6 @@ void vis_lua_win_close(Vis*, Win*);
|
|
||||||
void vis_lua_win_highlight(Vis*, Win*);
|
|
||||||
void vis_lua_win_status(Vis*, Win*);
|
|
||||||
void vis_lua_term_csi(Vis*, const long *);
|
|
||||||
+void vis_lua_process_response(Vis *, const char *, char *, size_t, ResponseType);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/vis-subprocess.c
|
|
||||||
@@ -0,0 +1,176 @@
|
|
||||||
+#include <fcntl.h>
|
|
||||||
+#include <stdio.h>
|
|
||||||
+#include <stdbool.h>
|
|
||||||
+#include <errno.h>
|
|
||||||
+#include <string.h>
|
|
||||||
+#include <sys/wait.h>
|
|
||||||
+#include "vis-lua.h"
|
|
||||||
+#include "vis-subprocess.h"
|
|
||||||
+
|
|
||||||
+/* Maximum amount of data what can be read from IPC pipe per event */
|
|
||||||
+#define MAXBUFFER 1024
|
|
||||||
+
|
|
||||||
+/* Pool of information about currently running subprocesses */
|
|
||||||
+static Process *process_pool;
|
|
||||||
+
|
|
||||||
+Process *new_in_pool() {
|
|
||||||
+ /* Adds new empty process information structure to the process pool and
|
|
||||||
+ * returns it */
|
|
||||||
+ Process *newprocess = (Process *)malloc(sizeof(Process));
|
|
||||||
+ if (!newprocess) return NULL;
|
|
||||||
+ newprocess->next = process_pool;
|
|
||||||
+ process_pool = newprocess;
|
|
||||||
+ return newprocess;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+void destroy(Process **pointer) {
|
|
||||||
+ /* Removes the subprocess information from the pool, sets invalidator to NULL
|
|
||||||
+ * and frees resources. */
|
|
||||||
+ Process *target = *pointer;
|
|
||||||
+ if (target->outfd != -1) close(target->outfd);
|
|
||||||
+ if (target->errfd != -1) close(target->errfd);
|
|
||||||
+ if (target->inpfd != -1) close(target->inpfd);
|
|
||||||
+ /* marking stream as closed for lua */
|
|
||||||
+ if (target->invalidator) *(target->invalidator) = NULL;
|
|
||||||
+ if (target->name) free(target->name);
|
|
||||||
+ *pointer = target->next;
|
|
||||||
+ free(target);
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+Process *vis_process_communicate(Vis *vis, const char *name,
|
|
||||||
+ const char *command, void **invalidator) {
|
|
||||||
+ /* Starts new subprocess by passing the `command` to the shell and
|
|
||||||
+ * returns the subprocess information structure, containing file descriptors
|
|
||||||
+ * of the process.
|
|
||||||
+ * Also stores the subprocess information to the internal pool to track
|
|
||||||
+ * its status and responses.
|
|
||||||
+ * `name` - the string than should contain an unique name of the subprocess.
|
|
||||||
+ * This name will be passed to the PROCESS_RESPONSE event handler
|
|
||||||
+ * to distinguish running subprocesses.
|
|
||||||
+ * `invalidator` - a pointer to the pointer which shows that the subprocess
|
|
||||||
+ * is invalid when set to NULL. When subprocess dies, it is being set to NULL.
|
|
||||||
+ * If the pointer is set to NULL by an external code, the subprocess will be
|
|
||||||
+ * killed on the next main loop iteration. */
|
|
||||||
+ int pin[2], pout[2], perr[2];
|
|
||||||
+ pid_t pid = (pid_t)-1;
|
|
||||||
+ if (pipe(perr) == -1) goto closeerr;
|
|
||||||
+ if (pipe(pout) == -1) goto closeouterr;
|
|
||||||
+ if (pipe(pin) == -1) goto closeall;
|
|
||||||
+ pid = fork();
|
|
||||||
+ if (pid == -1)
|
|
||||||
+ vis_info_show(vis, "fork failed: %s", strerror(errno));
|
|
||||||
+ else if (pid == 0){ /* child process */
|
|
||||||
+ sigset_t sigterm_mask;
|
|
||||||
+ sigemptyset(&sigterm_mask);
|
|
||||||
+ sigaddset(&sigterm_mask, SIGTERM);
|
|
||||||
+ if (sigprocmask(SIG_UNBLOCK, &sigterm_mask, NULL) == -1) {
|
|
||||||
+ fprintf(stderr, "failed to reset signal mask");
|
|
||||||
+ exit(EXIT_FAILURE);
|
|
||||||
+ }
|
|
||||||
+ dup2(pin[0], STDIN_FILENO);
|
|
||||||
+ dup2(pout[1], STDOUT_FILENO);
|
|
||||||
+ dup2(perr[1], STDERR_FILENO);
|
|
||||||
+ }
|
|
||||||
+ else { /* main process */
|
|
||||||
+ Process *new = new_in_pool();
|
|
||||||
+ if (!new) {
|
|
||||||
+ vis_info_show(vis, "Can not create process: %s", strerror(errno));
|
|
||||||
+ goto closeall;
|
|
||||||
+ }
|
|
||||||
+ new->name = strdup(name);
|
|
||||||
+ if (!new->name) {
|
|
||||||
+ vis_info_show(vis, "Can not copy process name: %s", strerror(errno));
|
|
||||||
+ /* pop top element (which is `new`) from the pool */
|
|
||||||
+ destroy(&process_pool);
|
|
||||||
+ goto closeall;
|
|
||||||
+ }
|
|
||||||
+ new->outfd = pout[0];
|
|
||||||
+ new->errfd = perr[0];
|
|
||||||
+ new->inpfd = pin[1];
|
|
||||||
+ new->pid = pid;
|
|
||||||
+ new->invalidator = invalidator;
|
|
||||||
+ close(pin[0]);
|
|
||||||
+ close(pout[1]);
|
|
||||||
+ close(perr[1]);
|
|
||||||
+ return new;
|
|
||||||
+ }
|
|
||||||
+closeall:
|
|
||||||
+ close(pin[0]);
|
|
||||||
+ close(pin[1]);
|
|
||||||
+closeouterr:
|
|
||||||
+ close(pout[0]);
|
|
||||||
+ close(pout[1]);
|
|
||||||
+closeerr:
|
|
||||||
+ close(perr[0]);
|
|
||||||
+ close(perr[1]);
|
|
||||||
+ if (pid == 0) { /* start command in child process */
|
|
||||||
+ execlp(vis->shell, vis->shell, "-c", command, (char*)NULL);
|
|
||||||
+ fprintf(stderr, "exec failed: %s(%d)\n", strerror(errno), errno);
|
|
||||||
+ exit(1);
|
|
||||||
+ }
|
|
||||||
+ else
|
|
||||||
+ vis_info_show(vis, "process creation failed: %s", strerror(errno));
|
|
||||||
+ return NULL;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+int vis_process_before_tick(fd_set *readfds) {
|
|
||||||
+ /* Adds file descriptors of currently running subprocesses to the `readfds`
|
|
||||||
+ * to track their readiness and returns maximum file descriptor value
|
|
||||||
+ * to pass it to the `pselect` call */
|
|
||||||
+ Process **pointer = &process_pool;
|
|
||||||
+ int maxfd = 0;
|
|
||||||
+ while (*pointer) {
|
|
||||||
+ Process *current = *pointer;
|
|
||||||
+ if (current->outfd != -1) {
|
|
||||||
+ FD_SET(current->outfd, readfds);
|
|
||||||
+ maxfd = maxfd < current->outfd ? current->outfd : maxfd;
|
|
||||||
+ }
|
|
||||||
+ if (current->errfd != -1) {
|
|
||||||
+ FD_SET(current->errfd, readfds);
|
|
||||||
+ maxfd = maxfd < current->errfd ? current->errfd : maxfd;
|
|
||||||
+ }
|
|
||||||
+ pointer = ¤t->next;
|
|
||||||
+ }
|
|
||||||
+ return maxfd;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+void read_and_fire(Vis* vis, int fd, const char *name, ResponseType rtype) {
|
|
||||||
+ /* Reads data from the given subprocess file descriptor `fd` and fires
|
|
||||||
+ * the PROCESS_RESPONSE event in Lua with given subprocess `name`,
|
|
||||||
+ * `rtype` and the read data as arguments. */
|
|
||||||
+ static char buffer[MAXBUFFER];
|
|
||||||
+ size_t obtained = read(fd, &buffer, MAXBUFFER-1);
|
|
||||||
+ if (obtained > 0)
|
|
||||||
+ vis_lua_process_response(vis, name, buffer, obtained, rtype);
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+void vis_process_tick(Vis *vis, fd_set *readfds) {
|
|
||||||
+ /* Checks if `readfds` contains file discriptors of subprocesses from
|
|
||||||
+ * the pool. If so, reads the data from them and fires corresponding events.
|
|
||||||
+ * Also checks if subprocesses from pool is dead or need to be killed then
|
|
||||||
+ * raises event or kills it if necessary. */
|
|
||||||
+ Process **pointer = &process_pool;
|
|
||||||
+ while (*pointer) {
|
|
||||||
+ Process *current = *pointer;
|
|
||||||
+ if (current->outfd != -1 && FD_ISSET(current->outfd, readfds))
|
|
||||||
+ read_and_fire(vis, current->outfd, current->name, STDOUT);
|
|
||||||
+ if (current->errfd != -1 && FD_ISSET(current->errfd, readfds))
|
|
||||||
+ read_and_fire(vis, current->errfd, current->name, STDERR);
|
|
||||||
+ int status;
|
|
||||||
+ pid_t wpid = waitpid(current->pid, &status, WNOHANG);
|
|
||||||
+ if (wpid == -1) vis_message_show(vis, strerror(errno));
|
|
||||||
+ else if (wpid == current->pid) goto just_destroy;
|
|
||||||
+ else if(!*(current->invalidator)) goto kill_and_destroy;
|
|
||||||
+ pointer = ¤t->next;
|
|
||||||
+ continue;
|
|
||||||
+kill_and_destroy:
|
|
||||||
+ kill(current->pid, SIGTERM);
|
|
||||||
+ waitpid(current->pid, &status, 0);
|
|
||||||
+just_destroy:
|
|
||||||
+ if (WIFSIGNALED(status))
|
|
||||||
+ vis_lua_process_response(vis, current->name, NULL, WTERMSIG(status), SIGNAL);
|
|
||||||
+ else
|
|
||||||
+ vis_lua_process_response(vis, current->name, NULL, WEXITSTATUS(status), EXIT);
|
|
||||||
+ destroy(pointer);
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/vis-subprocess.h
|
|
||||||
@@ -0,0 +1,23 @@
|
|
||||||
+#ifndef VIS_SUBPROCESS_H
|
|
||||||
+#define VIS_SUBPROCESS_H
|
|
||||||
+#include "vis-core.h"
|
|
||||||
+#include <sys/select.h>
|
|
||||||
+
|
|
||||||
+struct Process {
|
|
||||||
+ char *name;
|
|
||||||
+ int outfd;
|
|
||||||
+ int errfd;
|
|
||||||
+ int inpfd;
|
|
||||||
+ pid_t pid;
|
|
||||||
+ void **invalidator;
|
|
||||||
+ struct Process *next;
|
|
||||||
+};
|
|
||||||
+
|
|
||||||
+typedef struct Process Process;
|
|
||||||
+typedef enum { STDOUT, STDERR, SIGNAL, EXIT } ResponseType;
|
|
||||||
+
|
|
||||||
+Process *vis_process_communicate(Vis *, const char *command, const char *name,
|
|
||||||
+ void **invalidator);
|
|
||||||
+int vis_process_before_tick(fd_set *);
|
|
||||||
+void vis_process_tick(Vis *, fd_set *);
|
|
||||||
+#endif
|
|
||||||
--- a/vis.c
|
|
||||||
+++ b/vis.c
|
|
||||||
@@ -28,6 +28,7 @@
|
|
||||||
#include "vis-core.h"
|
|
||||||
#include "sam.h"
|
|
||||||
#include "ui.h"
|
|
||||||
+#include "vis-subprocess.h"
|
|
||||||
|
|
||||||
|
|
||||||
static void macro_replay(Vis *vis, const Macro *macro);
|
|
||||||
@@ -1412,7 +1413,8 @@ int vis_run(Vis *vis) {
|
|
||||||
|
|
||||||
vis_update(vis);
|
|
||||||
idle.tv_sec = vis->mode->idle_timeout;
|
|
||||||
- int r = pselect(1, &fds, NULL, NULL, timeout, &emptyset);
|
|
||||||
+ int r = pselect(vis_process_before_tick(&fds) + 1, &fds, NULL, NULL,
|
|
||||||
+ timeout, &emptyset);
|
|
||||||
if (r == -1 && errno == EINTR)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
@@ -1420,6 +1422,7 @@ int vis_run(Vis *vis) {
|
|
||||||
/* TODO save all pending changes to a ~suffixed file */
|
|
||||||
vis_die(vis, "Error in mainloop: %s\n", strerror(errno));
|
|
||||||
}
|
|
||||||
+ vis_process_tick(vis, &fds);
|
|
||||||
|
|
||||||
if (!FD_ISSET(STDIN_FILENO, &fds)) {
|
|
||||||
if (vis->mode->idle)
|
|
@ -1,61 +0,0 @@
|
|||||||
From 3984e4497d0a6466cb82b3749e05600ad6e24603 Mon Sep 17 00:00:00 2001
|
|
||||||
From: TwoFinger <Two-Finger@users.noreply.github.com>
|
|
||||||
Date: Mon, 14 May 2018 15:42:05 +0300
|
|
||||||
Subject: [PATCH] vis: Fix a crash when re-entering prompt window
|
|
||||||
|
|
||||||
vis->mode was incorrectly "restored" to a NULL prompt->parent_mode in
|
|
||||||
prompt_restore() because vis_prompt_show() was assuming that the
|
|
||||||
currently active window is always a regular one.
|
|
||||||
But if the active window is the command window, a new command window(s) would
|
|
||||||
be created with the old command window as its parent.
|
|
||||||
---
|
|
||||||
vis-prompt.c | 38 ++++++++++++++++++++------------------
|
|
||||||
1 file changed, 20 insertions(+), 18 deletions(-)
|
|
||||||
|
|
||||||
--- a/vis-prompt.c
|
|
||||||
+++ b/vis-prompt.c
|
|
||||||
@@ -158,24 +158,26 @@ static const KeyBinding prompt_tab_bindi
|
|
||||||
|
|
||||||
void vis_prompt_show(Vis *vis, const char *title) {
|
|
||||||
Win *active = vis->win;
|
|
||||||
- Win *prompt = window_new_file(vis, title[0] == ':' ? vis->command_file : vis->search_file,
|
|
||||||
- UI_OPTION_ONELINE);
|
|
||||||
- if (!prompt)
|
|
||||||
- return;
|
|
||||||
- Text *txt = prompt->file->text;
|
|
||||||
- text_appendf(txt, "%s\n", title);
|
|
||||||
- Selection *sel = view_selections_primary_get(prompt->view);
|
|
||||||
- view_cursors_scroll_to(sel, text_size(txt)-1);
|
|
||||||
- prompt->parent = active;
|
|
||||||
- prompt->parent_mode = vis->mode;
|
|
||||||
- vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Enter>", &prompt_enter_binding);
|
|
||||||
- vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Enter>", &prompt_enter_binding);
|
|
||||||
- vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<C-j>", &prompt_enter_binding);
|
|
||||||
- vis_window_mode_map(prompt, VIS_MODE_VISUAL, true, "<Enter>", &prompt_enter_binding);
|
|
||||||
- vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Escape>", &prompt_esc_binding);
|
|
||||||
- vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Up>", &prompt_up_binding);
|
|
||||||
- if (CONFIG_LUA)
|
|
||||||
- vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Tab>", &prompt_tab_binding);
|
|
||||||
+ if (active->file != vis->command_file && active->file != vis->search_file) {
|
|
||||||
+ Win *prompt = window_new_file(vis, title[0] == ':' ? vis->command_file : vis->search_file,
|
|
||||||
+ UI_OPTION_ONELINE);
|
|
||||||
+ if (!prompt)
|
|
||||||
+ return;
|
|
||||||
+ Text *txt = prompt->file->text;
|
|
||||||
+ text_appendf(txt, "%s\n", title);
|
|
||||||
+ Selection *sel = view_selections_primary_get(prompt->view);
|
|
||||||
+ view_cursors_scroll_to(sel, text_size(txt)-1);
|
|
||||||
+ prompt->parent = active;
|
|
||||||
+ prompt->parent_mode = vis->mode;
|
|
||||||
+ vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Enter>", &prompt_enter_binding);
|
|
||||||
+ vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Enter>", &prompt_enter_binding);
|
|
||||||
+ vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<C-j>", &prompt_enter_binding);
|
|
||||||
+ vis_window_mode_map(prompt, VIS_MODE_VISUAL, true, "<Enter>", &prompt_enter_binding);
|
|
||||||
+ vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Escape>", &prompt_esc_binding);
|
|
||||||
+ vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Up>", &prompt_up_binding);
|
|
||||||
+ if (CONFIG_LUA)
|
|
||||||
+ vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Tab>", &prompt_tab_binding);
|
|
||||||
+ }
|
|
||||||
vis_mode_switch(vis, VIS_MODE_INSERT);
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
|||||||
From 115884fd617114be76ccddd2389b815a3a0c6100 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Miles Canfield <miles.a.canfield@gmail.com>
|
|
||||||
Date: Tue, 20 Oct 2020 17:17:30 -0600
|
|
||||||
Subject: [PATCH] Limit to lines within range for inner text objects
|
|
||||||
|
|
||||||
---
|
|
||||||
vis.c | 3 +++
|
|
||||||
1 file changed, 3 insertions(+)
|
|
||||||
|
|
||||||
--- a/vis.c
|
|
||||||
+++ b/vis.c
|
|
||||||
@@ -963,6 +963,9 @@ void vis_do(Vis *vis) {
|
|
||||||
if (a->textobj->type & TEXTOBJECT_DELIMITED_OUTER) {
|
|
||||||
r.start--;
|
|
||||||
r.end++;
|
|
||||||
+ } else if (linewise && (a->textobj->type & TEXTOBJECT_DELIMITED_INNER)) {
|
|
||||||
+ r.start = text_line_next(txt, r.start);
|
|
||||||
+ r.end = text_line_prev(txt, r.end);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vis->mode->visual || (i > 0 && !(a->textobj->type & TEXTOBJECT_NON_CONTIGUOUS)))
|
|
@ -1,99 +0,0 @@
|
|||||||
From d59b98d934815e54320ad000eebfdaaf8fee344d Mon Sep 17 00:00:00 2001
|
|
||||||
From: Silvan Jegen <s.jegen@gmail.com>
|
|
||||||
Date: Sat, 10 Apr 2021 13:40:51 +0200
|
|
||||||
Subject: [PATCH 1/2] vis-menu: try to preserve valid Unicode points
|
|
||||||
|
|
||||||
Before we were not taking non-ascii characters into account properly. With
|
|
||||||
this patch we still mix byte counts and "grapheme cluster" (i.e. complete
|
|
||||||
glyphs that are rendered in a terminal cell) counts but the code should
|
|
||||||
be less broken in the more common case now.
|
|
||||||
---
|
|
||||||
vis-complete | 2 +-
|
|
||||||
vis-menu.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
|
|
||||||
2 files changed, 44 insertions(+), 5 deletions(-)
|
|
||||||
|
|
||||||
--- a/vis-complete
|
|
||||||
+++ b/vis-complete
|
|
||||||
@@ -29,7 +29,7 @@ while [ $# -gt 0 ]; do
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ $COMPLETE_WORD = 1 ]; then
|
|
||||||
- tr -cs '[:alnum:]_' '\n' |
|
|
||||||
+ tr -s '[:blank:]_' '\n' |
|
|
||||||
grep "^$(basic_regex_quote "$PATTERN")." |
|
|
||||||
sort -u
|
|
||||||
else
|
|
||||||
--- a/vis-menu.c
|
|
||||||
+++ b/vis-menu.c
|
|
||||||
@@ -84,12 +84,46 @@ appenditem(Item *item, Item **list, Item
|
|
||||||
|
|
||||||
static size_t
|
|
||||||
textwn(const char *s, int l) {
|
|
||||||
- int b, c; /* bytes and UTF-8 characters */
|
|
||||||
+ int c;
|
|
||||||
|
|
||||||
- for(b=c=0; s && s[b] && (l<0 || b<l); b++) if((s[b] & 0xc0) != 0x80) c++;
|
|
||||||
+ for(c=0; s && s[c] && (l<0 || c<l); ) c++;
|
|
||||||
return c+4; /* Accomodate for the leading and trailing spaces */
|
|
||||||
}
|
|
||||||
|
|
||||||
+/*
|
|
||||||
+ * textvalidn returns the highest amount of bytes <= l of string s that
|
|
||||||
+ * only contains valid Unicode points. This is used to make sure we don't
|
|
||||||
+ * cut off any valid UTF-8-encoded unicode point in case there is not
|
|
||||||
+ * enough space to render the whole text string.
|
|
||||||
+*/
|
|
||||||
+static ssize_t
|
|
||||||
+textvalidn(const char *s, int l) {
|
|
||||||
+ int c, utfcharbytes; /* byte count and UTF-8 codepoint length */
|
|
||||||
+
|
|
||||||
+ for (c=0; s && s[c] && (l<0 || c<l); ) {
|
|
||||||
+ utfcharbytes = 0;
|
|
||||||
+ if ((s[c] & 0x80) == 0) {
|
|
||||||
+ utfcharbytes = 1;
|
|
||||||
+ } else if ((s[c] & 0xf0) == 0xf0) {
|
|
||||||
+ utfcharbytes = 4;
|
|
||||||
+ } else if ((s[c] & 0xf0) == 0xe0) {
|
|
||||||
+ utfcharbytes = 3;
|
|
||||||
+ } else if ((s[c] & 0xe0) == 0xc0) {
|
|
||||||
+ utfcharbytes = 2;
|
|
||||||
+ } else {
|
|
||||||
+ return -1;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ if ((l>0 && c + utfcharbytes >= l)) {
|
|
||||||
+ break;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ c += utfcharbytes;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ return c;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
static size_t
|
|
||||||
textw(const char *s) {
|
|
||||||
return textwn(s, -1);
|
|
||||||
@@ -130,6 +164,7 @@ static void
|
|
||||||
drawtext(const char *t, size_t w, Color col) {
|
|
||||||
const char *prestr, *poststr;
|
|
||||||
size_t i, tw;
|
|
||||||
+ ssize_t valid;
|
|
||||||
char *buf;
|
|
||||||
|
|
||||||
if (w<5) return; /* This is the minimum size needed to write a label: 1 char + 4 padding spaces */
|
|
||||||
@@ -148,8 +183,12 @@ drawtext(const char *t, size_t w, Color
|
|
||||||
memset(buf, ' ', tw);
|
|
||||||
buf[tw] = '\0';
|
|
||||||
memcpy(buf, t, MIN(strlen(t), tw));
|
|
||||||
- if (textw(t) > w) /* Remember textw returns the width WITH padding */
|
|
||||||
- for (i = MAX((tw-4), 0); i < tw; i++) buf[i] = '.';
|
|
||||||
+ if (textw(t) > w) {/* Remember textw returns the width WITH padding */
|
|
||||||
+ valid = textvalidn(t, w-4);
|
|
||||||
+ if (valid < 0)
|
|
||||||
+ die("invalid UTF-8 sequence");
|
|
||||||
+ for (i = MAX(valid, 0); i < tw; i++) buf[i] = '.';
|
|
||||||
+ }
|
|
||||||
|
|
||||||
fprintf(stderr, "%s %s %s", prestr, buf, poststr);
|
|
||||||
free(buf);
|
|
@ -1,384 +0,0 @@
|
|||||||
From cc3a7e5566f7a33deeed5cbdcb9057e585c91dde Mon Sep 17 00:00:00 2001
|
|
||||||
From: Andrey Proskurin <>
|
|
||||||
Date: Sun, 9 May 2021 00:34:16 +0000
|
|
||||||
Subject: [PATCH 1/5] view: refactor view_addch
|
|
||||||
|
|
||||||
---
|
|
||||||
man/vis.1 | 5 +
|
|
||||||
sam.c | 12 +++
|
|
||||||
view.c | 224 +++++++++++++++++++++++++++++++++++++------------------------
|
|
||||||
view.h | 2
|
|
||||||
vis-cmds.c | 9 ++
|
|
||||||
5 files changed, 164 insertions(+), 88 deletions(-)
|
|
||||||
|
|
||||||
--- a/man/vis.1
|
|
||||||
+++ b/man/vis.1
|
|
||||||
@@ -1423,6 +1423,11 @@ WARNING: modifying a memory mapped file
|
|
||||||
Whether to use vertical or horizontal layout.
|
|
||||||
.It Cm ignorecase , Cm ic Op Cm off
|
|
||||||
Whether to ignore case when searching.
|
|
||||||
+.It Ic wrapcolumn , Ic wc Op Ar 0
|
|
||||||
+Wrap lines at minimum of window width and wrapcolumn.
|
|
||||||
+.
|
|
||||||
+.It Ic breakat , brk Op Dq Pa ""
|
|
||||||
+Characters which might cause a word wrap.
|
|
||||||
.El
|
|
||||||
.
|
|
||||||
.Sh COMMAND and SEARCH PROMPT
|
|
||||||
--- a/sam.c
|
|
||||||
+++ b/sam.c
|
|
||||||
@@ -301,6 +301,8 @@ enum {
|
|
||||||
OPTION_CHANGE_256COLORS,
|
|
||||||
OPTION_LAYOUT,
|
|
||||||
OPTION_IGNORECASE,
|
|
||||||
+ OPTION_BREAKAT,
|
|
||||||
+ OPTION_WRAP_COLUMN,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const OptionDef options[] = {
|
|
||||||
@@ -394,6 +396,16 @@ static const OptionDef options[] = {
|
|
||||||
VIS_OPTION_TYPE_BOOL,
|
|
||||||
VIS_HELP("Ignore case when searching")
|
|
||||||
},
|
|
||||||
+ [OPTION_BREAKAT] = {
|
|
||||||
+ { "breakat", "brk" },
|
|
||||||
+ VIS_OPTION_TYPE_STRING|VIS_OPTION_NEED_WINDOW,
|
|
||||||
+ VIS_HELP("Characters which might cause a word wrap")
|
|
||||||
+ },
|
|
||||||
+ [OPTION_WRAP_COLUMN] = {
|
|
||||||
+ { "wrapcolumn", "wc" },
|
|
||||||
+ VIS_OPTION_TYPE_NUMBER|VIS_OPTION_NEED_WINDOW,
|
|
||||||
+ VIS_HELP("Wrap lines at minimum of window width and wrapcolumn")
|
|
||||||
+ },
|
|
||||||
};
|
|
||||||
|
|
||||||
bool sam_init(Vis *vis) {
|
|
||||||
--- a/view.c
|
|
||||||
+++ b/view.c
|
|
||||||
@@ -80,6 +80,10 @@ struct View {
|
|
||||||
bool need_update; /* whether view has been redrawn */
|
|
||||||
bool large_file; /* optimize for displaying large files */
|
|
||||||
int colorcolumn;
|
|
||||||
+ char *breakat; /* characters which might cause a word wrap */
|
|
||||||
+ int wrapcolumn; /* wrap lines at minimum of window width and wrapcolumn (if != 0) */
|
|
||||||
+ int wrapcol; /* used while drawing view content, column where word wrap might happen */
|
|
||||||
+ bool prevch_breakat; /* used while drawing view content, previous char is part of breakat */
|
|
||||||
};
|
|
||||||
|
|
||||||
static const SyntaxSymbol symbols_none[] = {
|
|
||||||
@@ -109,6 +113,7 @@ static bool view_viewport_up(View *view,
|
|
||||||
static bool view_viewport_down(View *view, int n);
|
|
||||||
|
|
||||||
static void view_clear(View *view);
|
|
||||||
+static bool view_add_cell(View *view, const Cell *cell);
|
|
||||||
static bool view_addch(View *view, Cell *cell);
|
|
||||||
static void selection_free(Selection*);
|
|
||||||
/* set/move current cursor position to a given (line, column) pair */
|
|
||||||
@@ -156,6 +161,8 @@ static void view_clear(View *view) {
|
|
||||||
view->bottomline->next = NULL;
|
|
||||||
view->line = view->topline;
|
|
||||||
view->col = 0;
|
|
||||||
+ view->wrapcol = 0;
|
|
||||||
+ view->prevch_breakat = false;
|
|
||||||
if (view->ui)
|
|
||||||
view->cell_blank.style = view->ui->style_get(view->ui, UI_STYLE_DEFAULT);
|
|
||||||
}
|
|
||||||
@@ -164,98 +171,124 @@ Filerange view_viewport_get(View *view)
|
|
||||||
return (Filerange){ .start = view->start, .end = view->end };
|
|
||||||
}
|
|
||||||
|
|
||||||
-/* try to add another character to the view, return whether there was space left */
|
|
||||||
-static bool view_addch(View *view, Cell *cell) {
|
|
||||||
+static int view_max_text_width(const View *view) {
|
|
||||||
+ if (view->wrapcolumn > 0)
|
|
||||||
+ return MIN(view->wrapcolumn, view->width);
|
|
||||||
+ return view->width;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static void view_wrap_line(View *view) {
|
|
||||||
+ Line *cur_line = view->line;
|
|
||||||
+ int cur_col = view->col;
|
|
||||||
+ int wrapcol = (view->wrapcol > 0) ? view->wrapcol : cur_col;
|
|
||||||
+
|
|
||||||
+ view->line = cur_line->next;
|
|
||||||
+ view->col = 0;
|
|
||||||
+ view->wrapcol = 0;
|
|
||||||
+ if (view->line) {
|
|
||||||
+ /* move extra cells to the next line */
|
|
||||||
+ for (int i = wrapcol; i < cur_col; ++i) {
|
|
||||||
+ const Cell *cell = &cur_line->cells[i];
|
|
||||||
+ view_add_cell(view, cell);
|
|
||||||
+ cur_line->width -= cell->width;
|
|
||||||
+ cur_line->len -= cell->len;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ for (int i = wrapcol; i < view->width; ++i) {
|
|
||||||
+ /* clear remaining of line */
|
|
||||||
+ cur_line->cells[i] = view->cell_blank;
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static bool view_add_cell(View *view, const Cell *cell) {
|
|
||||||
+ size_t lineno = view->line->lineno;
|
|
||||||
+
|
|
||||||
+ if (view->col + cell->width > view_max_text_width(view))
|
|
||||||
+ view_wrap_line(view);
|
|
||||||
+
|
|
||||||
if (!view->line)
|
|
||||||
return false;
|
|
||||||
+ view->line->width += cell->width;
|
|
||||||
+ view->line->len += cell->len;
|
|
||||||
+ view->line->lineno = lineno;
|
|
||||||
+ view->line->cells[view->col] = *cell;
|
|
||||||
+ view->col++;
|
|
||||||
+ /* set cells of a character which uses multiple columns */
|
|
||||||
+ for (int i = 1; i < cell->width; i++)
|
|
||||||
+ view->line->cells[view->col++] = cell_unused;
|
|
||||||
+ return true;
|
|
||||||
+}
|
|
||||||
|
|
||||||
- int width;
|
|
||||||
- size_t lineno = view->line->lineno;
|
|
||||||
- unsigned char ch = (unsigned char)cell->data[0];
|
|
||||||
- cell->style = view->cell_blank.style;
|
|
||||||
+static bool view_expand_tab(View *view, Cell *cell) {
|
|
||||||
+ cell->width = 1;
|
|
||||||
|
|
||||||
- switch (ch) {
|
|
||||||
- case '\t':
|
|
||||||
- cell->width = 1;
|
|
||||||
- width = view->tabwidth - (view->col % view->tabwidth);
|
|
||||||
- for (int w = 0; w < width; w++) {
|
|
||||||
- if (view->col + 1 > view->width) {
|
|
||||||
- view->line = view->line->next;
|
|
||||||
- view->col = 0;
|
|
||||||
- if (!view->line)
|
|
||||||
- return false;
|
|
||||||
- view->line->lineno = lineno;
|
|
||||||
- }
|
|
||||||
-
|
|
||||||
- cell->len = w == 0 ? 1 : 0;
|
|
||||||
- int t = w == 0 ? SYNTAX_SYMBOL_TAB : SYNTAX_SYMBOL_TAB_FILL;
|
|
||||||
- strncpy(cell->data, view->symbols[t]->symbol, sizeof(cell->data)-1);
|
|
||||||
- view->line->cells[view->col] = *cell;
|
|
||||||
- view->line->len += cell->len;
|
|
||||||
- view->line->width += cell->width;
|
|
||||||
- view->col++;
|
|
||||||
- }
|
|
||||||
- cell->len = 1;
|
|
||||||
- return true;
|
|
||||||
- case '\n':
|
|
||||||
- cell->width = 1;
|
|
||||||
- if (view->col + cell->width > view->width) {
|
|
||||||
- view->line = view->line->next;
|
|
||||||
- view->col = 0;
|
|
||||||
- if (!view->line)
|
|
||||||
- return false;
|
|
||||||
- view->line->lineno = lineno;
|
|
||||||
- }
|
|
||||||
+ int displayed_width = view->tabwidth - (view->col % view->tabwidth);
|
|
||||||
+ for (int w = 0; w < displayed_width; ++w) {
|
|
||||||
|
|
||||||
- strncpy(cell->data, view->symbols[SYNTAX_SYMBOL_EOL]->symbol, sizeof(cell->data)-1);
|
|
||||||
+ int t = (w == 0) ? SYNTAX_SYMBOL_TAB : SYNTAX_SYMBOL_TAB_FILL;
|
|
||||||
+ const char *symbol = view->symbols[t]->symbol;
|
|
||||||
+ strncpy(cell->data, symbol, sizeof(cell->data) - 1);
|
|
||||||
+ cell->len = (w == 0) ? 1 : 0;
|
|
||||||
|
|
||||||
- view->line->cells[view->col] = *cell;
|
|
||||||
- view->line->len += cell->len;
|
|
||||||
- view->line->width += cell->width;
|
|
||||||
- for (int i = view->col + 1; i < view->width; i++)
|
|
||||||
- view->line->cells[i] = view->cell_blank;
|
|
||||||
-
|
|
||||||
- view->line = view->line->next;
|
|
||||||
- if (view->line)
|
|
||||||
- view->line->lineno = lineno + 1;
|
|
||||||
- view->col = 0;
|
|
||||||
- return true;
|
|
||||||
- default:
|
|
||||||
- if (ch < 128 && !isprint(ch)) {
|
|
||||||
- /* non-printable ascii char, represent it as ^(char + 64) */
|
|
||||||
- *cell = (Cell) {
|
|
||||||
- .data = { '^', ch == 127 ? '?' : ch + 64, '\0' },
|
|
||||||
- .len = 1,
|
|
||||||
- .width = 2,
|
|
||||||
- .style = cell->style,
|
|
||||||
- };
|
|
||||||
- }
|
|
||||||
+ if (!view_add_cell(view, cell))
|
|
||||||
+ return false;
|
|
||||||
+ }
|
|
||||||
|
|
||||||
- if (ch == ' ') {
|
|
||||||
- strncpy(cell->data, view->symbols[SYNTAX_SYMBOL_SPACE]->symbol, sizeof(cell->data)-1);
|
|
||||||
+ cell->len = 1;
|
|
||||||
+ return true;
|
|
||||||
+}
|
|
||||||
|
|
||||||
- }
|
|
||||||
+static bool view_expand_newline(View *view, Cell *cell) {
|
|
||||||
+ size_t lineno = view->line->lineno;
|
|
||||||
+ const char *symbol = view->symbols[SYNTAX_SYMBOL_EOL]->symbol;
|
|
||||||
|
|
||||||
- if (view->col + cell->width > view->width) {
|
|
||||||
- for (int i = view->col; i < view->width; i++)
|
|
||||||
- view->line->cells[i] = view->cell_blank;
|
|
||||||
- view->line = view->line->next;
|
|
||||||
- view->col = 0;
|
|
||||||
- }
|
|
||||||
+ strncpy(cell->data, symbol, sizeof(cell->data) - 1);
|
|
||||||
+ cell->width = 1;
|
|
||||||
+ if (!view_add_cell(view, cell))
|
|
||||||
+ return false;
|
|
||||||
|
|
||||||
- if (view->line) {
|
|
||||||
- view->line->width += cell->width;
|
|
||||||
- view->line->len += cell->len;
|
|
||||||
- view->line->lineno = lineno;
|
|
||||||
- view->line->cells[view->col] = *cell;
|
|
||||||
- view->col++;
|
|
||||||
- /* set cells of a character which uses multiple columns */
|
|
||||||
- for (int i = 1; i < cell->width; i++)
|
|
||||||
- view->line->cells[view->col++] = cell_unused;
|
|
||||||
- return true;
|
|
||||||
- }
|
|
||||||
+ view->wrapcol = 0;
|
|
||||||
+ view_wrap_line(view);
|
|
||||||
+ if (view->line)
|
|
||||||
+ view->line->lineno = lineno + 1;
|
|
||||||
+ return true;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+/* try to add another character to the view, return whether there was space left */
|
|
||||||
+static bool view_addch(View *view, Cell *cell) {
|
|
||||||
+ if (!view->line)
|
|
||||||
return false;
|
|
||||||
+
|
|
||||||
+ unsigned char ch = (unsigned char)cell->data[0];
|
|
||||||
+ bool ch_breakat = strstr(view->breakat, cell->data);
|
|
||||||
+ if (view->prevch_breakat && !ch_breakat) {
|
|
||||||
+ /* this is a good place to wrap line if needed */
|
|
||||||
+ view->wrapcol = view->col;
|
|
||||||
}
|
|
||||||
+ view->prevch_breakat = ch_breakat;
|
|
||||||
+ cell->style = view->cell_blank.style;
|
|
||||||
+
|
|
||||||
+ switch (ch) {
|
|
||||||
+ case '\t':
|
|
||||||
+ return view_expand_tab(view, cell);
|
|
||||||
+ case '\n':
|
|
||||||
+ return view_expand_newline(view, cell);
|
|
||||||
+ case ' ': {
|
|
||||||
+ const char *symbol = view->symbols[SYNTAX_SYMBOL_SPACE]->symbol;
|
|
||||||
+ strncpy(cell->data, symbol, sizeof(cell->data) - 1);
|
|
||||||
+ return view_add_cell(view, cell);
|
|
||||||
+ }}
|
|
||||||
+
|
|
||||||
+ if (ch < 128 && !isprint(ch)) {
|
|
||||||
+ /* non-printable ascii char, represent it as ^(char + 64) */
|
|
||||||
+ *cell = (Cell) {
|
|
||||||
+ .data = { '^', ch == 127 ? '?' : ch + 64, '\0' },
|
|
||||||
+ .len = 1,
|
|
||||||
+ .width = 2,
|
|
||||||
+ .style = cell->style,
|
|
||||||
+ };
|
|
||||||
+ }
|
|
||||||
+ return view_add_cell(view, cell);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cursor_to(Selection *s, size_t pos) {
|
|
||||||
@@ -492,6 +525,7 @@ void view_free(View *view) {
|
|
||||||
selection_free(view->selections);
|
|
||||||
free(view->textbuf);
|
|
||||||
free(view->lines);
|
|
||||||
+ free(view->breakat);
|
|
||||||
free(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -507,27 +541,27 @@ View *view_new(Text *text) {
|
|
||||||
View *view = calloc(1, sizeof(View));
|
|
||||||
if (!view)
|
|
||||||
return NULL;
|
|
||||||
- view->text = text;
|
|
||||||
- if (!view_selections_new(view, 0)) {
|
|
||||||
- view_free(view);
|
|
||||||
- return NULL;
|
|
||||||
- }
|
|
||||||
|
|
||||||
+ view->text = text;
|
|
||||||
+ view->tabwidth = 8;
|
|
||||||
+ view->breakat = strdup("");
|
|
||||||
+ view->wrapcolumn = 0;
|
|
||||||
view->cell_blank = (Cell) {
|
|
||||||
.width = 0,
|
|
||||||
.len = 0,
|
|
||||||
.data = " ",
|
|
||||||
};
|
|
||||||
- view->tabwidth = 8;
|
|
||||||
view_options_set(view, 0);
|
|
||||||
|
|
||||||
- if (!view_resize(view, 1, 1)) {
|
|
||||||
+ if (!view->breakat ||
|
|
||||||
+ !view_selections_new(view, 0) ||
|
|
||||||
+ !view_resize(view, 1, 1))
|
|
||||||
+ {
|
|
||||||
view_free(view);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
view_cursor_to(view, 0);
|
|
||||||
-
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -862,6 +896,20 @@ int view_colorcolumn_get(View *view) {
|
|
||||||
return view->colorcolumn;
|
|
||||||
}
|
|
||||||
|
|
||||||
+void view_wrapcolumn_set(View *view, int col) {
|
|
||||||
+ if (col >= 0)
|
|
||||||
+ view->wrapcolumn = col;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+bool view_breakat_set(View *view, const char *breakat) {
|
|
||||||
+ char *copy = strdup(breakat);
|
|
||||||
+ if (!copy)
|
|
||||||
+ return false;
|
|
||||||
+ free(view->breakat);
|
|
||||||
+ view->breakat = copy;
|
|
||||||
+ return true;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
size_t view_screenline_goto(View *view, int n) {
|
|
||||||
size_t pos = view->start;
|
|
||||||
for (Line *line = view->topline; --n > 0 && line != view->lastline; line = line->next)
|
|
||||||
--- a/view.h
|
|
||||||
+++ b/view.h
|
|
||||||
@@ -358,6 +358,8 @@ void view_options_set(View*, enum UiOpti
|
|
||||||
enum UiOption view_options_get(View*);
|
|
||||||
void view_colorcolumn_set(View*, int col);
|
|
||||||
int view_colorcolumn_get(View*);
|
|
||||||
+void view_wrapcolumn_set(View*, int col);
|
|
||||||
+bool view_breakat_set(View*, const char *breakat);
|
|
||||||
|
|
||||||
/** Set how many spaces are used to display a tab `\t` character. */
|
|
||||||
void view_tabwidth_set(View*, int tabwidth);
|
|
||||||
--- a/vis-cmds.c
|
|
||||||
+++ b/vis-cmds.c
|
|
||||||
@@ -364,6 +364,15 @@ static bool cmd_set(Vis *vis, Win *win,
|
|
||||||
case OPTION_IGNORECASE:
|
|
||||||
vis->ignorecase = toggle ? !vis->ignorecase : arg.b;
|
|
||||||
break;
|
|
||||||
+ case OPTION_BREAKAT:
|
|
||||||
+ if (!view_breakat_set(win->view, arg.s)) {
|
|
||||||
+ vis_info_show(vis, "Failed to set breakat");
|
|
||||||
+ return false;
|
|
||||||
+ }
|
|
||||||
+ break;
|
|
||||||
+ case OPTION_WRAP_COLUMN:
|
|
||||||
+ view_wrapcolumn_set(win->view, arg.i);
|
|
||||||
+ break;
|
|
||||||
default:
|
|
||||||
if (!opt->func)
|
|
||||||
return false;
|
|
@ -1,152 +0,0 @@
|
|||||||
From 37034a6549ca23f6d59deefae3d5f845c74683d1 Mon Sep 17 00:00:00 2001
|
|
||||||
From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20G=2E=20Garcia?=
|
|
||||||
<joaopauloggarcia@gmail.com>
|
|
||||||
Date: Sun, 1 Aug 2021 15:22:01 -0300
|
|
||||||
Subject: [PATCH 1/3] complete-filename: allow shell expansions and escape
|
|
||||||
"spaces".
|
|
||||||
|
|
||||||
Enclose prefix within double quotes so that we can properly use
|
|
||||||
environment variables.
|
|
||||||
|
|
||||||
Force "tilda expansion" by replacind "~"
|
|
||||||
with "$HOME".
|
|
||||||
|
|
||||||
Escape occurrences of spaces in vis-open output.
|
|
||||||
---
|
|
||||||
lua/plugins/complete-filename.lua | 8 ++--
|
|
||||||
vis-complete | 76 ++++++++++++++++++--------------------
|
|
||||||
2 files changed, 41 insertions(+), 43 deletions(-)
|
|
||||||
|
|
||||||
--- a/lua/plugins/complete-filename.lua
|
|
||||||
+++ b/lua/plugins/complete-filename.lua
|
|
||||||
@@ -15,7 +15,8 @@ vis:map(vis.modes.INSERT, "<C-x><C-f>",
|
|
||||||
-- Strip leading delimiters for some languages
|
|
||||||
local _, j = string.find(prefix, "[[(<'\"]+")
|
|
||||||
if j then prefix = prefix:sub(j + 1) end
|
|
||||||
- local cmd = string.format("vis-complete --file '%s'", prefix:gsub("'", "'\\''"))
|
|
||||||
+ local cmd = string.format('vis-complete --file "%s"',
|
|
||||||
+ prefix:gsub("^~", "$HOME"):gsub("'", "'\\''"))
|
|
||||||
local status, out, err = vis:pipe(file, { start = 0, finish = 0 }, cmd)
|
|
||||||
if status ~= 0 or not out then
|
|
||||||
if err then vis:info(err) end
|
|
||||||
@@ -43,13 +44,14 @@ vis:map(vis.modes.INSERT, "<C-x><C-o>",
|
|
||||||
range.start = pos
|
|
||||||
range.finish = pos
|
|
||||||
end
|
|
||||||
- local cmd = string.format("vis-open -- '%s'*", prefix:gsub("'", "'\\''"))
|
|
||||||
+ local cmd = string.format('vis-open -- "%s"*',
|
|
||||||
+ prefix:gsub("^~", "$HOME"):gsub("'", "'\\''"))
|
|
||||||
local status, out, err = vis:pipe(file, { start = 0, finish = 0 }, cmd)
|
|
||||||
if status ~= 0 or not out then
|
|
||||||
if err then vis:info(err) end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
- out = out:gsub("\n$", "")
|
|
||||||
+ out = out:gsub("\n$", ""):gsub(" ", "\\ ")
|
|
||||||
file:delete(range)
|
|
||||||
file:insert(range.start, out)
|
|
||||||
win.selection.pos = range.start + #out
|
|
||||||
--- a/vis-complete
|
|
||||||
+++ b/vis-complete
|
|
||||||
@@ -1,65 +1,61 @@
|
|
||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
-basic_regex_quote() { printf "%s" "$1" | sed 's|[\\.*^$[]|\\&|g'; }
|
|
||||||
-glob_quote () { printf "%s" "$1" | sed 's|[\\?*[]]|\\&|g'; }
|
|
||||||
+basic_regex_quote() { printf "%s" "$1" | sed 's/[|\\.*^$[]/\\&/g'; }
|
|
||||||
+
|
|
||||||
+print_completion() {
|
|
||||||
+ sort -u \
|
|
||||||
+ | vis-menu -b -i -l $VIS_MENU_LINES \
|
|
||||||
+ | sed "s|^$1||" \
|
|
||||||
+ | tr -d '\n'
|
|
||||||
+}
|
|
||||||
|
|
||||||
PATTERN=""
|
|
||||||
-COMPLETE_WORD=0
|
|
||||||
+COMPLETE_MODE='-' # -) stdin; w) split stdin in words; f) find(1) filenames
|
|
||||||
FIND_FILE_LIMIT=1000
|
|
||||||
+VIS_MENU_LINES=0
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
-h|--help)
|
|
||||||
- echo "usage: $(basename "$0") [-h] [--file|--word] [pattern]"
|
|
||||||
+ echo "usage: $(basename "$0") [-h] [-l lines] [--file|--word] [pattern]"
|
|
||||||
exit 0;
|
|
||||||
;;
|
|
||||||
--file)
|
|
||||||
+ COMPLETE_MODE='f'
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--word)
|
|
||||||
- COMPLETE_WORD=1
|
|
||||||
+ COMPLETE_MODE='w'
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
+ -l)
|
|
||||||
+ VIS_MENU_LINES=$2
|
|
||||||
+ shift 2
|
|
||||||
+ ;;
|
|
||||||
*)
|
|
||||||
PATTERN="$1"
|
|
||||||
+ QPATTERN=$(basic_regex_quote "$PATTERN") # Avoid problems with sed and grep.
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
-if [ $COMPLETE_WORD = 1 ]; then
|
|
||||||
- tr -s '[:blank:]_' '\n' |
|
|
||||||
- grep "^$(basic_regex_quote "$PATTERN")." |
|
|
||||||
- sort -u
|
|
||||||
-else
|
|
||||||
- # Expand to absolute path because of the -path option below.
|
|
||||||
- case $PATTERN in
|
|
||||||
- /*)
|
|
||||||
- XPATTERN=$PATTERN
|
|
||||||
- ;;
|
|
||||||
- '~'|'~/'*)
|
|
||||||
- XPATTERN=$HOME$(echo $PATTERN | tail -c +2)
|
|
||||||
- ;;
|
|
||||||
- *)
|
|
||||||
- XPATTERN=$PWD/$PATTERN
|
|
||||||
- ;;
|
|
||||||
- esac
|
|
||||||
-
|
|
||||||
- # The first path condition rules out paths that start with "." unless
|
|
||||||
- # they start with "..". That way, hidden paths should stay hidden, but
|
|
||||||
- # non-normalised paths should still show up.
|
|
||||||
- find $(dirname "$XPATTERN") \
|
|
||||||
- -name '.*' -prune \
|
|
||||||
- -o \( \
|
|
||||||
- ! -name '.*' \
|
|
||||||
- -a -path "$(glob_quote "$XPATTERN")*" \
|
|
||||||
- -print \
|
|
||||||
- \) 2>/dev/null |
|
|
||||||
- head -n $FIND_FILE_LIMIT |
|
|
||||||
- sort |
|
|
||||||
- sed "s|^$(dirname $XPATTERN)/||"
|
|
||||||
-fi |
|
|
||||||
- vis-menu -b |
|
|
||||||
- sed "s|^$(basename $PATTERN)$(echo $PATTERN | tail -c 2 | fgrep /)||" |
|
|
||||||
- tr -d '\n'
|
|
||||||
+case $COMPLETE_MODE in
|
|
||||||
+ -)
|
|
||||||
+ grep "^$QPATTERN." | print_completion "$QPATTERN"
|
|
||||||
+ ;;
|
|
||||||
+ w)
|
|
||||||
+ tr -cs '[:alnum:]_' '\n' \
|
|
||||||
+ | grep "^$PATTERN." \
|
|
||||||
+ | print_completion "$PATTERN"
|
|
||||||
+ ;;
|
|
||||||
+ f)
|
|
||||||
+ find "$PATTERN"* \
|
|
||||||
+ -name ".*" -prune \
|
|
||||||
+ -o -print 2> /dev/null \
|
|
||||||
+ | head -n $FIND_FILE_LIMIT \
|
|
||||||
+ | sed "s|^$(dirname "$QPATTERN".)/||" \
|
|
||||||
+ | print_completion "${QPATTERN##*/}"
|
|
||||||
+ ;;
|
|
||||||
+esac
|
|
@ -1,53 +0,0 @@
|
|||||||
Return-Path: <mcepl@cepl.eu>
|
|
||||||
Delivered-To: <mcepl@cepl.eu>
|
|
||||||
Received: from redcrew.org
|
|
||||||
by redcrew.org (Dovecot) with LMTP id WRniDQJfz2EqMQAAsTppAA
|
|
||||||
for <mcepl@cepl.eu>; Fri, 31 Dec 2021 21:00:20 +0100
|
|
||||||
Received: from stitny.localdomain (unknown [83.208.252.159])
|
|
||||||
(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))
|
|
||||||
(No client certificate requested)
|
|
||||||
by redcrew.org (Postfix) with ESMTPSA id 38AC7C70;
|
|
||||||
Fri, 31 Dec 2021 21:00:18 +0100 (CET)
|
|
||||||
Received: from stitny.localdomain (localhost [127.0.0.1])
|
|
||||||
by stitny.localdomain (Postfix) with ESMTP id 79FC54BDC4DD;
|
|
||||||
Fri, 31 Dec 2021 21:00:17 +0100 (CET)
|
|
||||||
From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= <mcepl@cepl.eu>
|
|
||||||
To: ~martanne/devel@lists.sr.ht
|
|
||||||
Cc: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= <mcepl@cepl.eu>
|
|
||||||
Subject: [vis] wl-paste and wl-copy should not add \n to the end of the clipboard.
|
|
||||||
Date: Fri, 31 Dec 2021 20:56:32 +0100
|
|
||||||
Message-Id: <20211231195631.12681-1-mcepl@cepl.eu>
|
|
||||||
X-Mailer: git-send-email 2.34.1
|
|
||||||
MIME-Version: 1.0
|
|
||||||
Content-Transfer-Encoding: 8bit
|
|
||||||
|
|
||||||
Hello,
|
|
||||||
|
|
||||||
it is very uncomfortable, that vis-clipboard (at least for me)
|
|
||||||
always adds \n to the pasted text. I am not sure whether it
|
|
||||||
is because of missing -n for wl-copy or the missing one for
|
|
||||||
wl-paste, so I have added the one for both, and I am very much
|
|
||||||
open to the discussion on the possible better solution.
|
|
||||||
|
|
||||||
Best,
|
|
||||||
|
|
||||||
Matěj
|
|
||||||
|
|
||||||
---
|
|
||||||
vis-clipboard | 4 ++--
|
|
||||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
|
||||||
|
|
||||||
--- a/vis-clipboard
|
|
||||||
+++ b/vis-clipboard
|
|
||||||
@@ -89,9 +89,9 @@ vc_wlclipboard_copy() {
|
|
||||||
|
|
||||||
vc_wlclipboard_paste() {
|
|
||||||
if [ "$sel" = "primary" ]; then
|
|
||||||
- wl-paste --primary -t text
|
|
||||||
+ wl-paste --no-newline --primary -t text
|
|
||||||
else
|
|
||||||
- wl-paste -t text
|
|
||||||
+ wl-paste --no-newline -t text
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
31
vis.spec
31
vis.spec
@ -28,36 +28,6 @@ URL: https://github.com/martanne/vis
|
|||||||
#!RemoteAssetUrl: git+https://github.com/mcepl/vis.git#scintillua
|
#!RemoteAssetUrl: git+https://github.com/mcepl/vis.git#scintillua
|
||||||
#!RemoteAssetUrl: git+https://github.com/martanne/vis-test.git#v0.5
|
#!RemoteAssetUrl: git+https://github.com/martanne/vis-test.git#v0.5
|
||||||
Source99: vis-rpmlintrc
|
Source99: vis-rpmlintrc
|
||||||
# PATCH-FEATURE-UPSTREAM 675-non-block_subproc.patch gh#martanne/vis#675 mcepl@suse.com
|
|
||||||
# adds function vis.commuincate which spawns a process and returns handles to its std files.
|
|
||||||
# seems to be the cause of crash in gh#martanne/vis#988
|
|
||||||
Patch0: 675-non-block_subproc.patch
|
|
||||||
# PATCH-FIX-UPSTREAM 699-no-crash-reenter-prompt.patch gh#martanne/vis#628 mcepl@suse.com
|
|
||||||
# don't crash on reenter of the prompt window
|
|
||||||
Patch1: 699-no-crash-reenter-prompt.patch
|
|
||||||
# PATCH-FIX-UPSTREAM 946-non-ASCII-completion.patch gh#martanne/vis#941 mcepl@suse.com
|
|
||||||
# make vis-menu handle non-ASCII characters better
|
|
||||||
Patch2: 946-non-ASCII-completion.patch
|
|
||||||
# # PATCH-FEATURE-UPSTREAM 948-soft-word-wrapping.patch gh#martanne/vis#948 mcepl@suse.com
|
|
||||||
# # adds soft word wrapping (linebreak in vim)
|
|
||||||
# Patch3: 948-soft-word-wrapping.patch
|
|
||||||
# PATCH-FEATURE-UPSTREAM 617-vis-highlight.patch gh#martanne/vis#617 mcepl@suse.com
|
|
||||||
# add vis-highlight command
|
|
||||||
Patch4: 617-vis-highlight.patch
|
|
||||||
# PATCH-FEATURE-UPSTREAM 959-flexible-insert-completion.patch gh#martanne/vis#959
|
|
||||||
# allow changes for https://github.com/jpaulogg/vis-ins-completion/tree/flex-completion
|
|
||||||
Patch5: 959-flexible-insert-completion.patch
|
|
||||||
# PATCH-FIX-UPSTREAM 558-gf_reimplementation.patch gh#martanne/vis#558 mcepl@suse.com
|
|
||||||
# Implementation of the gf command, v2
|
|
||||||
# This patch seems to ignite gh#martanne/vis#827 again.
|
|
||||||
Patch7: 558-gf_reimplementation.patch
|
|
||||||
# PATCH-FIX-UPSTREAM no-EOL-to-wl-clipboard.patch mcepl@suse.com
|
|
||||||
# don't add \n on paste
|
|
||||||
# from https://lists.sr.ht/~martanne/devel/%3C20211231195631.12681-1-mcepl%40cepl.eu%3E
|
|
||||||
Patch8: no-EOL-to-wl-clipboard.patch
|
|
||||||
# PATCH-FIX-UPSTREAM 881-linewise-inner-objects.patch gh#martanne/vis#881 mcepl@suse.com
|
|
||||||
# make linewise inner objects work differently from outer ones
|
|
||||||
Patch9: 881-linewise-inner-objects.patch
|
|
||||||
BuildRequires: libselinux-devel
|
BuildRequires: libselinux-devel
|
||||||
BuildRequires: libtermkey-devel
|
BuildRequires: libtermkey-devel
|
||||||
BuildRequires: ncurses-devel
|
BuildRequires: ncurses-devel
|
||||||
@ -83,7 +53,6 @@ It extends vi's modal editing with built-in support for multiple cursors/selecti
|
|||||||
%setup -q -n vis -c -T
|
%setup -q -n vis -c -T
|
||||||
cp -a %{_sourcedir}/vis/* .
|
cp -a %{_sourcedir}/vis/* .
|
||||||
cp -a %{_sourcedir}/vis-test/* test/
|
cp -a %{_sourcedir}/vis-test/* test/
|
||||||
%autopatch -p1
|
|
||||||
|
|
||||||
%build
|
%build
|
||||||
export CFLAGS="%{optflags} -fcommon"
|
export CFLAGS="%{optflags} -fcommon"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user