mhinz / vim-startify

:link: The fancy start screen for Vim.
MIT License
5.31k stars 187 forks source link

Implement custom lists #288

Closed mhinz closed 6 years ago

mhinz commented 7 years ago

Currently we have a fixed number of list types, e.g. files, dir, session, etc.

It would be great if we'd allow custom lists. For that I'd like to extend g:startify_list_order:

let g:startify_list_order = ['custom list title', function('s:callback', ...) ]

" This function gets a list of recently used files and is free to return whatever it likes.
" It can also ignore a:entries entirely. It returns any list.
function! s:callback(entries)
  for entry in a:entries
    startify#register(...)
  endfor
endfunction

This could be used to for creating a new list that shows recently accessed repositories (by searching for .git and .hg directories from the directory of each entry upwards) etc.

g-i-o-r-g-i-o commented 6 years ago

I agree that having a configurable list at startup would considerably speed up my workflow.

mhinz commented 6 years ago

@GianniGi Could you give an example? What do you want to see at startup?

sanmiguel commented 6 years ago

I too would love to see custom lists for vim-startify!

A couple of lists I'd love are:

Above all though, I'd love to see what you suggested above - a way to define our own callbacks to populate a list with data from wherever we please. Then it's just a case of hooking up a function that calls out to e.g. octokit.rb (or one of the million python GH API libs) and handing it to vim-startify.

For specifying the config, I could imagine something such as:

let g:startify_list_order = [
  \ { 'name': 'github.com notifications',
  \    'function': function('s:list_github_notifications') },
  \ { 'name': 'notes',
  \    'function': function('s:list_notes') } ]

Where each of those callback functions returns a list of things that are a name and a command to run or something?

I got to thinking about this and realised that you could go one step further and, if we're currently in a git directory, and the remote matches a configured pattern (e.g. github.com or your-enterprise-gh.org) then show the pulls/issues for that repo... I don't know if that would prove to be useful but I feel like it might be.

mhinz commented 6 years ago

Okay.. since the old name g:startify_list_order is long out-of-date anyway, I introduced a new option g:startify_lists. That option does the same as the old one, but uses a different format.

If g:startify_list_order exists but not g:startify_lists, it gets converted to the new format automatically. I will mark g:startify_list_order as deprecated in the docs later.

Since we're using an undocumented new option, I pushed the code to master, since it won't break backward compatibility.

So, update the plugin and put this in your vimrc:

function! s:neovim_commits()
  let git = 'git -C /data/repo/neovim'
  let commits = systemlist(git .' log --oneline | head -n10')
  " use :Git from vim-fugitive
  let git = 'G' . git[1:]
  return map(commits, '{"line": v:val, "cmd": "'. git .' show ". matchstr(v:val, "^\\x\\+") }')
endfunction

let g:startify_lists = [
      \ { 'header': ['   Neovim commits'], 'type': function('s:neovim_commits') },
      \ { 'header': ['   MRU'],            'type': 'files' },
      \ { 'header': ['   MRU '. getcwd()], 'type': 'dir' },
      \ { 'header': ['   Sessions'],       'type': 'sessions' },
      \ { 'header': ['   Bookmarks'],      'type': 'bookmarks' },
      \ { 'header': ['   Commands'],       'type': 'commands' },
      \ ]

You probably have to adjust the function a bit, but it should explain the general approach.

The option requires a type key. The header key is optionally.

If the type key is a function, that function should return a list of dicts, whereas each dict requires a line and cmd key.

To make it clear, s:neovim_commits() returns this in my case:

[{'cmd': 'Git -C /data/repo/neovim show cca407b43',
  'line': 'cca407b43 DirChanged: support <buffer> (#8140)'},
 {'cmd': 'Git -C /data/repo/neovim show 0093c25dd', 'line': '0093c25dd doc: nodejs'},
 {'cmd': 'Git -C /data/repo/neovim show 338664e96',
  'line': '338664e96 node/provider: support g:node_host_prog #8135'},
 {'cmd': 'Git -C /data/repo/neovim show 5ce8158a5',
  'line': '5ce8158a5 vim-patch:8.0.0316: :help z? does not work (#8134)'},
 {'cmd': 'Git -C /data/repo/neovim show f5b0f5e17',
  'line': 'f5b0f5e17 Merge pull request #8127 from jamessan/update-pvs-headers'},
 {'cmd': 'Git -C /data/repo/neovim show e24e98534',
  'line': 'e24e98534 ci/AppVeyor: use PowerShell (#8124)'},
 {'cmd': 'Git -C /data/repo/neovim show 4e5e6506b',
  'line': '4e5e6506b pvscheck: Ignore exit code of pvs-studio-analyzer'},
 {'cmd': 'Git -C /data/repo/neovim show 8bd1bbcec',
  'line': '8bd1bbcec Add missing PVS headers to new files'},
 {'cmd': 'Git -C /data/repo/neovim show c7f95fde1',
  'line': "c7f95fde1 ci/travis: Don't destroy cache during prepare"},
 {'cmd': 'Git -C /data/repo/neovim show 241c380da',
  'line': "241c380da Merge #8117 'build/CI/MSVC/LuaRocks'"}]

(You can check :StartifyDebug to see what got registered exactly.)

Does it work for you? Do you miss anything?

sanmiguel commented 6 years ago

This all sounds fantastic and exactly what I was after. I'll try to give it a whirl tonight or over the weekend and let you know how it goes!

Thanks so much for such a comprehensive and swift answer! :+1:

On Fri, 16 Mar 2018, 15:40 Marco Hinz, notifications@github.com wrote:

Okay.. since the old name g:startify_list_order is long out-of-date anyway, I introduced a new option g:startify_lists. That option does the same as the old one, but uses a different format.

If g:startify_list_order exists but not g:startify_lists, it gets converted to the new format automatically. I will mark g:startify_list_order as deprecated in the docs later.

Since we're using an undocumented new option, I pushed the code to master, since it won't break backward compatibility.

So, update the plugin and put this in your vimrc:

function! s:neovim_commits() let git = 'git -C /data/repo/neovim' let commits = systemlist(git .' log --oneline | head -n10') " use :Git from vim-fugitive let git = 'G' . git[1:] return map(commits, '{"line": v:val, "cmd": "'. git .' show ". matchstr(v:val, "^\x\+") }')endfunction let g:startify_lists = [ \ { 'header': [' Neovim commits'], 'type': function('s:neovim_commits') }, \ { 'header': [' MRU'], 'type': 'files' }, \ { 'header': [' MRU '. getcwd()], 'type': 'dir' }, \ { 'header': [' Sessions'], 'type': 'sessions' }, \ { 'header': [' Bookmarks'], 'type': 'bookmarks' }, \ { 'header': [' Commands'], 'type': 'commands' }, \ ]

You probably have to adjust the function a bit, but it should explain the general approach.

If the type key is a function, that function should return a list of dicts, whereas each dict requires a line and cmd key.

To make it clear, s:neovim_commits() returns this in my case:

[{'cmd': 'Git -C /data/repo/neovim show cca407b43', 'line': 'cca407b43 DirChanged: support (#8140)'}, {'cmd': 'Git -C /data/repo/neovim show 0093c25dd', 'line': '0093c25dd doc: nodejs'}, {'cmd': 'Git -C /data/repo/neovim show 338664e96', 'line': '338664e96 node/provider: support g:node_host_prog #8135'}, {'cmd': 'Git -C /data/repo/neovim show 5ce8158a5', 'line': '5ce8158a5 vim-patch:8.0.0316: :help z? does not work (#8134)'}, {'cmd': 'Git -C /data/repo/neovim show f5b0f5e17', 'line': 'f5b0f5e17 Merge pull request #8127 from jamessan/update-pvs-headers'}, {'cmd': 'Git -C /data/repo/neovim show e24e98534', 'line': 'e24e98534 ci/AppVeyor: use PowerShell (#8124)'}, {'cmd': 'Git -C /data/repo/neovim show 4e5e6506b', 'line': '4e5e6506b pvscheck: Ignore exit code of pvs-studio-analyzer'}, {'cmd': 'Git -C /data/repo/neovim show 8bd1bbcec', 'line': '8bd1bbcec Add missing PVS headers to new files'}, {'cmd': 'Git -C /data/repo/neovim show c7f95fde1', 'line': "c7f95fde1 ci/travis: Don't destroy cache during prepare"}, {'cmd': 'Git -C /data/repo/neovim show 241c380da', 'line': "241c380da Merge #8117 'build/CI/MSVC/LuaRocks'"}]

Does it work for you? Do you miss anything?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mhinz/vim-startify/issues/288#issuecomment-373733718, or mute the thread https://github.com/notifications/unsubscribe-auth/ACBkRlryDdyoZFZF6PE3IETYRWxeI1lxks5te87HgaJpZM4N_v8s .

mhinz commented 6 years ago

It's now all documented under :h g:startify_lists.

Thanks for the feedback. This is a pretty neat feature!

sanmiguel commented 6 years ago

Thanks for putting it together! I'm looking forward to getting it up and running in anger... I had a quick play with it at the weekend but picked the wrong plugin to try to integrate, which turned out not to be as helpful as vim-startify. :) I might be back with more questions or requests once I've got a couple of things going with it....