hadronized / hop.nvim

Neovim motions on speed!
Other
2.48k stars 137 forks source link

Docs: hint_with_callback example #202

Open smackesey opened 2 years ago

smackesey commented 2 years ago

I tried for some time to get hint_with_callback to work and kept running into errors. From the docs, it was unclear to me which of these I was supposed to do-- I ended up trying them all until I got the working one. I suggest adding a simple example:

local hop, hopjt = require('hop'), require('hop.jump_target')
local cb = function (target) print(target.line) end

-- option (1) -- FAIL
hop.hint_with_callback(
  hopjt.jump_targets_by_scanning_lines,
  hopjt.regex_by_word_start(),
  cb
)

-- option (2) -- FAIL
hop.hint_with_callback(
  hopjt.jump_targets_by_scanning_lines,
  hopjt.regex_by_word_start,
  cb
)

-- option (3) -- FAIL
hop.hint_with_callback(
  hopjt.jump_targets_by_scanning_lines(hopjt.regex_by_word_start()),
  {},
  cb
)

-- option (4) -- FAIL
hop.hint_with_callback(
  hopjt.jump_targets_by_scanning_lines(hopjt.regex_by_word_start),
  {},
  cb
)

-- option (5) -- OK
hop.hint_with_callback(
  hopjt.jump_targets_by_scanning_lines(hopjt.regex_by_word_start),
  nil,
  cb
)
hadronized commented 2 years ago

What kind of errors do you get?

smackesey commented 2 years ago

This was months ago, so I don't recall, but I stand by my suggestion to provide an example along the lines of option (5).