Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin: desk #40

Closed
ratmav opened this issue Nov 17, 2020 · 32 comments
Closed

plugin: desk #40

ratmav opened this issue Nov 17, 2020 · 32 comments
Assignees
Labels

Comments

@ratmav
Copy link
Owner

ratmav commented Nov 17, 2020

minimal plugin for more conventional (to me) project workspace management. leans on tabs and logic from other plugins (give them a shoutout in the readme), this just bundles them all up nicely and limits options so i don't step on my own feet.

desk -> single nvim instance
book -> vim tab (book on desk)
page -> vim buffer (page in book)

Bindings:

  • Ctrl-d-n: new book
  • Ctrl-d-l: next book
  • Ctrl-d-h: previous book
  • Ctrl-d-c: refreshes list of files in search
  • Ctrl-d-f: tab-scoped fuzzy file name search
  • Ctrld-d-t: simple tree view, hjkl navigation. "Enter" opens file in buffer. that's all (nerdtree)
  • Ctrl-d-r: renames book (vim-ctrlspace)
  • Ctrl-d-q: closes book (vim-ctrlspace)
  • Ctrl-d-m: moves book (vim-bufkill)
  • Ctrl-d-g: greps file content (not buffer or file name), using the silver searcher (need to investigate).

dependencies (to be forked and pulled in as needed):

  • vimctrlspace
    • tab-scoped file name search (avoid go binary, try using glob and/or CtrlP logic w/ ignore rules)
  • nerdtree
    • simple tree view; only need "Enter" to open file in buffer, really.
  • vim-buffkill
    • probably necessary to keep tab/window around when moving a desk, since move wipes open desk buffers.

desk sets these as default keybindings, probably using viml commands

@ratmav
Copy link
Owner Author

ratmav commented Nov 17, 2020

for now, just lean on the various plugins defined above and set the keybindings to see how they feel. will have to add ctrlp back and confirm that it respects the tab container that vim-ctrlspace sets up.

once that's done move ctrl-t to starting a terminal; leave leader t alone.

@ratmav
Copy link
Owner Author

ratmav commented Nov 19, 2020

ok, after getting your current keybindings using the other plugins close to this, the first step is probably figuring out how Ctrl-d-n is going to work. do a step at a time: open the tab, then name the tab, then scope buffers by tab.

@ratmav
Copy link
Owner Author

ratmav commented Nov 20, 2020

Ctrl-d-n was overloaded with new desk and name desk. going with ctrl-d-c for "create desk" and ctrl-d-n for name desk.

@ratmav
Copy link
Owner Author

ratmav commented Nov 20, 2020

ctrlp file search respects the vim-ctrlspace tab container, but the buffer search does not. oh well, looks like vim-ctrlspace has it's own fuzzy search.

@ratmav
Copy link
Owner Author

ratmav commented Nov 20, 2020

this will need os detection for the local desk project script runner. already in init.vim, but here's the vimscript for reference:

" os detection.
if has("win64") || has("win32") || has("win16")
    let s:vimfiles = "~/AppData/Local/nvim"
    let s:os = "windows"
else
    let s:vimfiles = "~/.config/nvim"
    if has("mac")
      let s:os = "darwin"
    else
      let s:os = "linux"
    endif
endif

function! LocalDeskProject()
  " set platform-specific extension
  if s:os == "windows"
    let extension = "ps1"
  else
    let extension = "sh"
  endif
  let project_script = "./.desk." . extension

  " run the script if it exists
  if filereadable(project_script)
    :execute ":! " . project_script
  else
    echo "local project script not found"
  endif
endfunction

@ratmav
Copy link
Owner Author

ratmav commented Nov 20, 2020

this looks super useful for containing buffers to a tab, i wouldn't be surprised if it was this simple in vim-ctrlspace:

Windows live in tabs and they can show any buffer. A buffer can be shown in more than one window across multiple tabs. But you can build a quick buffer switcher from a simple mapping:

nnoremap gB :ls<cr>:buffer<space>
From the documentation:

To get a list of all buffers in all tabs use this:

let buflist = []
for i in range(tabpagenr('$'))
    call extend(buflist, tabpagebuflist(i + 1))
endfor
Note that a buffer may appear in more than one window.

@ratmav
Copy link
Owner Author

ratmav commented Nov 20, 2020

got the tab rename to work by reaching into vim-ctrlspace and calling redraw. next up is to make C-d-c ask for a path (with tab to complete), then set tcd to that path, and set the tab name to the last dir on that path.

@ratmav
Copy link
Owner Author

ratmav commented Nov 20, 2020

the vim-ctrlspace fuzzy file search needs to ignore stuff like the .git, vendor, and node_modules dirs. here's the old ctrlp ignore:

set wildignore+=*/tmp/*,*.so,*.swp,*.zip
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe
"  ignore git metadata and (go, node.js) dependencies
let g:ctrlp_custom_ignore = {
  \ 'dir':  '\v[\/]\.(git)|(vendor|node_modules)$',
  \ }

@ratmav
Copy link
Owner Author

ratmav commented Nov 23, 2020

Ctrl-d-z is now Ctrl-w-z for zooming windows via the vim-maximizer plugin.

@ratmav
Copy link
Owner Author

ratmav commented Nov 25, 2020

made some progress on DeskNew(): can create the tab and set a static tab current directory (tree view, file search, and buffer search work). still need to figure out how to grab tcd path from user (with path autocomplete) and how to set the new tab/desk name.

@ratmav
Copy link
Owner Author

ratmav commented Nov 25, 2020

taboo looks like it's got some handy tab open and set the name tricks.

@ratmav ratmav added vim and removed enhancement labels Nov 26, 2020
@ratmav
Copy link
Owner Author

ratmav commented Nov 27, 2020

made some progress on the new desk function. found that it'd be nice to set the first tab to the tcd/cd on vim startup. might be able to do that by writing a function to get the tcd/cd, then set the tab name and call redraw at the bottom of vimrc. it would be nice for the plugin to do that automatically at startup, without users having to modify their vim config.

one way to do this might be for the plugin to have it's own startup script, which renames the tab and calls redraw, but until this gets pulled out into it's own plugin maybe just hacking init.vim will be ok.

@ratmav
Copy link
Owner Author

ratmav commented Nov 27, 2020

i think what i'll do from here on is:

  1. wire up the keybdingings in init.vim to get things going to validate the workflow (just lean on nerdtree and vim-ctrlspace search as is for now before hacking on those): desk close, tree and buffer refresh.
  2. move over to marv to pull that out into a plugin and get that project in order just to learn how all that's done (vint, github action, license, etc.)
  3. fork vim-ctrlspace, nerdree, ctrlp.
  4. use forks to start entirely new plugin repo for desk.

@ratmav
Copy link
Owner Author

ratmav commented Nov 27, 2020

a question worth investigating: if nerdtree already has logic to search tcd, and you can hack ctrlp to only search tcd, then is vim-ctrlspace even necessary? let's find that out before the items listed above.

also, some housekeeping: don't forget to update the readme with the appropriate keybindings in the is-ag-necessary branch, where most of this work has been happening.

@ratmav
Copy link
Owner Author

ratmav commented Nov 27, 2020

ctrlp doesn't seem to search buffers based on the tcd, so i might be better to just hack on vim-ctrlspace's file and buffer search. that said, it'd be nice if the vim-ctrlspace search just used native vimscript instead of a go binary. can probably use at least some logic from ctrlp and glob to get that going. ok, going to move back to the todo list.

@ratmav
Copy link
Owner Author

ratmav commented Nov 27, 2020

ok, new todo list:

  1. finish out search wrapper functions/keybindings
  2. suppress vim-ctrlspace popup on desk close
  3. tree and search refresh
  4. marv
  5. fork vim-ctrlspace and nerdtree
  6. start on desk, using forks for reference.

@ratmav
Copy link
Owner Author

ratmav commented Nov 28, 2020

calling ctrlspace#tabs#CloseTab() closes all the windows and associated buffers (:q, tabclose, etc. leave the buffers around), but pops a dialog window at the bottom. going to try and sort that.

@ratmav
Copy link
Owner Author

ratmav commented Nov 28, 2020

meh. the popup is just asking what buffer you want to look at in the previous (re: left) tab after closing a tab. that's fine.

@ratmav
Copy link
Owner Author

ratmav commented Nov 28, 2020

there's a quirk with vim-ctrlspace's file search, where it tries to find a project root using .git, .svn, etc. and then index. trying to set it to tcd via DeskInit doesn't have much effect. might be worth fixing in the actual desk plugin. to reproduce:

  1. start nvim in a dir that's not a git repo, etc.
  2. Ctrl-d-f
  3. get "project root not set" error.

@ratmav
Copy link
Owner Author

ratmav commented Nov 28, 2020

ok, we've got a quirk in the last comment, the ctrlspace popup on tab close is actually potentially useful, and tree/search refresh are mapped. that leaves:

  1. marv (reading learn vimscript the hard way)
  2. fork
  3. hack desk into it's own plugin and remove deps on nerdtree and vim-ctrlspace.

@ratmav
Copy link
Owner Author

ratmav commented Nov 30, 2020

reading through vimscript the hard way, and thinking about desk, i have file name search, buffer name search, but i don't have a good file or buffer content search. ag might be a good tool for that (cross platform), using vimscript to leverage ag output and the quickfix window.

also want the search scoped to the desk current directory. here's some logic for toggling the quickfix window:

function! ToggleQuickfix()
  let l:nr =  winnr("$")
  if l:nr == 1
      copen
  else
      cclose
  endif
endfunction

@ratmav
Copy link
Owner Author

ratmav commented Nov 30, 2020

got to chapter 42 this weekend, right where plugins start to get covered. learned a good bit. want to get through this last part then package marv.

@ratmav
Copy link
Owner Author

ratmav commented Dec 2, 2020

got a scaffold up for marv. honestly most of it's there, just need to iron out the kinks and get it functional.

@ratmav
Copy link
Owner Author

ratmav commented Dec 3, 2020

having tab-scoped (re: desk local) :bn and :bp and mapping to Ctrl-b-l and Ctrl-b-h respectively would own.

@ratmav ratmav changed the title plugin: desk plugin: spec Dec 5, 2020
@ratmav ratmav self-assigned this Dec 5, 2020
@ratmav ratmav changed the title plugin: spec plugin: specs Dec 11, 2020
@ratmav ratmav changed the title plugin: specs plugin: drift Dec 11, 2020
@ratmav ratmav changed the title plugin: drift plugin: desk Dec 11, 2020
@ratmav
Copy link
Owner Author

ratmav commented Dec 11, 2020

hmmm...alright. some modeling:

  • "desks" are a layer on tabs.
  • "pages" (files on a desk), are a layer on buffers

just thinking about this as a way to name classes/functions/state containers in the future.

@ratmav
Copy link
Owner Author

ratmav commented Dec 12, 2020

having a buffer name search and a file name search feels redundant. maybe it's the way the vim-ctrlspace search works, but the Ctrl-d-f finds the file, and will switch to a buffer if it's already open. that's...probably more than enough, esp. once :bn and :bp allow moving across desk buffers (not vim instance buffers)

that said, having a Ctrl-d-c for a file content search (via pt or ripgrep or whatever or just plain grep; all with good ignore rules like git grep or ctrl-p's rules for avoiding local dependency directories) sounds...rad.

@ratmav
Copy link
Owner Author

ratmav commented Dec 12, 2020

yeah, went ahead and removed the buffer name search.

@ratmav
Copy link
Owner Author

ratmav commented Dec 12, 2020

lol and just noticed that for some reason the vim-ctrlspace search doesn't search the autoload dir in vim plugins. sigh. lol probably better to gut that go search and try to just use whatever ctrlp does, probably with glob.

@ratmav
Copy link
Owner Author

ratmav commented Dec 19, 2020

desk grep: Ctrl-d-g calls a go bin that wraps pt and asks for a search string, then passes in the exact search term to pt, search is opened in location window, jk to move up and down location window, enter to open file in buffer. search bin is local and built per arch. os detection calls the correct bin.

@ratmav
Copy link
Owner Author

ratmav commented Dec 27, 2020

removing the desk task runner logic; just use https://github.com/gulien/orbit

@ratmav
Copy link
Owner Author

ratmav commented Dec 27, 2020

also, instead of buffers, name them "pages" when in a desk scope. that would make projects...books, so tabs are "books."

@ratmav
Copy link
Owner Author

ratmav commented Feb 15, 2021

goneovim (new branch), will take care of this, and is worth it because it not only provides workspaces, it also allows connections to remote nvim instances.

@ratmav ratmav closed this as completed Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant