[vim/vim] Remove/modify filetype indent for asm files (Issue #14791)

15 views
Skip to first unread message

Zachary Huang

unread,
May 17, 2024, 6:03:38 AMMay 17
to vim/vim, Subscribed

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 using an autocommand, 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.


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14791@github.com>

Christian Brabandt

unread,
May 17, 2024, 6:13:18 AMMay 17
to vim/vim, Subscribed

ping @philj56


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14791/2117222999@github.com>

Eric Biggers

unread,
May 22, 2024, 9:31:49 PMMay 22
to vim/vim, Subscribed

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.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14791/2126030755@github.com>

Philip Jones

unread,
May 26, 2024, 10:51:29 AMMay 26
to vim/vim, Subscribed

@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.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14791/2132248793@github.com>

Christian Brabandt

unread,
May 26, 2024, 12:04:08 PMMay 26
to vim/vim, Subscribed

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


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14791/2132271420@github.com>

Christian Brabandt

unread,
May 26, 2024, 12:08:07 PMMay 26
to vim/vim, Subscribed

Closed #14791 as completed via 76174e7.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/14791/issue_event/12937324931@github.com>

Reply all
Reply to author
Forward
0 new messages