different color for current and other paragraphs #34

Closed
Cutuchiqueno opened this Issue Jun 30, 2014 · 10 comments

Projects

None yet

3 participants

@Cutuchiqueno

One feature which was always a killer feature for me personally of distraction free writing environments was the usage of different font colors for the paragraph in which the cursor is operating and the other paragraphs. Normally it works the way that the paragraph with the cursor (in which I am writing) maintains the normal font color while the other paragraphs turn into a grey that does not raise attention anymore.

I wonder if it is possible to implement something like this by using the conceal feature or cursorline feature?

@junegunn
Owner

Hi, thanks for the suggestion. I'm not sure if it's in the scope of Goyo.vim, but it's an interesting idea.

Here's a prototype implementation of it (for 256-color terminal Vim):

function! s:dim_the_rest()
  let curr = [line('.'), line('$')]
  if curr ==# s:dtr_prev[0 : 1]
    return
  endif

  let paragraph_range = [searchpos('^$', 'bnW')[0], searchpos('^$', 'nW')[0]]
  if paragraph_range ==# s:dtr_prev[2 : 3]
    return
  endif

  while !empty(s:dtr_match_ids)
    silent! call matchdelete(remove(s:dtr_match_ids, -1))
  endwhile
  call add(s:dtr_match_ids, matchadd('Dim', '\%<'.paragraph_range[0].'l'))
  if paragraph_range[1] > 0
    call add(s:dtr_match_ids, matchadd('Dim', '\%>'.paragraph_range[1].'l'))
  endif
  let s:dtr_prev = extend(curr, paragraph_range)
endfunction

augroup dim_the_rest
  autocmd!
  if !exists('s:dtr_match_ids')
    let s:dtr_match_ids = []
  endif
  if !exists('s:dtr_prev')
    let s:dtr_prev = [0, 0, 0, 0]
  endif
  let fg = synIDattr(synIDtrans(hlID('Normal')), 'fg')
  execute 'hi Dim ctermfg=' . (fg + (&background == 'dark' ? -10 : 10))
  autocmd CursorMoved,CursorMovedI <buffer> call s:dim_the_rest()
augroup END

What do you think about it? And do you think it makes sense to add this feature to Goyo? Another option is to bake it into a separate plugin so that it can be used with or without Goyo.

@Cutuchiqueno

whow, thx for this quick and beatiful reaction.

I put your code into my .vimrc. Unfortunately, I get an error message during the start:

Fehler beim Ausführen von "/home/cutuchiqueno/.vimrc":
Zeile  112:
E421: Unbekannte Farbbezeichnung oder -Nummer: ctermfg=-3
Betätigen Sie die EINGABETASTE oder geben Sie einen Befehl ein

Line 112 refers to:

execute 'hi Dim ctermfg=' . (fg + (&background == 'dark' ? -10 : 10))

I use terminal vim in rxvt_unicode with t_Co=256 enabled.

I am also not capable to call a function dim_the_rest() / s:dim_the_rest() /#dim_the_rest() afterwards. Is there something I do wrong?

Concerning the question if it fits into the scope of goyo, well, I think the answer can only be subjective. I raised this issue because I have seen it in other distraction free writing environments. Hence, I would argue that it's part of the distraction free writing idea. Furthermore, when you write also free text and not only code as I do it definitely helps you focus on your paragraph and that means less distraction.

My suggestion would be to include id into Goyo but make it toggable with a variable.

@junegunn
Owner
junegunn commented Jul 1, 2014

Thanks for the feedback. Sorry, the code is incomplete and may not work depending on the color scheme, so don't sweat it.

It looks like this:

dim

I agree that this concept goes well with Goyo, but I feel that there's value in making it a separately accessible plugin. It is possible that one might want to enable it without centering the window using Goyo. I could add a command for toggling it, but I was a little proud of Goyo for being single-commanded. 😏
And it would be trivial to enable it in Goyo using before/after callbacks.

@Cutuchiqueno

The demonstration looks great, exactly what I had in mind.

I absolutely appretiate the single-command enthusiasm ;-) and also the value the feature might have out of a distraction free view.

The only point to make would be that it should be easy to integrate with Goyo, not necessarily by a new command but by a variable that if flaged makes Goyo look for the existence of this other PlugIn in the vim environment and use it. Similar like the vim-pandoc-after approach that does the same for non vim-pandoc plugins in the context of vim-pandoc (https://github.com/vim-pandoc/vim-pandoc-after). This would leave the idea of an extra plugin and a single command Goyo untouched.

@junegunn junegunn added the enhancement label Jul 1, 2014
@junegunn
Owner
junegunn commented Jul 1, 2014

Actually I was thinking about not changing Goyo at all since it's already possible to toggle other plugins with g:goyo_callbacks

function! GoyoBefore()
  " Turn it on
endfunction

function! GoyoAfter()
  " Turn it off
endfunction

let g:goyo_callbacks = [function('GoyoBefore'), function('GoyoAfter')]

Tightly integrating the two plugins should make it slightly easier to set them up, but I believe we're better off without unnecessary coupling.

@junegunn
Owner
junegunn commented Jul 2, 2014
@junegunn junegunn closed this Jul 2, 2014
@sunaku
sunaku commented Jul 2, 2014

Genius! 🙇

@Cutuchiqueno

Amazing! It works for me with conceal since my color theme (base16) is not supported by the default method, but still great and exactly what I missed in all the other distraction free writing plugins for vim.

Thx.

@junegunn
Owner
junegunn commented Jul 2, 2014

Thanks for the feedback. I've updated Limelight to cover a few more cases, so now it might work with those as well. Try it if you have time. (But the automatic color interpolation can give suboptimal result on a customized terminal palette, so it's not a bad idea to manually define conceal value even if it's supported)

@Cutuchiqueno

That's cool! I will post testing issues at the Limelight repository in case there are issues. Althogh there is another possible enhancement in the context of distractionfree writing for which I don't know at the moment to which repository it should belong. As it's somehow connected to spacial focusing open it at Limelight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment