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?

Drew
  • 75,699
  • 9
  • 109
  • 225
ccQpein
  • 123
  • 5

1 Answers1

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.

Drew
  • 75,699
  • 9
  • 109
  • 225