Skip to content

Adds an option to disable eldoc #197

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

Merged
merged 8 commits into from
Mar 15, 2022

Conversation

dpsutton
Copy link
Contributor

@dpsutton dpsutton commented Mar 1, 2022

Eldoc is quite nice and puts the function signatures in the
minibuffer. But it does this at a cost. Since inf-clojure only uses a
single connection (currently at least) the commands interrupt the
values of *1, *2, etc. Further, this can lead to multiple prompts
appearing in the repl buffer.

user=> user=> (map inc (range 4))
(1 2 3 4)
user=> user=> *1
nil
user=>

user appears multiple times, and then *1 has been bound to the
result of getting arglists

user=> (+ 1 1)
2
user=> *1
([f] [f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls])

The multiple prompts is quite annoying when inserting forms into the
repl.

Note that *1 is oftentimes nil because eldoc just runs (try (:arglists (meta _whatever-your-cursor-is-on)) (catch nil)) whenever your cursor stays on something for too long. This is also not throwing away too much functionality since you can easily get the docstring in the repl by C-c C-v (inf-clojure-show-var-documentation)

dpsutton added 2 commits March 1, 2022 12:37
Eldoc is quite nice and puts the function signatures in the
minibuffer. But it does this at a cost. Since inf-clojure only uses a
single connection (currently at least) the commands interrupt the
values of `*1`, `*2`, etc. Further, this can lead to multiple prompts
appearing in the repl buffer.

```clojure
user=> user=> (map inc (range 4))
(1 2 3 4)
user=> user=> *1
nil
user=>
```

`user` appears multiple times, and then `*1` has been bound to the
result of getting arglists

```clojure
user=> (+ 1 1)
2
user=> *1
([f] [f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls])
```

The multiple prompts is quite annoying when inserting forms into the
repl.
@bbatsov
Copy link
Member

bbatsov commented Mar 2, 2022

Can't people just turn-off eldoc-mode locally? (e.g. using a hook)

@dpsutton
Copy link
Contributor Author

dpsutton commented Mar 2, 2022

I think you are right that this is not the way to go forward. A hook to turn off eldoc mode helps for newly created buffers but is annoying for any that already exist. But perhaps that's not so bad. Let me think on it for a bit. I'm wondering if other modes in the buffer use eldoc so that turning eldoc mode completely off is heavy handed.

@Andre0991
Copy link

I'm wondering if other modes in the buffer use eldoc so that turning eldoc mode completely off is heavy handed.

eglot (LSP client) uses eldoc.

@Andre0991
Copy link

By the way, as an inspiration, eglot has an variable for not interfering with other modes:

`eglot-stay-out-of: List of Emacs features that Eglot shouldn't automatically try to manage on users' behalf. Useful when you need non-LSP Flymake or Company backends. See docstring for examples.

I wonder if inf-clojure could do the same for eldoc.

inf-clojure.el Outdated
"Var that allows disabling `eldoc-mode` in `inf-clojure`.

Set to `nil` to disable eldoc. Eldoc can be quite useful by
displaying funciton signatures in the modeline, but can also
Copy link
Member

Choose a reason for hiding this comment

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

Btw, this disclaimer is true for every command that does some code evaluation on the side. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, but all others are user driver. If you refresh a namespace or call doc, you understand that *1 and others will have been moved because you caused an evaluation. Eldoc is special because unbeknownst to the user those vars will change value. It makes using them very frustrating.

Copy link
Member

Choose a reason for hiding this comment

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

Also - there's a typo in function.

@dpsutton
Copy link
Contributor Author

I've updated it to be a bit more sensible i think. Now I just prohibit the eldoc setup when it is not enabled. This allows other modes to use eldoc and seems quite nice in practice for me.

inf-clojure.el Outdated
@@ -384,6 +384,13 @@ mode line entirely."
:type 'sexp
:risky t)

(defvar inf-clojure-eldoc-enabledp t
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this a defcustom and name it inf-clojure-enable-eldoc.

inf-clojure.el Outdated
@@ -631,7 +639,8 @@ to continue it."
(setq mode-line-process '(":%s"))
(clojure-mode-variables)
(clojure-font-lock-setup)
(inf-clojure-eldoc-setup)
(when inf-clojure-eldoc-enabledp
Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with this, but it might be better to make the eldoc integration a no-op instead, so that people won't have to disable/enable inf-clojure-mode for the new config to be taken into account.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was originally my solution, but that still leads to some problems. Eldoc is initialized as follows:

(defun inf-clojure-eldoc-setup ()
  "Turn on eldoc mode in the current buffer."
  (setq-local eldoc-documentation-function #'inf-clojure-eldoc)
  (apply #'eldoc-add-command inf-clojure-extra-eldoc-commands))

Since it clobbers any existing eldoc-documentation-function, once eldoc is initialized in a buffer there's no good way to go back to a clean slate since any previous eldoc function is gone. I'll add the enabledp function to the eldoc function so it would prevent more eldocs, but it cannot restore the previous eldoc unfortunately.

@bbatsov
Copy link
Member

bbatsov commented Mar 14, 2022

I've added a couple of small feedback remarks. This also needs to be documented somewhere in the README.

If someone changes this value after using `inf-clojure`, we cannot
restore other eldoc functions (lsp, etc) but we can at least not send
more eldoc requests and mess with the repl. Restarting emacs or
perhaps even just disabling and then enabling the mode would put them
in a clean state
@dpsutton
Copy link
Contributor Author

All addressed I believe. Thanks for the thoughtful review @bbatsov !

@bbatsov bbatsov merged commit de59e5c into clojure-emacs:master Mar 15, 2022
@bbatsov
Copy link
Member

bbatsov commented Mar 15, 2022

You're welcome! Thanks for tackling this.

@dpsutton dpsutton deleted the option-to-disable-eldoc branch March 15, 2022 13:32
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy