Commit Graph

166 Commits

Author SHA1 Message Date
Thiago de Arruda
34c48aaf12 memory: Add free wrapper and refactor project to use it
We already use wrappers for allocation, the new `xfree` function is the
equivalent for deallocation and provides a way to fully replace the malloc
implementation used by Neovim.
2015-04-13 08:22:44 -03:00
Michael Reed
5b390395e6 Merge pull request #2404 from Pyrohh/coverity-108870
[RFC] coverity/108870: Missing break in switch
2015-04-11 18:05:06 -04:00
Marco Hinz
0e65962a68 Remove all references to JobActivity
The JobActivity event got replaced by callback functions provided to
jobstart() or termopen().

It got removed here:

6e7757ad51
2015-04-11 18:32:18 +02:00
Michael Reed
98f976b861 coverity/108870: Missing break in switch 2015-04-10 22:12:29 -04:00
Alexey Shmalko
6139c72251 coverity/{108271,108272,108273}: add fallthrough annotation #2362
Signed-off-by: Michael Reed <m.reed@mykolab.com>
2015-04-10 02:05:48 -04:00
Marco Hinz
cd7b910e81 Add new highlight groups TermCursor/TermCursorNC
These highlight groups replace the old mechanism of setting:

  - {g,b}:terminal_focused_cursor_highlight
  - {g,b}:terminal_unfocused_cursor_highlight
2015-04-09 16:38:32 +02:00
Scott Prager
e1bac3b840 Merge pull request #2346 from splinterofchaos/fix-terminal
[RFC] terminal: Handle loss of focus in event loop.
2015-04-08 12:27:52 -04:00
Eliseo Martínez
af8adc2d8c Fix warnings: terminal.c: get_config_int(): Dead init: RI.
Problem    : Dead initialization @ 1119.
Diagnostic : Real issue.
Rationale  : `obj` is immediately assigned another value through
             GET_CONFIG_VALUE macro.
Resolution : Don't initialize.

Helped-by: oni-link <knil.ino@gmail.com>
2015-04-07 20:04:34 -04:00
Eliseo Martínez
1b4dbdf45b Fix warnings: terminal.c: get_config_string(): Dead init: RI.
Problem    : Dead initialization @ 1109.
Diagnostic : Real issue.
Rationale  : `obj` is immediately assigned another value through
             GET_CONFIG_VALUE macro.
Resolution : Don't initialize.

Helped-by: oni-link <knil.ino@gmail.com>
2015-04-07 20:04:33 -04:00
Eliseo Martínez
3465a945e1 Fix warnings: terminal.c: redraw(): Np dereference: RI.
Problem    : Dereference of null pointer @ 1053.
Diagnostic : Real issue.
Rationale  : Branch "Exiting focused terminal" can actually be executed
             when term is NULL.
Resolution : Guard branch with term check.
2015-04-07 20:04:33 -04:00
Scott Prager
8cac2eea75 term: ensure term->buf is valid
The fallowing test (reduced), submitted by @mhinz may free term->buf,
leaving the pointer dangling.

```vim
let s:buf  = -1

function! s:exit_handler()
  execute 'bdelete!' s:buf
endfunction

vnew
let s:buf = bufnr('%')
let id = termopen('sleep 1', { 'on_exit': function('s:exit_handler') })

call s:test()
```

When the buffer is known to be closing, set term->buf to NULL, and check
buf_valid() in on_refresh().

Helped-by: Marco Hinz (@mhinz)
2015-04-07 16:05:00 -04:00
Scott Prager
013bd4461d term: use window col offset to calculate width
fixes #2317
2015-04-05 16:07:54 -04:00
Scott Prager
b8ae09b3cf term: after <C-\>, resume normal input loop
Pressing <C-\> and then a mouse click will insert the click into the
terminal as if a keyboard button had been pressed.

Keep track of whether the last input was <C-\> and only call
terminal_send_key() if the next input is a key press.
2015-04-05 13:40:21 -04:00
Scott Prager
b6296f4e84 terminal: Handle loss of focus in event loop.
While in a terminal and insert mode, if an event caused loss of focus,
nvim would stay in the terminal event loop causing an inconsistent view
of internal state and/or segfault.

Remove the "term" argument from terminal_enter() as it only makes sense
to call it with curbuf->terminal. Terminate the loop when switched to a
different buffer.

fixes #2301
2015-04-05 13:39:55 -04:00
Michael Reed
00e1b62ca8 Modeline cleanup
If users want folds to be automatically collapsed, then they should just
set foldmethod=marker in their vimrc.
2015-03-31 16:56:41 -04:00
Thiago de Arruda
cdedd89d22 terminal: New module that implements a terminal emulator
This commit integrates libvterm with Neovim and implements a terminal emulator
with nvim buffers as the display mechanism. Terminal buffers can be created
using any of the following methods:

- Opening a file with name following the "term://[${cwd}//[${pid}:]]${cmd}"
  URI pattern where:
  - cwd is the working directory of the process
  - pid is the process id. This is just for use in session files where a pid
    would have been assigned to the saved buffer title.
  - cmd is the command to run
- Invoking the `:terminal` ex command
- Invoking the `termopen` function which returns a job id for automating the
  terminal window.

Some extra changes were also implemented to adapt with terminal buffers. Here's
an overview:

- The `main` function now sets a BufReadCmd autocmd to intercept the term:// URI
  and spawn the terminal buffer instead of reading the file.
- terminal buffers behave as if the following local buffer options were set:
  - `nomodifiable`
  - `swapfile`
  - `undolevels=-1`
  - `bufhidden=hide`
- All commands that delete buffers(`:bun`, `:bd` and `:bw`) behave the same for
  terminal buffers, but only work when bang is passed(eg: `:bwipeout!`)
- A new "terminal" mode was added. A consequence is that a new set of mapping
  commands were implemented with the "t" prefix(tmap, tunmap, tnoremap...)
- The `edit` function(which enters insert mode) will actually enter terminal
  mode if the current buffer is a terminal
- The `put` operator was adapted to send data to the terminal instead of
  modifying the buffer directly.
- A window being resized will also trigger a terminal resize if the window
  displays the terminal.
2015-03-25 18:57:35 -03:00