reddit / emacs

Is this an error for integrating lsp with emacs?

timlee126 · 2022-01-31 01:39
I try to install Microsoft’s python-language-server on NixOS, and integrate it with emacs, following https://github.com/emacs-lsp/lsp-python-ms. I have installed Microsoft’s python-language-server on NixOS, by adding `python-language-server` to `configuration.nix`. Then I try to integrate it into Emacs. I copy the following into `~/.emacs.d/init.el`: ;; Include lsp-python-ms in the configuration file: (require 'lsp-python-ms) (setq lsp-python-ms-auto-install-server t) (add-hook 'python-mode-hook #'lsp) ; or lsp-deferred ;; initialization (use-package lsp-python-ms :ensure t :hook (python-mode . (lambda () (require 'lsp-python-ms) (lsp))) :init (setq lsp-python-ms-executable (executable-find "python-language-server"))) (1) I don't want to restart emacs for reloading the above added code in `~/.emacs.d/init.el`, because I don't want to kill the programs run from a shell inside emacs. Can I select the above added code region , and hit C-x C-e? (2) When I did that, I saw in the Backtrace buffer: Debugger entered--Lisp error: (void-function use-package) (use-package lsp-python-ms :ensure t :hook (python-mode lambda nil (require 'lsp-python-ms) (lsp)) :init (setq lsp-python-ms-executable (executable-find "python-language-server"))) eval((use-package lsp-python-ms :ensure t :hook (python-mode lambda nil (require 'lsp-python-ms) (lsp)) :init (setq lsp-python-ms-executable (executable-find "python-language-server"))) nil) elisp--eval-last-sexp(nil) eval-last-sexp(nil) funcall-interactively(eval-last-sexp nil) call-interactively(eval-last-sexp nil nil) command-execute(eval-last-sexp) I was wondering if there is something wrong by `Debugger entered--Lisp error`? How shall I make the lsp work in emacs? Thanks.
leungbk · 2022-01-31 01:54
`use-package` isn't part of base Emacs. You need to install that in your config, preferably towards the beginning, prior to any invocations of it later on. I also don't recommend that server since it's not really maintained.
timlee126 · 2022-01-31 02:05
> use-package isn't part of base Emacs. You need to install that in your config, preferably towards the beginning, prior to any invocations of it later on. What code for installing it? Can I run the code for installation without restarting emacs? > I also don't recommend that server since it's not really maintained. Which one do you like? Thanks.
leungbk · 2022-01-31 03:55
Try putting this into `some-other-init.el`: (let ((bootstrap-file (concat user-emacs-directory "straight/repos/straight.el/bootstrap.el")) (bootstrap-version 5)) (unless (file-exists-p bootstrap-file) (with-current-buffer (url-retrieve-synchronously "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el" 'silent 'inhibit-cookies) (goto-char (point-max)) (eval-print-last-sexp))) (load bootstrap-file nil 'nomessage)) (straight-use-package 'use-package) (setq straight-use-package-by-default t) (setq read-process-output-max (* 1024 1024 3)) ;; useful for lsp stuff (use-package lsp-mode ;; ;; etc... ) This installs an alternate package manager, which in turn installs `use-package`. You can load this by running `emacs -q -l path/to/some-other-init.el` in your terminal. I'm not a Python expert, but Pyright seems to meet my needs.
seregaxvm · 2022-01-31 05:25
To install it, you could just hit `Alt+X package-install use-package`. I use [`pylsp`](https://emacs-lsp.github.io/lsp-mode/page/lsp-pylsp/). Emacs will usually warn you if you're using an unmaintained version of lsp.