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

different color for current and other paragraphs #34

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

different color for current and other paragraphs #34

Cutuchiqueno opened this issue Jun 30, 2014 · 10 comments

Comments

@Cutuchiqueno
Copy link

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
Copy link
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
Copy link
Author

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
Copy link
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
Copy link
Author

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
Copy link
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
Copy link
Owner

junegunn commented Jul 2, 2014

Please check out https://github.com/junegunn/limelight.vim 😃

@junegunn junegunn closed this as completed Jul 2, 2014
@sunaku
Copy link

sunaku commented Jul 2, 2014

Genius! 🙇

@Cutuchiqueno
Copy link
Author

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
Copy link
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
Copy link
Author

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
Projects
None yet
Development

No branches or pull requests

3 participants