* Looking For Any Emacs Config Examples That Has LSP Mode With 'aggressive-indent' Mode
@ 2022-04-28 16:46 Samuel Banya
2022-04-28 20:36 ` Óscar Fuentes
0 siblings, 1 reply; 5+ messages in thread
From: Samuel Banya @ 2022-04-28 16:46 UTC (permalink / raw)
To: Emanuel Berg
Hey there,
I'm vamping up my Emacs config so that I can make it handle web dev related projects, specifically anything related to HTML, CSS, JS, Typescript, Python, Ruby, etc.
However, I'm not having the best time with automatic indentation for Emacs so far, even after really trying to take some deep dives with my config and some of the 'System Crafters' based LSP mode based videos.
I'm wondering if anyone could help me figure out why 'aggressive-indent' and 'LSP Mode' in my config just do not get along with each other, or could offer their config examples to help me figure out how to solve that issue.
As much as I despise VS Code and how ironic it is that LSP wouldn't exist without VS Code, I do envy the fact that it 'just works' out of the box when it comes to this indentation stuff.
Here's my Emacs config itself:
https://github.com/SamuelBanya/dotfiles
Here's my config snippets that contain LSP Mode and various web mode stuff:
```
*** Add 'lsp-mode' for better autocompletion for many programming languages (python, ruby, java, C++)
#+begin_src emacs-lisp
(defun ef/lsp-mode-setup ()
;; Taken from this 'System Crafters' video:
;; https://www.youtube.com/watch?v=E-NAM9U5JYE
;; This allows breadcrumb segments to appear in projects
(setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols))
(lsp-headerline-breadcrumb-mode))
(use-package lsp-mode
:ensure t
:commands (lsp lsp-deferred)
;; Taken from this page:
;; https://www.mattduck.com/lsp-python-getting-started.html
:init
(setq lsp-keymap-prefix "C-c l")
:config
(lsp-enable-which-key-integration t)
;; Set 'lsp-idle-delay' to 0.5 seconds for quick autocompletion
(setq lsp-idle-delay 0.5))
#+end_src
*** Add 'typescript-mode' for Typescript support for 'lsp-mode'
#+begin_src emacs-lisp
(use-package typescript-mode
:ensure t
:mode ("\\.ts\\'" "\\.tsx\\'")
:hook (typescript-mode . lsp-deferred)
:config
(setq typescript-indent-level 2))
#+end_src
*** Add 'web-mode' for support for .html, .ejs, .tsx, and .jsx files
#+begin_src emacs-lisp
(use-package web-mode
:mode "(\\.\\(html?\\|ejs\\|tsx\\|jsx\\)\\'"
:config
(setq-default web-mode-code-indent-offset 2)
(setq-default web-mode-markup-indent-offset 2)
(setq-default web-mode-attribute-indent-offset 2))
#+end_src
```
Thanks,
Sam
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Looking For Any Emacs Config Examples That Has LSP Mode With 'aggressive-indent' Mode
2022-04-28 16:46 Looking For Any Emacs Config Examples That Has LSP Mode With 'aggressive-indent' Mode Samuel Banya
@ 2022-04-28 20:36 ` Óscar Fuentes
2022-04-28 21:53 ` Samuel Banya
0 siblings, 1 reply; 5+ messages in thread
From: Óscar Fuentes @ 2022-04-28 20:36 UTC (permalink / raw)
To: help-gnu-emacs
"Samuel Banya" <sbanya@fastmail.com> writes:
> I'm wondering if anyone could help me figure out why
> 'aggressive-indent' and 'LSP Mode' in my config just do not get along
> with each other, or could offer their config examples to help me
> figure out how to solve that issue.
What follows is my experience as a happy user of aggressive-indent (for
lisp-like languages) and lsp-mode for Dart/Flutter. I'm not an expert on
lsp-mode.
Usually the lsp server takes the responsability of indenting your code,
so aggressive-indent shouldn't be needed. AFAIK both lsp-mode and
aggressive-indent watch for changes on the buffer as triggers to do
their work, which is to delegate to the language server or to Emacs'
mode-specific indentation system, respectively.
OTOH, your mode-dependent indentation settings (such as
typescript-indent-level) may or may not be respected by the language's
lsp server, in case it takes control of the indentation. The mode must
tell the server about those settings.
Why do you want to use aggressive-indent with lsp-mode? Is it because
the auto-indentation doesn't happen often enough? IIRC lsp-mode (or the
Emacs part of the language server) has configs for determining when to
trigger each feature.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Looking For Any Emacs Config Examples That Has LSP Mode With 'aggressive-indent' Mode
2022-04-28 20:36 ` Óscar Fuentes
@ 2022-04-28 21:53 ` Samuel Banya
2022-04-28 23:44 ` Óscar Fuentes
0 siblings, 1 reply; 5+ messages in thread
From: Samuel Banya @ 2022-04-28 21:53 UTC (permalink / raw)
To: Emanuel Berg
Hello Oscar,
Yeah, LSP on its own doesn't do enough indentation.
Aggressive indent is awesome because it does a ton more work for you.
LSP always really only reacts when you hit the Enter key in some cases, hard to describe.
Its just not on point in comparison.
Does anyone have any configs that combine the two or at least gets a more aggressive LSP mode present?
Thanks,
Sam
On Thu, Apr 28, 2022, at 4:36 PM, Óscar Fuentes wrote:
> "Samuel Banya" <sbanya@fastmail.com> writes:
>
> > I'm wondering if anyone could help me figure out why
> > 'aggressive-indent' and 'LSP Mode' in my config just do not get along
> > with each other, or could offer their config examples to help me
> > figure out how to solve that issue.
>
> What follows is my experience as a happy user of aggressive-indent (for
> lisp-like languages) and lsp-mode for Dart/Flutter. I'm not an expert on
> lsp-mode.
>
> Usually the lsp server takes the responsability of indenting your code,
> so aggressive-indent shouldn't be needed. AFAIK both lsp-mode and
> aggressive-indent watch for changes on the buffer as triggers to do
> their work, which is to delegate to the language server or to Emacs'
> mode-specific indentation system, respectively.
>
> OTOH, your mode-dependent indentation settings (such as
> typescript-indent-level) may or may not be respected by the language's
> lsp server, in case it takes control of the indentation. The mode must
> tell the server about those settings.
>
> Why do you want to use aggressive-indent with lsp-mode? Is it because
> the auto-indentation doesn't happen often enough? IIRC lsp-mode (or the
> Emacs part of the language server) has configs for determining when to
> trigger each feature.
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Looking For Any Emacs Config Examples That Has LSP Mode With 'aggressive-indent' Mode
2022-04-28 21:53 ` Samuel Banya
@ 2022-04-28 23:44 ` Óscar Fuentes
2022-04-30 1:42 ` Samuel Banya
0 siblings, 1 reply; 5+ messages in thread
From: Óscar Fuentes @ 2022-04-28 23:44 UTC (permalink / raw)
To: help-gnu-emacs
"Samuel Banya" <sbanya@fastmail.com> writes:
> Hello Oscar,
>
> Yeah, LSP on its own doesn't do enough indentation.
>
> Aggressive indent is awesome because it does a ton more work for you.
>
> LSP always really only reacts when you hit the Enter key in some cases, hard to describe.
>
> Its just not on point in comparison.
>
> Does anyone have any configs that combine the two or at least gets a
> more aggressive LSP mode present?
If you are happy with aggressive-indent, you can disable lsp-mode
indentation system altogether. See lsp-enable-indent (and probably
lsp-enable-on-type-formatting too).
IIRC lsp-mode has settings for choosing when to trigger the
auto-formatting, but can't remember them right now. You can try a
brute-force solution consisting on invoking lsp-format-buffer from a
function on self-insert-hook.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Looking For Any Emacs Config Examples That Has LSP Mode With 'aggressive-indent' Mode
2022-04-28 23:44 ` Óscar Fuentes
@ 2022-04-30 1:42 ` Samuel Banya
0 siblings, 0 replies; 5+ messages in thread
From: Samuel Banya @ 2022-04-30 1:42 UTC (permalink / raw)
To: Emanuel Berg
Yeah, that's the crazy part, I kind of like both in their own way.
However, I did look more into the configuration options for LSP mode, and there really is just only an on-off switch for indentation itself.
I guess its up to the LSP server itself to be more wary of how and when to indent blocks of code.
Hoping someone has a good idea for what else to do or at least a sample LSP config that I can check out.
Thanks,
Sam
On Thu, Apr 28, 2022, at 7:44 PM, Óscar Fuentes wrote:
> "Samuel Banya" <sbanya@fastmail.com> writes:
>
> > Hello Oscar,
> >
> > Yeah, LSP on its own doesn't do enough indentation.
> >
> > Aggressive indent is awesome because it does a ton more work for you.
> >
> > LSP always really only reacts when you hit the Enter key in some cases, hard to describe.
> >
> > Its just not on point in comparison.
> >
> > Does anyone have any configs that combine the two or at least gets a
> > more aggressive LSP mode present?
>
> If you are happy with aggressive-indent, you can disable lsp-mode
> indentation system altogether. See lsp-enable-indent (and probably
> lsp-enable-on-type-formatting too).
>
> IIRC lsp-mode has settings for choosing when to trigger the
> auto-formatting, but can't remember them right now. You can try a
> brute-force solution consisting on invoking lsp-format-buffer from a
> function on self-insert-hook.
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-04-30 1:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-28 16:46 Looking For Any Emacs Config Examples That Has LSP Mode With 'aggressive-indent' Mode Samuel Banya
2022-04-28 20:36 ` Óscar Fuentes
2022-04-28 21:53 ` Samuel Banya
2022-04-28 23:44 ` Óscar Fuentes
2022-04-30 1:42 ` Samuel Banya
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).