2

I am using lsp under Python. I have followed: https://emacs-lsp.github.io/lsp-mode/page/installation/ for its installation.

(require 'lsp-mode)
(add-hook 'python-mode-hook 'lsp)
(add-hook 'python-mode-hook #'lsp-deferred)

When I type print( automatically its description shown as below window:

enter image description here

Would it be possible to disable this option for selected functions such as print(), hence I do not want to see its definition automatically.

9
  • I tried took a stub at it, and got a "kinda" working solution, but then my Emacs froze along with all code. Not gonna rewrite, because that was a dirty hack, and also lsp-mode folks should be ashamed of their lsp-hover function that accepts contents in what seems like a thousand of types! Anyway, your best bet is to create a report to lsp-mode and ask them to fix their lsp-eldoc-hook, which (among other problems) doesn't provide any way of extracting the docs. In my "hacky code" I had to modify lsp-hover instead, which I'm sure would break long-term due to using lsp-mode internals.
    – Hi-Angel
    Aug 5 at 23:09
  • Can I try your hacky code code? Shoud I report to lsp-mode through their github issue page (github.com/emacs-lsp/lsp-mode/issues)? , I can write your points and link my question to them.
    – alper
    Aug 6 at 9:04
  • As I mentioned, I lost the code due to emacs getting frozen. But yes, it might be useful to create a report on the link you mention, in which you would describe your usecase, and also that there is a lsp-eldoc-hook which could've been used to implement your usecase, weren't it for the fact that: 1) the functions that this hook executes do not accept the new documentation as an argument, 2) the hook is a list of functions, but there's no way to make one of them stop the list execution (which could be used by you to not execute that function that shows eldoc upon noticing "print" in docs).
    – Hi-Angel
    Aug 6 at 9:24
  • I basically open a issue pasting or discussion: github.com/emacs-lsp/lsp-mode/issues/3038
    – alper
    Aug 6 at 9:52
  • They mentioned: emacs-lsp.github.io/lsp-mode/tutorials/how-to-turn-off I think you want to set (setq lsp-eldoc-enable-hover nil) and closed the issue.
    – alper
    Aug 6 at 10:05
1
+50

I am no expert on lsp and its options, but the following answer works for Spacemacs, where the popup window is created via lsp-signature.

In that case you could add a hook as follows:

(defun lsp-signature-hook-function ()
  (setq lsp-signature-doc-lines
        (when (and lsp-signature-mode
                   (member (python-eldoc--get-symbol-at-point) '("print")))
          (lsp-signature-stop))))

(add-hook 'lsp-signature-mode-hook #'lsp-signature-hook-function)

And you can add more symbols to the list in the member form.

However, you might be interested to just set lsp-signature-doc-lines to 1 (see this reddit post). Subsequently, you can toggle between full and small size doc using M-x lsp-signature-toggle-full-docs (or by setting a value for lsp-signature-doc-lines by modifying the hook just mentioned).

4
  • Seems like it works, but I am seeing following warning text: Variable binding depth exceeds max-specpdl-size when I type print( and cursor waits; is this message normal? It does not show up all the time but it might makes emacs freeze for few seconds
    – alper
    Aug 7 at 19:19
  • 1
    That indeed is not clean behavior. So it seems to be caused by the lsp-signature-function calling (lsp-signature-mode -1) which again triggers the lsp-hook-function. So we should run the code in the condition only when lsp-signature-mode is t. I have updated the code snippet accordingly. Aug 7 at 20:06
  • If I add another function name like format along with print , how could I add it? Should I recreate lsp-signature-hook-function function with different name?
    – alper
    Aug 8 at 20:17
  • 1
    As hinted in the answer, you should add the function names to the list in the member form, i.e. '("print" "format"). Aug 9 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.