1

I am trying to start dap-mode in my golang project. I already have lsp-mode config set.

for example:

(use-package lsp-mode
  :hook
  ((go-mode . lsp-deferred)
   (rust-mode . lsp-deferred)
  )
)

What I want is let dap-mode in use-package block, but only load the configs when it is go-mode.

I have wrote

(use-package dap-mode
  :if (member major-mode '(go-mode))
  :custom
  (dap-auto-configure-mode t)
  (dap-auto-configure-features
   '(sessions locals breakpoints expressions tooltip))

  :config
  (require 'dap-go)
  )

Then I have the question that, I am using emacs server and client. So if I first in my golang project, dap-mode has loaded, then when I in my rust project, even I don't want dap-mode, it is still loaded.

So actually it is some question of emacs server-client and use-package mode. How can I make the mode in use-package load in special type mode and unload in other modes without restart emacs server?

1 Answer 1

1
(with-eval-after-load 'lsp-mode (require 'dap-mode))

or

(eval-after-load 'lsp-mode '(require 'dap-mode))

C-h f with-eval-after-load says:

with-eval-after-load is a Lisp macro in subr.el.

(with-eval-after-load FILE &rest BODY)

Execute BODY after FILE is loaded.

FILE is normally a feature name, but it can also be a file name, in case that file does not provide any feature. See eval-after-load for more details about the different forms of FILE and their semantics.

You can add the other code you want after the (require 'lsp-mode). You can put any code you like there: the Customize code you want, for options such as dap-auto-configure-mode, additional requires, and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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