Skip to content
This repository was archived by the owner on Oct 6, 2024. It is now read-only.

Asynchronous and automatic pathfinding#13

Merged
danth merged 11 commits intomasterfrom
automatic-run
May 31, 2020
Merged

Asynchronous and automatic pathfinding#13
danth merged 11 commits intomasterfrom
automatic-run

Conversation

@danth
Copy link
Copy Markdown
Owner

@danth danth commented May 30, 2020

  • Run pathfinding in the background without blocking Vim
  • Run pathfinding automatically when the cursor moves
  • Display results in a popup window
  • Update README.md with new information

Closes #12

danth added 2 commits May 29, 2020 13:47
Do pathfinding in a subprocess which runs a "server" within a stripped-down,
plugin-free Vim. This increases the speed of pathfinding significantly.
It also leaves the user's cursor alone, and doesn't block - so they may
continue working. This is necessary to implement #12.

The client is responsible for launching and connecting to the server.
The server will shut down it's Vim process when the client disconnects.

The server starts using a custom vimrc (serverrc.vim), which disables
unnecessary features like syntax highlighting and other plugins.
pathfinder.vim checks for the existance of a g:pf_server_communiation_file
variable (which the client sets using --cmd), if that exists it starts in
server mode, otherwise it starts in client mode.

Communication between the client (user's Vim) and server (subprocess Vim)
happens with a temporary file and multiprocessing.connection classes.
The current buffer contents, g:pf_motions setting, scrolloff setting, start
and target positions and the window size are transferred to the server
before each pathfinding request. The window size is restored using
&lines and &columns, meaning the surrounding windows don't need to be
transferred.
@danth danth added the feature A new feature or a feature request label May 30, 2020
@danth danth self-assigned this May 30, 2020
danth added 3 commits May 30, 2020 13:01
Pathfinding runs when...
- The cursor has not moved for a configurable (g:pf_autorun_delay) time
  (default 2 seconds)
  > End position is the current cursor position
- An edit (x,rx,p etc.) was made in normal mode
  > End position is the position just before the edit
- Switching modes from normal, visual or visual-line
  > End position is the position just before switching modes

The start position is wherever the cursor was after...
- The pathfinder last ran
- Switching window or tab
- Opening a file or an empty buffer
- Loading a session
reset()


def loop():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function loop has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

danth added 5 commits May 30, 2020 17:58
Must have accidentally deleted this
If Vim has +popupwin (available in 8.2), use that to display the full
output in a box at the bottom of the screen.

Otherwise, display a single-line compact form using echo. (Having only
one line prevents a "press enter" prompt from appearing.)
This causes the history from the user's Vim to be deleted.
Increase the time the popup is shown for when it has a lot of lines, so
that it doesn't disappear too fast for the user to read it.

Suggestion: make this configurable.
@danth danth marked this pull request as ready for review May 30, 2020 23:53
Copy link
Copy Markdown
Owner Author

@danth danth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works!

@danth danth merged commit 7dc5ad1 into master May 31, 2020
@danth danth deleted the automatic-run branch May 31, 2020 08:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature A new feature or a feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make PathfinderBegin and PathfinderRun automatic

1 participant