Python Configuration for Emacs 29

Поділитися
Вставка
  • Опубліковано 17 лис 2024

КОМЕНТАРІ • 30

  • @deedend
    @deedend 5 місяців тому +1

    This video is really what I was looking for... Thank you very much!!

  • @DangerSepp
    @DangerSepp Рік тому

    Highly appreciated, thank you!

  • @myyouaccounttube1024
    @myyouaccounttube1024 11 місяців тому +1

    Thank you for this video. I use elpy package which unfortunately isn't maintained/updated anymore. However it has autopep8 which automatically formats Python code to conform to the PEP 8 style guide. Does the package you suggest do the same based on PEP 8?

    • @bwestbro
      @bwestbro  11 місяців тому +2

      Around 13:51 I set up a keybinding for eglot-format, which uses the LSP to format the buffer. I'm not that familiar with the different formatting styles for python, but I see on the python-lsp-server github page that pylsp.plugins.autopep8.enable is enabled by default, so I think the short answer is yes!
      Here's the link if you need more information: github.com/python-lsp/python-lsp-server/blob/develop/CONFIGURATION.md

  • @dpassen1
    @dpassen1 Рік тому +1

    You should be able to use `eglot-managed-mode-hook` to turn on company

    • @bwestbro
      @bwestbro  Рік тому +1

      Ahhh, thank you! I looked in the docs, but only noticed `eglot-connect-hook`. I'll give this a try!

  • @shubhampawar7921
    @shubhampawar7921 10 місяців тому

    Hello Brent, one thing that has kept me using neovim is the autocompletion.
    I wanted to configure company to show me lsp suggestions then followed by buffer suggestions ( words inside all the opened buffers). Couldn't get this kinda company setup

    • @bwestbro
      @bwestbro  10 місяців тому +2

      I think you can achieve this by modifying the company-backends variable. I think I've only ever used one at a time, but the documentation mentions "grouped" backends where the results from each one are merged together. If you could group the LSP and buffer suggestions, that should give you what you want! It also mentions a :separate keyword argument that will keep the two sets separate if that's what you want too.
      I was looking at the docs inside of Emacs, but this page also looks helpful: company-mode.github.io/manual/Backends.html

  • @VorpalForceField
    @VorpalForceField 3 місяці тому

    Cool Deal .. Thank You for sharing .. Cheers :)

  • @0netom
    @0netom Рік тому

    @bwestbro You were not able navigate up and down in the company-mode popup @6:36 .
    What was the reason for that?
    What did u do instead to get that gray, inline completion proposal?

    • @bwestbro
      @bwestbro  Рік тому +1

      I'm just not used to the default company-mode bindings! I think in my main config with evil-mode, I use C-n and C-p or Tab to navigate the completions, but the default bindings are M-n/M-p to navigate and Ret to accept. I'm actually not sure what I hit to accept that, but it might have been Tab to fill company's only suggestion, or I might have hit M-/, which is dabbrev-expand. It's a pretty handy binding to keep in mind for situations where you just want to complete a word in the current or other buffer without something like company-mode active.

  • @vivaneret1249
    @vivaneret1249 Рік тому

    Excellent!

  • @angry-penguin
    @angry-penguin Рік тому

    The last thing that keeps me stuck on nvim is that I still haven't found any working recipe for configuring tree-sitter support in multi-mode like vue-mode or svelte (web-mode/mmm-mode). Anyway, great video!

    • @bwestbro
      @bwestbro  Рік тому

      Oh that's a great question, I haven't looked into multi-mode stuff before! From a quick search, the mmm-mode repo suggests something like
      (mmm-add-mode-ext-class 'html-mode "\\.php\\'" 'html-php)
      for adding php support to html-mode. Can you do something like this?
      (mmm-add-mode-ext-class 'html-ts-mode ...)
      Like I said, I haven't tried mmm-mode, and you might have already tried this, but I wanted to throw it out there. Thanks for the kind words!

  • @batuurdor
    @batuurdor 7 місяців тому

    Hey brent, how did you get your company work out-of-box with python ?

    • @bwestbro
      @bwestbro  6 місяців тому +1

      I'm not totally sure what you mean, but a few things you will need are:
      1. company-mode active in python-mode (or python-ts-mode if you're following the video; I usually check this with C-h m)
      2. A company backend that provides completions (I think eglot or lsp-mode should provide this automatically)
      3. An LSP server for eglot or lsp-mode to connect to
      For point 1, it looks like I add a hook to python-ts-mode to activate company-mode at 5:28, and I install pylsp around 4:37 for point 3. Like I said, I think either of the main LSP packages will handle point 2 for you, but I used to have to mess with the company-backends variable before LSP servers were common.
      I hope this helps!

  • @HarishNarayanan
    @HarishNarayanan Рік тому

    This is really cool. I am doing something very wrong and do not seem to truly get any functionality out of eglot even though it proudly expresses in the mini buffer that it's connected to the LSP. Could you please paste your working config or the relevant Python Treesitter/Company sections of it somewhere online so I can inspect what I'm doing wrong? Thank you!

    • @bwestbro
      @bwestbro  Рік тому

      Great idea! I just put the whole config in this gist: gist.github.com/ntBre/a6e1f7933314c77eceef49cd844b5413
      Hope it helps, let me know if you have any more questions.

    • @HarishNarayanan
      @HarishNarayanan Рік тому

      @@bwestbroThank you so much, I will try it out and let you know.

  • @vivaneret1249
    @vivaneret1249 Рік тому

    Hi, I am new to emacs and I learn a lot from your videos. One question: when I compile a python file the compile buffer opens horizontally and not vertically as in your videos. How can I change that? Thank you very much!

    • @bwestbro
      @bwestbro  Рік тому +1

      I think Emacs tries to pick the "best" split for the current size of your frame, but I found the link below suggesting either (setq split-width-threshold nil) to prioritize a vertical split or (setq split-width-threshold 1) for a horizontal split. I always get vertical and horizontal mixed up, so I recommend trying both of those if making your frame larger doesn't fix it!
      stackoverflow.com/a/7998271/12935407

    • @vivaneret1249
      @vivaneret1249 Рік тому

      @@bwestbro Thanks! I will try both!

    • @vivaneret1249
      @vivaneret1249 Рік тому

      @@bwestbroI used (setq split-width-threshold 1 ) and it works perfect, the buffer looks like in your videos. Thank you!

  • @PE4ENAROBOTV
    @PE4ENAROBOTV Рік тому

    thanks a lot

  • @rikhardfsoss
    @rikhardfsoss Рік тому +1

    what happen to the sound, is sooooooooooooooo low.

    • @bwestbro
      @bwestbro  Рік тому

      Oh no! The whole video or specific parts? I just clicked through, and it sounded okay for me :(

    • @rikhardfsoss
      @rikhardfsoss Рік тому

      @@bwestbro well at least for me it's the entire video, it's audible, but compared to other videos is quite low.

    • @bwestbro
      @bwestbro  Рік тому +2

      Thanks for the feedback, I'll try to increase the volume in future videos!

  • @cycomkid
    @cycomkid Рік тому +1

    Bro just use vscode, everything that you did in 2 videos, can be done in vscode in 1 minutes

    • @bwestbro
      @bwestbro  Рік тому +9

      Of course I know about VSCode and have tried using it in the past. I vastly prefer Emacs for all of the other configuration options it gives me and the integration between different parts of my workflow. One of the points of these videos is to give other people, who may not want to spend 20 minutes setting up their editor, a config to paste in and be started in "1 minutes" just like VSCode.