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

Allow lookup of function symbol when cursor is on opening paren #2738

Merged
merged 2 commits into from
Nov 2, 2019

Conversation

yuhan0
Copy link
Contributor

@yuhan0 yuhan0 commented Oct 30, 2019

A simple DWIM addition to allow for calling cider-doc and related commands on a symbol when the cursor is at its opening paren. (This is a common state to be in when using structure based navigation)

Eg. with the cursor at |, calling M-x cider-doc should bring up documentation for g

(f |(g x))

Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (make test)
  • All code passes the linter (make lint) which is based on elisp-lint and includes
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the user manual (if adding/changing user-visible functionality)

@bbatsov
Copy link
Member

bbatsov commented Oct 30, 2019

Fine by me. Just add one unit test as well.

@yuhan0
Copy link
Contributor Author

yuhan0 commented Oct 30, 2019

Alright, added :)

@@ -97,6 +97,13 @@
(spy-on 'thing-at-point :and-return-value nil)
(expect (cider-symbol-at-point) :not :to-be-truthy)))

(describe "when on an opening paren"
(it "returns the following symbol"
(with-temp-buffer
Copy link
Member

Choose a reason for hiding this comment

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

You forgot to enable clojure-mode. I guess we need to add some helper named with-clojure-buffer that actually does this automatically. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just going by the other cider-symbol-at-point tests above which don't enable clojure-mode either. Maybe because it's a text-based util that doesn't need clojure-mode?

Copy link
Member

Choose a reason for hiding this comment

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

The behaviour of thing-at-point is defined by the syntax table of each major mode. Some tests will pass with the default syntax table, but that's merely a coincidence. I've noticed recently we had a few incorrect tests, but I didn't have the time to update them yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see - in clojure-mode the above test for SomeRecord. without look-back fails, because . has a different syntax. I'll just change the expected value for that case.

@yuhan0 yuhan0 force-pushed the open-paren-symbol branch 2 times, most recently from 11c102a to a2db24c Compare October 31, 2019 10:34
"Execute BODY in a clojure-mode with CONTENTS

CONTENTS can be a single string to be inserted before the cursor, or a cons
cell of strings (BEFORE . AFTER) where the cursor is placed in between
Copy link
Member

Choose a reason for hiding this comment

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

Might be better to directly support having an (optional) | in the string and moving the point there instead of using a cons cell. The examples would read better IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, changed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I noticed something similar exists in clojure-mode's test suites, is it appropriate for the same macro name to be here as well?
I suppose they don't conflict and there's no way to reuse a test namespace from another package?

https://github.com/clojure-emacs/clojure-mode/blob/147bf84189ef672161b2229ddc5c35713323ad59/test/utils/test-helper.el#L35

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's what I had in mind. Unfortunately the test stuff can't be shared, so they have to be copied.

Also fixes a few tests which did not enable clojure-mode
@bbatsov bbatsov merged commit 03b9081 into clojure-emacs:master Nov 2, 2019
@bbatsov
Copy link
Member

bbatsov commented Nov 2, 2019

Thanks!

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.

2 participants