[vim/vim] set comments and commentstring for .asm files (#6125)

208 views
Skip to first unread message

Colin Caine

unread,
May 23, 2020, 12:33:58 PM5/23/20
to vim/vim, Subscribed

Useful with tpope's commentary plugin.

There is no ftplugin for asm, so I haven't contacted the maintainer.

This might be controversial because asm has a bunch of different
dialects and ; is only a comment in some of them. This is also true of
the current default of /* */, but I think ; is right more of the
time (used in nasm, yasm, the official ARM assemblers, MASM, etc).


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/6125

Commit Summary

  • set comments and commentstring for .asm files

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Bram Moolenaar

unread,
May 23, 2020, 1:21:25 PM5/23/20
to vim/vim, Subscribed

Not sure how useful this is. At least setting 'comments' is wrong, the double quote starts a comment.

Colin Caine

unread,
May 23, 2020, 4:31:09 PM5/23/20
to vim/vim, Subscribed

Fixed the comments bit. Thanks! And thanks for writing and maintaining vim!

I'd like the commentstring set so that I can do gcc to correctly comment out a line and I'd like comments set so that I can use gww to have comment lines wrap properly (with a leading comment marker on each line).

It's useful to me 🤷

Codecov Comments Bot

unread,
May 23, 2020, 4:53:25 PM5/23/20
to vim/vim, Subscribed

Codecov Report

Merging #6125 into master will increase coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@

##           master    #6125      +/-   ##

==========================================

+ Coverage   87.29%   87.34%   +0.04%     

==========================================

  Files         137      141       +4     

  Lines      156787   157148     +361     

==========================================

+ Hits       136869   137257     +388     

+ Misses      19918    19891      -27     
Impacted Files Coverage Δ
src/netbeans.c 74.66% <0.00%> (-0.52%) ⬇️
src/term.c 81.89% <0.00%> (-0.06%) ⬇️
src/version.c 92.13% <0.00%> (ø)
src/kword_test.c 67.74% <0.00%> (ø)
src/memfile_test.c 100.00% <0.00%> (ø)
src/message_test.c 100.00% <0.00%> (ø)
src/json_test.c 100.00% <0.00%> (ø)
src/gui.c 63.40% <0.00%> (+0.10%) ⬆️
src/if_xcmdsrv.c 88.90% <0.00%> (+0.17%) ⬆️
src/mbyte.c 65.95% <0.00%> (+0.18%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 591cec8...20188af. Read the comment docs.

Gary Johnson

unread,
May 23, 2020, 4:54:02 PM5/23/20
to reply+ACY5DGHMMXWM75OUSL...@reply.github.com, vim...@googlegroups.com
On 2020-05-23, Colin Caine wrote:
> Fixed the comments bit. Thanks! And thanks for writing and maintaining vim!
>
> I'd like the commentstring set so that I can do gcc to correctly comment out a
> line and I'd like comments set so that I can use gww to have comment lines wrap
> properly (with a leading comment marker on each line).
>
> It's useful to me 🤷

If it's not generally useful, and especially if it could be wrong
for some users, put those settings in ~/.vim/after/ftplugin/asm.vim.
You won't have to think about them anymore and they won't change
Vim's behavior for anyone else.

Regards,
Gary

vim-dev ML

unread,
May 23, 2020, 4:54:18 PM5/23/20
to vim/vim, vim-dev ML, Your activity

Colin Caine

unread,
May 23, 2020, 5:28:48 PM5/23/20
to vim/vim, vim-dev ML, Comment

I already have these in my vimrc. I think these are good defaults, which is
why I'm suggesting them for the vim runtime.

As it stands, the current values are wrong for most (all?) assembly formats
other than GAS. Whereas ; is right for quite a lot of assemblers.


On Sat, 23 May 2020, 21:54 vim-dev ML, <notifi...@github.com> wrote:

> On 2020-05-23, Colin Caine wrote:
> > Fixed the comments bit. Thanks! And thanks for writing and maintaining
> vim!
> >
> > I'd like the commentstring set so that I can do gcc to correctly comment
> out a
> > line and I'd like comments set so that I can use gww to have comment
> lines wrap
> > properly (with a leading comment marker on each line).
> >
> > It's useful to me 🤷
>
> If it's not generally useful, and especially if it could be wrong
> for some users, put those settings in ~/.vim/after/ftplugin/asm.vim.
> You won't have to think about them anymore and they won't change
> Vim's behavior for anyone else.
>
> Regards,
> Gary
>
> —
> You are receiving this because you authored the thread.

> Reply to this email directly, view it on GitHub
> <https://github.com/vim/vim/pull/6125#issuecomment-633138482>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABNZA6PZMGMLMECID2U3GWDRTAZXJANCNFSM4NIQK3EQ>
> .
>


You are receiving this because you commented.

Gary Johnson

unread,
May 24, 2020, 2:55:08 AM5/24/20
to reply+ACY5DGABOHC6W26BHS...@reply.github.com, vim...@googlegroups.com
On 2020-05-23, Colin Caine wrote:
> I already have these in my vimrc. I think these are good defaults, which is
> why I'm suggesting them for the vim runtime.
>
> As it stands, the current values are wrong for most (all?) assembly formats
> other than GAS. Whereas ; is right for quite a lot of assemblers.

I don't know how many people use which assemblers. The only
assembler I use these days is GNU as and mostly for a RISC-V target.
All the assembly code I've seen for that target uses either C-style
or C++-style comments. If you want to add ; as a comment character,
or somehow make the comment characters assembler- or
target-dependent, fine, but I don't think Vim's current support for
the GNU assembler should be removed.

Regards,
Gary

vim-dev ML

unread,
May 24, 2020, 2:55:24 AM5/24/20
to vim/vim, vim-dev ML, Your activity

Colin Caine

unread,
May 24, 2020, 3:10:14 AM5/24/20
to vim/vim, vim-dev ML, Comment

@cmcaine commented on this pull request.


In runtime/ftplugin/asm.vim:

> @@ -0,0 +1,11 @@

+" Vim filetype plugin file

+" Language:	asm

+" Maintainer:	Colin Caine <cmcaine at the common googlemail domain>

+" Last Changed: 23 May 2020

+

+if exists("b:did_ftplugin") | finish | endif

+

+setl comments=:;

⬇️ Suggested change
-setl comments=:;

+setl comments=:;,s1:/*,mb:*,ex:*/,://


You are receiving this because you commented.

Colin Caine

unread,
May 24, 2020, 3:10:45 AM5/24/20
to vim/vim, vim-dev ML, Push

@cmcaine pushed 1 commit.

  • 7bc0ecf Continute to support GAS comments


You are receiving this because you are subscribed to this thread.

View it on GitHub or unsubscribe.

Colin Caine

unread,
May 24, 2020, 3:17:16 AM5/24/20
to vim/vim, vim-dev ML, Comment

The comments setting can happily accommodate both GAS and other assemblers, so that's hopefully not a problem?

This works for both and I've amended the PR accordingly, thanks for the prod.

comments=:;,s1:/,mb:,ex:*/,://

The commentstring setting has to pick a style and I don't intend to write something to detect what asm syntax is in use (I think this would be impossible to do well). I think the default should be semicolon, but if this is opposed then obviously we can just leave it as whatever the user has as the default (usually C multiline comment format). Users can just configure it themselves.

A question for the list: is it appropriate to add r to formatopts in this ftplugin? Again, it's useful to me, and I think it's a good default (especially if one were writing multiline C comments), but it is a small change.


You are receiving this because you commented.

Bram Moolenaar

unread,
Jun 2, 2020, 2:44:21 PM6/2/20
to vim/vim, vim-dev ML, Comment

Closed #6125.


You are receiving this because you commented.

Bram Moolenaar

unread,
Jun 2, 2020, 2:44:23 PM6/2/20
to vim/vim, vim-dev ML, Comment

OK, no recent objections. Let me include this, we can always adjust it.


You are receiving this because you commented.

Gary Johnson

unread,
Jun 2, 2020, 3:05:35 PM6/2/20
to reply+ACY5DGDLVX3VVMWT6B...@reply.github.com, vim...@googlegroups.com
On 2020-06-02, Bram Moolenaar wrote:
> OK, no recent objections. Let me include this, we can always adjust it.

Wouldn't it be better to set this conditionally as is done for
setting the syntax, described in ":help asm.vim" and as implemented
in autoload/dist/ft.vim?

Regards,
Gary

vim-dev ML

unread,
Jun 2, 2020, 3:05:58 PM6/2/20
to vim/vim, vim-dev ML, Your activity

Colin Caine

unread,
Jun 2, 2020, 4:19:13 PM6/2/20
to vim/vim, vim-dev ML, Comment

Thanks for the link to that code, Gary. Unfortunately, it has very little ability to detect which asm syntax is being used:

func dist#ft#FTasmsyntax()
  " see if file contains any asmsyntax=foo overrides. If so, change
  " b:asmsyntax appropriately
  let head = " ".getline(1)." ".getline(2)." ".getline(3)." ".getline(4).
	\" ".getline(5)." "
  let match = matchstr(head, '\sasmsyntax=\zs[a-zA-Z0-9]\+\ze\s')
  if match != ''
    let b:asmsyntax = match
  elseif ((head =~? '\.title') || (head =~? '\.ident') || (head =~? '\.macro') || (head =~? '\.subtitle') || (head =~? '\.library'))
    let b:asmsyntax = "vmasm"
  endif
endfunc

And the default is asm, which is the only one where we would not want these changes...

If the default was instead unknown asm or something, then we could probably do something with that, but that sounds quite breaking. Another option would be to set the comments and commentstring values in ft.vim (where we know if we're selecting asm as the default or if we're sure), but I think in practice that would make very little difference to doing as I have done in this patch (because the default is selected basically every time).


You are receiving this because you commented.

Gary Johnson

unread,
Jun 2, 2020, 11:34:04 PM6/2/20
to reply+ACY5DGHNF6YA7N53VP...@reply.github.com, vim...@googlegroups.com
There are a number of functions in ft.vim that deal with assembly
files. In addition to dist#ft#FTasmsyntax there are also
dist#ft#FTasm() and dist#ft#FTprogress_asm(). The last one looks
in the first ten lines for lines beginning with a semicolon.

I was thinking of something like the following for ftplugin/asm.vim.

if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1

let b:undo_ftplugin = "setlocal comments< commentstring<"

setlocal comments+=:;

call cursor(1, 1)
if search('^\s*;', 'cn', 10)
setlocal commentstring=;%s
endif

That will always include ; in 'comments', which I didn't think would
hurt anything, but changes 'commentstring' only if a semicolon is
the first non-space character in any of the first ten lines of the
buffer.

Regards,
Gary

vim-dev ML

unread,
Jun 2, 2020, 11:34:21 PM6/2/20
to vim/vim, vim-dev ML, Your activity
Reply all
Reply to author
Forward
0 new messages