Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove/modify filetype indent for asm files #14791

Closed
zack466 opened this issue May 17, 2024 · 4 comments
Closed

Remove/modify filetype indent for asm files #14791

zack466 opened this issue May 17, 2024 · 4 comments

Comments

@zack466
Copy link

zack466 commented May 17, 2024

I feel like the current filetype indent plugin for asm files, which appears to have been added to the repo about a month ago, is not very helpful for assembly programming (located at runtime/indent/asm.vim) and should be removed or modified.

The current indenting behavior is: every line is indented except for labels (keywords that end with a colon). IMO, this is pretty much useless (and actually a little annoying) for most assembly languages - this causes comments, labels (depending on the syntax being used), assembler directives, and preprocessor macros to all be incorrectly indented.

For example, here is something I think would be reasonable in a generic assembler syntax:

#define EIGHT (1 << 3)

.data
msg db "Hello, world!"

.code

; Some documentation for this function
; Some more documentation...
foo:
    LDI R16, 0x80
    ADD R16, R16

The current assembly indentation would turn this to: (assuming a shiftwidth of 4)

    #define EIGHT (1 << 3)

    .data
    msg db "Hello, world!"

    .code

    ; Some documentation for this function
    ; Some more documentation...
foo:
    LDI R16, 0x80
    ADD R16, R16

I don't think this is the way assembly code is typically indented...

I understand that you can easily turn this behavior off (I added autocmd FileType asm setlocal indentexpr= to my .vimrc), but I don't think it should be the default in the first place. Personally, I don't think there needs to be custom indentation behavior for asm files at all -- just indenting manually when needed and then letting autoindent figure it out is flexible and makes the most sense (and as far as I can tell, has been the default for a while). I would be interested in seeing what the general consensus is.

For context, my current use case is AVR assembly.

@chrisbra
Copy link
Member

ping @philj56

@ebiggers
Copy link

I ran into this too: //-style comments are being indented incorrectly. I worked around this by deleting /usr/share/vim/vim91/indent/asm.vim from my system.

@philj56
Copy link

philj56 commented May 26, 2024

@zack466 Hey, sorry for the slow response.

I think that's a pretty reasonable argument; this was a originally a very minimal-effort file for my personal use. It's included in vim because at least one other person wanted it (The original PR's at #14383).

I don't have any particularly strong opinions on it staying in or not, so if it's annoying multiple people, it's probably best off removed. It could also be modified to be much less zealous in its indenting while still achieving my original goals, by changing the GetAsmIndent function to something like:

function! GetAsmIndent()
  let line = getline(v:lnum)

  " If the line is a label (starts with ':' terminated keyword), 
  " then don't indent
  if line =~ '^\s*\k\+:'
    let ind = 0
  else
    " If the previous line was a label, indent:
    if getline(v:lnum - 1) =~ '^\s*\k\+:'
      let ind = s:buffer_shiftwidth()
    else
      " Let autoindent handle everything else.
      let ind = -1
    endif
  endif

  return ind
endfunction

This would mean basically nothing gets touched apart from labels and the lines directly after them.

@chrisbra
Copy link
Member

Hm, the s:buffer_shiftwidth() function seems undefined. Let me remove the indent script then if it causes problems.

clason added a commit to clason/neovim that referenced this issue May 26, 2024
…s too many issues

fixes: vim/vim#14791

vim/vim@76174e7

Co-authored-by: Christian Brabandt <cb@256bit.org>
clason added a commit to clason/neovim that referenced this issue May 26, 2024
…s too many issues

fixes: vim/vim#14791

vim/vim@76174e7

Co-authored-by: Christian Brabandt <cb@256bit.org>
clason added a commit to neovim/neovim that referenced this issue May 27, 2024
…s too many issues

fixes: vim/vim#14791

vim/vim@76174e7

Co-authored-by: Christian Brabandt <cb@256bit.org>
huangyingw pushed a commit to huangyingw/neovim that referenced this issue May 31, 2024
…s too many issues

fixes: vim/vim#14791

vim/vim@76174e7

Co-authored-by: Christian Brabandt <cb@256bit.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants