Commit Graph

47 Commits

Author SHA1 Message Date
Justin M. Keyes
9ef16a1628 doc: vim.fn, vim.call(), vim.api [ci skip] 2019-11-06 01:37:50 -08:00
Björn Linse
8ee7c94a92 lua: add vim.fn.{func} for direct access to vimL function
compared to vim.api.|nvim_call_function|, this fixes some typing issues
due to the indirect conversion via the API. float values are preserved
as such (fixes #9389) as well as empty dicts/arrays.

Ref https://github.com/norcalli/nvim.lua for the call syntax
2019-10-27 17:23:17 +01:00
Björn Linse
c8f861b739 tree-sitter: rename tree_sitter => treesitter for consistency 2019-09-28 14:55:43 +02:00
Björn Linse
4ea5e63aa8 tree-sitter: add basic testing on ci
build tree-sitter c parser on ci for testing purposes
2019-09-28 14:55:43 +02:00
Daniel Hahler
0571145c40
paste: fix handling of "<" in cmdline (#11094)
Fixes https://github.com/neovim/neovim/issues/11088.
2019-09-25 09:15:33 +02:00
Justin M. Keyes
c8223e1618 Merge #10995 'paste: fix paste in terminal mode' 2019-09-11 12:45:28 -07:00
Björn Linse
ffa029ad1c paste: fix paste in terminal mode 2019-09-11 20:12:29 +02:00
Justin M. Keyes
06bfb07e35 doc
fix #10127
fix #5972
2019-09-11 00:10:27 -07:00
Justin M. Keyes
456f1d4bdd doc: |api-fast| [ci skip] 2019-09-09 10:52:12 -07:00
Justin M. Keyes
05c668f684
paste: fix normal-mode paste by different approach #10976
Forcing insert-mode after the first paste-chunk seems to work, as an
alternative to a9e2bae0eb (insert-before-cursor).

NB: Dot-repeat needs to match the original action.  Since a9e2bae0eb
changed paste to insert-before-cursor, dot-repeat must also. But that
makes dot-repeat unpleasant/unusual.
2019-09-09 08:29:49 -07:00
Justin M. Keyes
a9e2bae0eb paste: insert before cursor always
Inserting "after" the cursor in Normal-mode, for big paste-streams, is
not reliable: sometimes the text "after" the cursor ends up in the
middle of the pasted text.  Maybe the cursor position is not updated?

To avoid weird behavior, always paste "before".  Maybe nvim_put() or
vim.paste() can be fixed more properly later.
2019-09-08 16:42:11 -07:00
Justin M. Keyes
acd2729573 paste: do not clobber msg area for small pastes 2019-09-08 15:37:32 -07:00
Justin M. Keyes
0dea44f93c paste/cmdline: discard all chunks after first line
Problem:  If multiple paste "chunks" are streamed, chunks after the
          first line are pasted into the buffer.
Solution: Check for cmdline-mode for all chunks in a paste-stream.
2019-09-08 15:37:32 -07:00
Justin M. Keyes
d91f4cd7d0
paste: reset 'paste' option immediately #10974
- Workaround #10966: 'paste' option is not always reset.
- In any case there's not much reason to wait until phase=3, because
  pasting in cmdline-mode skips lines after the first line (thus the
  `:set paste .. :set nopaste` dance happens only ~once).
2019-09-08 14:58:47 -07:00
Justin M. Keyes
8560bafc6c paste: redraw at end
Attempt to fix test failure since 976c6667e1 removed per-chunk redraw:

  ERROR test/functional/terminal/tui_spec.lua: TUI paste: cmdline-mode inserts 1 line
  test/functional/terminal/tui_spec.lua:367: in function <test/functional/terminal/tui_spec.lua:360
  Expected:
    |*foo                                               |
    |*                                                  |
    |{4:~                                                 }|
    |{4:~                                                 }|
    |{5:[No Name] [+]                                     }|
    |:"line 1{1:"}                                         |
    |{3:-- TERMINAL --}                                    |
  Actual:
    |*                                                  |
    |*{4:~                                                 }|
    |{4:~                                                 }|
    |{4:~                                                 }|
    |{5:[No Name] [+]                                     }|
    |:"line 1{1:"}                                         |
    |{3:-- TERMINAL --}                                    |
2019-09-02 03:34:01 +02:00
Justin M. Keyes
976c6667e1 paste: one undo-block per stream
- All "chunks" in a paste-stream should form a single undo-block. Side
  effect of 7a85792884 was to create an undo-block for each chunk.
- Also: remove old :redraw force logic, irrelevant after 7a85792884.
2019-09-02 02:27:13 +02:00
Justin M. Keyes
87389c6a57 paste: make vim.paste() "public" 2019-08-27 22:14:52 +02:00
Justin M. Keyes
5b41070c63 paste: implement redo (AKA dot-repeat)
- Normal-mode redo idiom(?): prepend "i" and append ESC.
- Insert-mode only needs AppendToRedobuffLit().
- Cmdline-mode: only paste the first line.
2019-08-27 22:13:45 +02:00
Justin M. Keyes
bfc5a18f4b paste: insert text "before" cursor in Insert-mode 2019-08-27 22:13:45 +02:00
Justin M. Keyes
eacc70fb3e API: nvim_paste 2019-08-27 22:13:45 +02:00
Justin M. Keyes
5ae6849517 paste: phases, dots
- Send `phase` parameter to the paste handler.
- Redraw at intervals and when paste terminates.
- Show "..." throbber during paste to indicate activity.
2019-08-27 21:19:10 +02:00
Justin M. Keyes
93e5f0235b API: nvim_put: "follow" parameter 2019-08-27 21:19:10 +02:00
Justin M. Keyes
5a2894d677 paste: use nvim_put() 2019-08-27 21:19:10 +02:00
Justin M. Keyes
f99caa755c paste: use chansend() in Terminal-mode 2019-08-27 21:19:10 +02:00
Justin M. Keyes
abd55be19a paste: fixup tests 2019-08-27 21:19:10 +02:00
Justin M. Keyes
4389401a7c paste: abort paste if handler does not return true 2019-08-27 21:19:10 +02:00
Justin M. Keyes
68ea9a7c8a TUI/paste: always flush on paste mode-change
Flush input before entering, not only when leaving, paste mode. Else
there could be pending input which will erroneously be sent to the paste
handler.
2019-08-27 21:19:10 +02:00
Justin M. Keyes
6d277f43a2 TUI/paste: define paste function as Lua builtin
- Define in Lua so that it is compiled-in (available with `-u NONE`).

TODO: Eventually we will want a 'pastefunc' option or some other way to
override the default paste handler.
2019-08-27 21:19:10 +02:00
Justin M. Keyes
7df566060c lua/stdlib: cleanup 2019-08-27 21:19:10 +02:00
Björn Linse
d33aaa0f5f libluv: use luv_set_callback to control callback execution
Disable the use of deferred API functions in a fast lua callback
Correctly display error messages from a fast lua callback
2019-06-30 13:13:08 +02:00
Justin M. Keyes
5b04a4fa09 lua/shared: share trim() impl 2019-05-20 23:46:56 +02:00
Justin M. Keyes
7cc01c704c Merge #9709 'fileio: use os_copy to create backups'
ref #8288
2019-05-20 22:33:19 +02:00
Justin M. Keyes
fab81cfb04 lua/shared: share more stuff
Leave trim() in vim.lua, because gen_vimdoc.py needs at least one
function in there, else it gets confused...
2019-05-19 18:31:40 +02:00
Justin M. Keyes
e4c2d85c77 lua/shared: share deepcopy() with test/*
deepcopy() was duplicated in test/helpers.lua
2019-05-19 17:58:54 +02:00
Justin M. Keyes
e628c011bf gen_vimdoc.py: support lua/shared.lua module [ci skip] 2019-05-19 17:30:20 +02:00
KillTheMule
53576dfb35 Document the vim.lua functions 2019-05-18 22:01:14 +02:00
Justin M. Keyes
bba75eb184 lua/stdlib: Introduce vim.shared
This is where "pure functions" can live, which can be shared by Nvim and
test logic which may not have a running Nvim instance available.

If in the future we use Nvim itself as the Lua engine for tests, then
these functions could be moved directly onto the `vim` Lua module.

closes #6580
2019-05-18 15:48:13 +02:00
Björn Linse
3a84e5be88 lua: expose full interface of vim.inspect and add test
Implement lazy loading for vim.submodule, this would be over-engineering
for inspect only, but we expect to use this solution also for more and
larger modules.
2019-01-14 20:12:57 +01:00
Justin M. Keyes
6c02ff4747 lua/stdlib: Load runtime modules on-demand
Instead of eager-loading during plugin/* sourcing, define runtime
modules such as `vim.inspect` as lazy builtins. Otherwise non-builtin
Lua modules such as `vim.inspect` would not be available during startup
(init.vim, `-c`, `--cmd`, …).

ref #6580
ref #8677
2019-01-14 02:22:16 +01:00
KillTheMule
bb3aa824b7 lua/stdlib: vim.inspect, string functions
ref #6580
ref #8677
2019-01-14 02:14:34 +01:00
Lucas Hoffmann
4d10024a56 API: Remove path prefix from command name in nvim_get_proc()
On macOS the output from `ps -o comm` might contain the full path of the
executable.  The `ucomm` would be the basename only but is less portable
(see previous commit).
2018-08-18 14:37:33 +02:00
Lucas Hoffmann
794e7b4359 API: Use ps -o comm in nvim_get_proc()
- The POSIX version of ps(1) only specifies "comm" for the "-o" option
  but not "ucomm".  See
  http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html
- On Linux (with the procps-ng package) "ucomm" is an alias for "comm".
  See https://gitlab.com/procps-ng/procps
- OpenBSD also has "ucomm" as an alias for "comm" (with the extra note
  "Name to be used for accounting."). See https://man.openbsd.org/ps
- FreeBSD describes "ucomm" as "Name to be used for accounting." but
  does not say that it should be an alias for "comm". See
  https://www.freebsd.org/cgi/man.cgi?query=ps
2018-08-15 12:39:10 +02:00
Justin M. Keyes
a034d4b69d API: nvim_get_proc()
TODO: "exepath" field (win32: QueryFullProcessImageName())

On unix-likes `ps` is used because the platform-specific APIs are
a nightmare.  For reference, below is a (incomplete) attempt:

diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c
index 09769925aca5..99afbbf290c1 100644
--- a/src/nvim/os/process.c
+++ b/src/nvim/os/process.c
@@ -208,3 +210,60 @@ int os_proc_children(int ppid, int **proc_list, size_t *proc_count)
   return 0;
 }

+/// Gets various properties of the process identified by `pid`.
+///
+/// @param pid Process to inspect.
+/// @return Map of process properties, empty on error.
+Dictionary os_proc_info(int pid)
+{
+  Dictionary pinfo = ARRAY_DICT_INIT;
+#ifdef WIN32
+
+#elif defined(__APPLE__)
+  char buf[PROC_PIDPATHINFO_MAXSIZE];
+  if (proc_pidpath(pid, buf, sizeof(buf))) {
+    name = getName(buf);
+    PUT(pinfo, "exepath", STRING_OBJ(cstr_to_string(buf)));
+    return name;
+  } else {
+    ILOG("proc_pidpath() failed for pid: %d", pid);
+  }
+#elif defined(BSD)
+# if defined(__FreeBSD__)
+#  define KP_COMM(o) o.ki_comm
+# else
+#  define KP_COMM(o) o.p_comm
+# endif
+  struct kinfo_proc *proc = kinfo_getproc(pid);
+  if (proc) {
+    PUT(pinfo, "name", cstr_to_string(KP_COMM(proc)));
+    xfree(proc);
+  } else {
+    ILOG("kinfo_getproc() failed for pid: %d", pid);
+  }
+
+#elif defined(__linux__)
+  char fname[256] = { 0 };
+  char buf[MAXPATHL];
+  snprintf(fname, sizeof(fname), "/proc/%d/comm", pid);
+  FILE *fp = fopen(fname, "r");
+  // FileDescriptor *f = file_open_new(&error, fname, kFileReadOnly, 0);
+  // ptrdiff_t file_read(FileDescriptor *const fp, char *const ret_buf,
+  //                     const size_t size)
+  if (fp == NULL) {
+    ILOG("fopen() of /proc/%d/comm failed", pid);
+  } else {
+    size_t n = fread(buf, sizeof(char), sizeof(buf) - 1, fp);
+    if (n == 0) {
+      WLOG("fread() of /proc/%d/comm failed", pid);
+    } else {
+      size_t end = MIN(sizeof(buf) - 1, n);
+      end = (end > 0 && buf[end - 1] == '\n') ? end - 1 : end;
+      buf[end] = '\0';
+      PUT(pinfo, "name", STRING_OBJ(cstr_to_string(buf)));
+    }
+  }
+  fclose(fp);
+#endif
+  return pinfo;
+}
2018-03-18 00:11:45 +01:00
Justin M. Keyes
12af7016e2 nvim_get_proc_children: fallback to shell
/proc/…/children may be unavailable because of an unset kernel option.
Fallback to `pgrep` invoked in a shell.
2018-03-16 10:55:12 +01:00
ZyX
a409fa2b3f lua: Use automatic determining of suffixes only for package.cpath 2017-05-28 23:55:51 +03:00
ZyX
97602371e6 lua: Add paths from &runtimepath to package.path and package.cpath 2017-05-25 16:27:40 +03:00
ZyX
f98a3d85ed lua: Move files from src/nvim/viml/executor to src/nvim/lua 2017-04-11 01:09:36 +03:00