What did you expect to happen?
That when opening a Typescript file (with extension .ts) with an indentation level different from that of the typescript-indent-level variable, the indentation level would be inferred from the file itself, and the typescript-indent-level variable is set accordingly.
The typescript-indent-level defaults to 4. If I open a file with an indentation level of 2, typescript-indent-level should be updated accordingly. For instance, if I open a file like the following, and I want to open a new line (the | denotes the cursor):
if (true) {
console.log("Hello")
if (true) {|
}
}
The new line should be indented 2 spaces, *i.e.*,
if (true) {
console.log("Hello")
if (true) {
|
}
}
**What actually happened?**
The new line was indented 4 spaces, *i.e.*,
if (true) {
console.log("Hello")
if (true) {
|
}
}
I have the `editorconfig` module enabled in my `doom!` block, which in my understanding is who tries to guess the indentation level for a given file.
The relevant log in the *Messages* buffer is:
Note: standard-indent, tab-width, evil-shift-width adjusted to 2
As far as I understand, `typescript-indent-level` is not being adjusted.
Instead, the indentation setup works as expected for *rust*. When opening a file where it detects the indentation offset is 2, *e.g.*,
fn main() {
println!("Hello");
if (true) {|
}
}
And I hit `RET`, then the new line is properly indented:
fn main() {
println!("Hello");
if (true) {
|
}
}
I can see that the `rustic-indent-offset` variable is properly set to 2:
Note: rustic-indent-offset, tab-width, evil-shift-width adjusted to 2
Please let me know if you need further information to clarify, or if I made a mistake, I've been `Doom`ed recently :p . Which btw, incredibly work! Thanks.
**Additional details:**
- Include a link to your private config
- Include screenshots/casts of your issue
- If you mention key sequences, include what commands they're bound to (use `SPC
h k KEY` or `C-h h k KEY` to inspect keys).
- Include any warnings or errors logged to \*Messages\* (use `M-x
view-echo-area-messages` to see it).
If an error message is involved include a backtrace of it.
How to acquire a backtrace:
https://github.com/hlissner/doom-emacs/blob/develop/docs/getting_started.org#how-to-extract-a-backtrace-from-an-error
Steps to reproduce:
System information:
emacs version 26.3
features NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES THREADS
build Sep 02, 2019
buildopts (--with-ns '--enable-locallisppath=/Library/Application Support/Emacs/${version}/site-lisp:/Library/Application Support/Emacs/site-lisp' --with-modules)
windowsys ns
daemonp server-running
doom version 2.0.9
build HEAD -> develop, origin/develop, origin/HEAD a381f5926 2020-04-03 02:12:50 -0400
dir /Volumes/Data/work/home/.doom.d/
system type darwin
config x86_64-apple-darwin18.2.0
shell /bin/zsh
uname Darwin 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64
path (~/.cabal/bin ~/.ghcup/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /usr/local/share/dotnet /Library/TeX/texbin ~/.dotnet/tools /Library/Frameworks/Mono.framework/Versions/Current/Commands ~/.cargo/bin /Applications/Emacs.app/Contents/MacOS/bin-x86_64-10_14 /Applications/Emacs.app/Contents/MacOS/libexec-x86_64-10_14 /Applications/Emacs.app/Contents/MacOS/libexec/)
config envfile envvar-file
elc-files 0
modules (:completion company (ivy +fuzzy +prescient +icons) :ui doom doom-dashboard doom-quit hl-todo hydra indent-guides modeline nav-flash ophints (popup +defaults) tabs treemacs vc-gutter vi-tilde-fringe (window-select +numbers) workspaces :editor (evil +everywhere) file-templates fold snippets :emacs (dired +ranger +icons) electric ibuffer vc :checkers syntax spell grammar :tools editorconfig (eval +overlay) lookup magit :lang data emacs-lisp ess javascript markdown org rest rust sh :config (default +bindings +smartparens))
packages ((git-time-metric))
unpin (n/a)
elpa (n/a)
This is because the dtrt-indent package doesn't recognize typescript-mode. I've PRed a fix upstream.
In the meantime, here is a quick workaround:
(after! dtrt-indent
(add-to-list 'dtrt-indent-hook-mapping-list '(typescript-mode javascript typescript-indent-level)))
Thanks for your quick reply!
The workaround works perfectly.
PS: I didn't know that this was a dtrt-indent's issue. And thanks again for forwarding it upstream.
As of aa2096e Doom installs the latest version of dtrt-indent (which includes my PRed fix), so I'll consider this issue resolved. Let me know if that isn't the case and I'll reopen the issue. Thanks for bringing it to my attention!
@hlissner I just upgraded doom, but I'm still not seeing typescript-mode's indent level changing to match the doom indent-level :(
Same here, my indent levels for typescript seem not right (4, when everything else is 2).
Most helpful comment
Same here, my indent levels for typescript seem not right (4, when everything else is 2).