junegunn / limelight.vim

:flashlight: All the world's indeed a stage and we are merely players

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Highlight sentence rather than paragraph?

josswright opened this issue · comments

I love using Limelight and Goyo for writing text, after initially discovering it through seeing iA Writer. In a recent look, though, I noticed that iA Writer seems to highlight each sentence rather than each paragraph. I haven't used it, but it seems intuitively more appealing to me.

Would it be possible for Limelight to highlight just the current sentence rather than the current paragraph?

#40 should offer a temporary workaround. Don't know why it was closed without any real solution.

Oh, I hadn't actually seen the limelight_bop and limelight_eop options. I imagine that I can do something with those!

I gave a try at the workaround but this cannot work in case of a very long sentence using soft wrapping (a situation often met when writing prose e.g using vim-pencil in SoftPencil mode).
It would be nice to define the highlighted line as a being only the characters on the display line on which the cursor is sitting.
Even nicer would be to have two levels of highlighting: super low for surrounding paragraphs, low for surrounding sentences (or better said display lines) and high for active display line.

@josswright @jfmoulin I really wanted this, so I spent the last few days getting it to work. I've got the changes up on my fork of the project, but sometime I'll polish it up enough to submit a pull request here. The way I built it, I didn't leave any of the paragraph stuff in because I don't personally want that, but I'm sure the maintainer here doesn't want only sentences.

Here is a view of mine:

screen shot 2018-11-30 at 9 03 44 pm

Hi! @josswright, did you have a chance to proceed with this?
I'am pretty eager to have a look at this when I am back of my holiday ;0)

Hi @jfmoulin -- I think that @ekaj2 was the one who had actually done something practical. I don't think I've tried their fork, but the screenshot looks exactly like the kind of thing I was imagining. It would be great to see this included, as I'm still very much using limelight for my writing.

joining back late...
@josswright ,thanks for answering my misaddressed question!
So after this while I feel I'll ask again, the right person this time!
Hi @ekaj2 , any progress?
;0)

Ooops. sorry I just gave my own old comment a smile.... anyway to un-smile?

Just following up here. As far as I can tell from looking at the code, limelight is currently built entirely around highlighting lines. I don't know much vimscript at all, but it looks like it would take a bit of work to make it highlight sentences correctly.

I'm interested to start looking at it, but it will involve learning vimscript from scratch, so if anyone more familiar with this code can give more of an idea then I'd be interested!

@josswright Not sure if you forgot about my fork that gets 95% of the way there...I still use this on a regular basis for myself and just don't think the remaining 5% is worth the hassle for me any longer: https://github.com/ekaj2/limelight.vim

Oh, sorry @ekaj2. I think I got this confused with the fork that lets you define a region via movement commands, but that can't do per-sentence highlighting due to the need to highlight the entire line. Assuming your version does that, I'll happily skip over to your fork and give it a try!

Is there anything special to do to get per-sentence highlighting working?

@ekaj2: I've just had a quick look. It's definitely highlighting partial lines, and seems never to highlight beyond the end of a sentence, but in almost all cases it's not correctly highlighting sentences when I move the cursor over them. (The actual highlighting behaviour I'm seeing is hard to describe, so I haven't gone into it here. Happy to write up a fuller report if needed, though.)

It looks so close to being there, though!

@josswright For most cases, proper punctuation will do, but I've not implemented everything for sure. I think it works in most cases though, as long as it is normalish prose I guess:

ezgif-2-3cabf88f56ec

@ekaj2 I think I've realised the problem. The file(s) that I've tried have hard linebreaks. It works pretty much perfectly on files without linebreaks. Here's a demonstration of a file with hard linebreaks.

limelight

Assuming this isn't an easy fix, it's already a fairly great improvement over my previous setup. If there is a way to handle hard linebreaks, though, that would be amazing. (I may have a poke at it myself, so a pointer to the best place to look would be really helpful, assuming this isn't something you plan on doing.)

@josswright I don't think that is possible IIRC, but you should look at my changes here to get the main idea: ekaj2@80b028b.

Essentially you use searchpos to find the column of a line that has a match for begin_punc or eop and that position is called start and end respectively.

This line will then convert to allow for word wrapping or whatever IIRC:

   let punc_found = s:GetVirtualCol(searchpos(begin_punc, 'bW'))

This will be something else that would probably need to be changed:

  " make sure that they are both on the same line
  if end[0] <= start[0] + 1
      " see above note
      let end[1] = virtcol('.')
      call setpos('.', pos)
  else
      call setpos('.', pos)
      let end = [start[0], virtcol('.')]
  endif

You will also need to have a new way of handling paragraphs (double newline) which I don't know is possible...

I don't know that the searchpos will let you search across multiple lines, but you may be able to search with another function to get the line, then position cursor on that line and then use searchpos.

That said, you could also just write with everything on the same line per paragraph and type gqq to auto hardwrap. If you then want the spaces between everything, there's probably a ton of ways to do so, but you could just do a macro something like: qqo<esc>j and then execute with: 9999@q or VG:norm @q.