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

cider-doc now renders spec using cider-browse-spec--pprint-indented #2154

Merged
merged 1 commit into from
Jan 11, 2018

Conversation

jpmonettas
Copy link
Contributor

There is also a button to jump to the browser

This needs to be merged together with! clojure-emacs/cider-nrepl#472


  • The commits are consistent with our [contribution guidelines][1]
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (make test)
  • The new code is not generating bytecode or M-x checkdoc warnings
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the readme (if adding/changing user-visible functionality)
  • You've updated the refcard (if you made changes to the commands listed there)

@jpmonettas
Copy link
Contributor Author

@bbatsov This is not ready to be merged yet, it works with eval-buffer but has a compilation error due to dependency cycle. I'm creating the pull request to discuss the solution.

The thing is I need to create a button in cider-doc.el that when clicked calls a procedure inside cider-browse-spec.el.

Can someone with more experience in elisp help me with this? Thanks

@xiongtx
Copy link
Member

xiongtx commented Jan 5, 2018

A screenshot would be helpful:

image

This presentation could be improved. See the existing:

image

@jpmonettas
Copy link
Contributor Author

jpmonettas commented Jan 5, 2018

@xiongtx Don't know why it looks like that, mines looks different :

latest-screenshot

I prefer it to show anonymous functions as functions and not to remove the #, because they look like the spec is invalid.

Any idea how to solve that dependency cycle issue?

@xiongtx
Copy link
Member

xiongtx commented Jan 5, 2018

Hmm, I'm not sure what's causing the differences. Perhaps @bbatsov can see what results he gets.

@bbatsov
Copy link
Member

bbatsov commented Jan 7, 2018

Perhaps I'm missing something, but the first version does look a bit tidier to me. Perhaps we can make it configurable which version to display in the doc buffer? After all I guess the "Browse" button is the most important thing.

@xiongtx
Copy link
Member

xiongtx commented Jan 7, 2018

Which version looks tidier? Couldn't be the first one in my post--it doesn't even line up the args, ret, etc. We should probably disregard it--I'd guess it's b/c I didn't pull down the required version of cider-nrepl.

Anyways, I'd be fine w/ merging what @jpmonettas shows, though I don't think the s/fspec is necessary--it's just noise. That it's an fdef is obvious from the :args, :ret, etc.

@@ -243,6 +245,14 @@ Display TITLE at the top and SPECS are indented underneath."
(string-join (mapcar #'cider-browse-spec--pprint (cl-rest form)) " "))))))
(t (format "%s" form))))

(defun cider-browse-spec--pprint-indented (spec-form)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this can be simplified w/ cider-font-lock-as-clojure on the pprinted string.

@bbatsov
Copy link
Member

bbatsov commented Jan 7, 2018

By first, I meant the existing one. I like the nice structural distinction between args, ret and fn (and I also think we can use better labels for those, btw). My personal preference would be to show by default something easier to parse by human minds and optionally be able to show the actual spec as it exists in the code.

@jpmonettas
Copy link
Contributor Author

@bbatsov @xiongtx Just removed the surrounding (s/fspec ...) stuff, now it looks like:

latest-screenshot

The cat looks nicer in our current version because it only has two parts, so we can show it all in one line, but as soon as you have a larger cat line I think it looks nicer to print one part in each line.

My personal preference would be to show by default something easier to parse by human minds and optionally be able to show the actual spec as it exists in the code.

I think this too, that's why I created that elisp spec formatter, so we have control and can fine tune how we print a spec instead of relaying on vanilla s/form pprinting.

Some time ago I created pretty-spec that uses fipp to pretty print specs sensitive to a width you have defined. Using something like this will require to move pprinting from elisp to cider-nrepl. (I explored those ideas some time ago when writing Inspectable

(insert "\n"))
(insert "\n"))
(emit "Spec:" 'font-lock-function-name-face)
(insert (cider-browse-spec--pprint-indented spec))
Copy link
Member

@xiongtx xiongtx Jan 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should (require 'cider-browse-spec) at the top of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if I do that I'm getting a dependency cycle :

In toplevel form:
cider-selector.el:35:1:Error: Recursive ‘require’ for feature ‘cider-interaction’

In toplevel form:
cider-inspector.el:32:1:Error: Recursive ‘require’ for feature ‘cider-interaction’

In toplevel form:
cider-debug.el:30:1:Error: Recursive ‘require’ for feature ‘cider-interaction’

In toplevel form:
cider-scratch.el:33:1:Error: Recursive ‘require’ for feature ‘cider-interaction’

In toplevel form:
cider-macroexpansion.el:34:1:Error: Recursive ‘require’ for feature ‘cider-interaction’

In toplevel form:
cider-interaction.el:35:1:Error: Recursive ‘require’ for feature ‘cider-repl’

In toplevel form:
cider-mode.el:35:1:Error: Recursive ‘require’ for feature ‘cider-interaction’

In toplevel form:
cider-apropos.el:28:1:Error: Recursive ‘require’ for feature ‘cider-doc’

In toplevel form:
cider-repl.el:35:1:Error: Recursive ‘require’ for feature ‘cider-doc’

In toplevel form:
cider-browse-spec.el:39:1:Error: Recursive ‘require’ for feature ‘cider-interaction’

In toplevel form:
cider-doc.el:39:1:Error: Recursive ‘require’ for feature ‘cider-browse-spec’

In toplevel form:
cider-browse-ns.el:38:1:Error: Recursive ‘require’ for feature ‘cider-interaction’

In toplevel form:
cider.el:82:1:Error: Recursive ‘require’ for feature ‘cider-repl’
Makefile:42: recipe for target 'test-bytecomp' failed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to figure out what's causing the dependency cycle then, and break it. We probably have some unnecessary requires in some files, or maybe some functions need to be shuffled around.

In any case, you're using cider-browse-spec--... in cider-doc.el so you should definitely require it in cider-doc.el.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, was cider-browse-spec depending on cider-interaction, it doesn't need to, so this is fixed.

@xiongtx
Copy link
Member

xiongtx commented Jan 9, 2018

Yes, removing the s/fspec stuff cleans it up a lot. I'm good w/ how it looks now.

@jpmonettas
Copy link
Contributor Author

Maybe this looks better? What about the naming ?

latest-screenshot

@jpmonettas jpmonettas force-pushed the fix/issue-2029 branch 2 times, most recently from 30211ba to a08b8be Compare January 9, 2018 17:30
@jpmonettas
Copy link
Contributor Author

@bbatsov @xiongtx if both agree on the latest screenshot now everything is ready to be merged together with clojure-emacs/cider-nrepl#472

  • The commits are consistent with our [contribution guidelines][1]
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (make test)
  • The new code is not generating bytecode or M-x checkdoc warnings
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the readme (if adding/changing user-visible functionality)
  • You've updated the refcard (if you made changes to the commands listed there)

@bbatsov
Copy link
Member

bbatsov commented Jan 9, 2018

I'm fine with it. Just rebase on top of the current master.

@bbatsov
Copy link
Member

bbatsov commented Jan 9, 2018

You should also add some changelog entry.

@jpmonettas jpmonettas force-pushed the fix/issue-2029 branch 2 times, most recently from 6e14ce7 to 32c6243 Compare January 9, 2018 23:06
@jpmonettas
Copy link
Contributor Author

@bbatsov added an entry to the changelog and rebased on top of master.

cider-doc.el Outdated
(insert-text-button "Browse spec"
'follow-link t
'action (lambda (x)
(cider-browse-spec (format "%s/%s" ns name))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed at the build output x is unused, which I assume is a mistake. It should be just _ if it's not needed.

There is also a button to jump to the browser
@bbatsov bbatsov merged commit f4e6c59 into clojure-emacs:master Jan 11, 2018
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

Successfully merging this pull request may close these issues.

3 participants