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

Customise pprint function #406

Open
SevereOverfl0w opened this issue Nov 25, 2022 · 2 comments
Open

Customise pprint function #406

SevereOverfl0w opened this issue Nov 25, 2022 · 2 comments

Comments

@SevereOverfl0w
Copy link
Contributor

Currently it's hardcoded to puget, it would be nice to customise it (e.g. for zprint)

@frenchy64
Copy link
Contributor

frenchy64 commented Oct 19, 2023

I think it's fipp now. I found more discussion here: cb124b8

fipp is causing me minor issues, also would be nice to have the option to switch to something more extensible (clojure.pprint).

AFAIU the issue is how to abstract over the following lines via configuration:

let a:msg['nrepl.middleware.print/print'] = 'cider.nrepl.pprint/fipp-pprint'
let a:msg['nrepl.middleware.print/options'] = {}
if a:width > 0
let a:msg['nrepl.middleware.print/options'].width = a:width
endif

@SevereOverfl0w
Copy link
Contributor Author

The solution that seems most flexible to me is a callback function (mirrored to tagfunc, etc.) with defaults built-in:

function! fireplace#pprint_puget(msg, width, ...)
  if fireplace#op_available('info')
    let a:msg['nrepl.middleware.print/print'] = 'cider.nrepl.pprint/puget-pprint'
    if a:0
      let a:msg['nrepl.middleware.print/options'] = a:1
    else
      let a:msg['nrepl.middleware.print/options'] = {}
    endif
    if a:width > 0
      let a:msg['nrepl.middleware.print/options'].width = a:width
    endif
  endif
endfunction

function! fireplace#pprint_fipp(msg, width, ...)
  if fireplace#op_available('info')
    let a:msg['nrepl.middleware.print/print'] = 'cider.nrepl.pprint/fipp-pprint'
    if a:0
      let a:msg['nrepl.middleware.print/options'] = a:1
    else
      let a:msg['nrepl.middleware.print/options'] = {}
    endif
    if a:width > 0
      let a:msg['nrepl.middleware.print/options'].width = a:width
    endif
  endif
endfunction

function! s:add_pprint_opts(msg, width) abort
  let a:msg['nrepl.middleware.print/stream?'] = 1
  call call(get(g:, 'Fireplace_pprint_func', 'fireplace#pprint_fipp'), [a:msg, a:width])
  return a:msg
endfunction

This would then support doing:

let g:Fireplace_pprint_func = {msg, width -> fireplace#pprint_puget(msg, width, #{print-meta: v:true})}

@tpope is that an interface you'd be happy with?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants