When I try to insert a semicolon in my code (in asm-mode) it seems to indent a certain number of tabs like this (usually 4 it seems):

D               ;

And if I put another semicolon on the next line it will indent one tab so it looks like this and add another semicolon even though I only pressed it once:

D               ;

I am sure this is some helpful auto-complete technique, but I am just trying to do commands with a semicolon inside of it like 0;JEQ but since I am an Emacs noob I don't know where to look to deactivate this. I searched with different queries looking for this problem, but I am having trouble finding it which is weird since everything else I looked up was easily answerable either from the Emacs manual or some other site. Can anyone point me to which option I can change so no white space is inserted?

Edit: Here is what option I changed my comment button to:

asm comment char

Is this correct? Basically, I just deleted the comment char which was ";" to what it is now which is "/", but like I say the same problem happens where when I press the semicolon key I get a slash instead and my slash key still gives me a slash.

  • 1
    What major mode is this, asm-mode?
    – wasamasa
    Commented Dec 7, 2017 at 22:32
  • Good call -- that looks fairly assemblerish, and in asm-mode I see that C-h k ; reports that ; is bound to asm-comment. Presumably ; is not a comment in the language being used here. M-x customize-option RET asm-comment-char would deal to that. (That might well not be the only misconfiguration for this language, however.)
    – phils
    Commented Dec 8, 2017 at 0:47
  • Yes it does say I am in asm-mode, and I tried M-x customize-option RET asm-comment-char, but I don't seem to know how to do it. Do I type it all one line? I tried M-x customize-option and then it asked me which variable to customize but I couldn't seem to get the rest of it to work. Also // and /**/ work for commenting which is strange since I would think that if ; is used for commenting then those wouldn't work? Commented Dec 8, 2017 at 5:28
  • @phils It seems I was successful in changing ";" comment char to "/" (it would only let me do one letter?). But now whenever I type the button on my keyboard that used to be semicolon it writes a "/". Like I say the double slash for comments already seem to be highlighted like I want, but I just want it so whenever I type a semicolon it doesn't indent a bunch. Did I do something wrong perhaps? Commented Dec 8, 2017 at 19:13
  • Based on my test, asm-comment-char tells the mode which key to bind to the asm-comment command, so typing / should now do the commenting action, and typing ; should insert a semicolon. You might need to revert your existing asm-mode buffers for that change to be picked up?
    – phils
    Commented Dec 9, 2017 at 1:28

2 Answers 2


In asm-mode, C-hk; reports that ; is bound to asm-comment.

The Commentary for asm-mode.el (M-x find-library RET asm-mode RET) says:

This minor mode is based on text mode.  It defines a private abbrev table
that can be used to save abbrevs for assembler mnemonics.  It binds just
five keys:

        TAB             tab to next tab stop
        :               outdent preceding label, tab to tab stop
        comment char    place or move comment
                        asm-comment-char specifies which character this is;
                        you can use a different character in different
                        Asm mode buffers.
        C-j, C-m        newline and tab to tab stop

Code is indented to the first tab stop level.

This mode runs two hooks:
  1) An asm-mode-set-comment-hook before the part of the initialization
depending on asm-comment-char, and
  2) an asm-mode-hook at the end of initialization.

So the variable asm-comment-char defines the comment character, and the mode uses this value to bind the associated key to the asm-comment command (i.e. "place or move comment").

You can configure this value globally via M-x customize-option RET asm-comment-char RET

Exactly how this feature works is entirely up to how the mode is written. In this case I can see that when the asm-mode function is called it generates a new local keymap for the buffer which inherits from asm-mode-map, and it defines the comment key in there.

Immediately before it does that it runs asm-mode-set-comment-hook, so one could also set a value for asm-comment-char (potentially a buffer-local value) using that hook, instead of customizing the option globally.

All of this commenting configuration happens when the asm-mode function runs, so changing the global value doesn't affect existing asm-mode buffers; but you could just run M-x asm-mode in a buffer to get it to pick on on a change to asm-comment-char, or you could revert the buffer(s), or re-visit them.


  • M-x revert-buffer
  • or kill the buffer and re-visit it
  • or use something like M-x ibuffer to mark and revert buffers en-masse

In ibuffer that would be *M asm-mode RET to mark, and V to revert.

Note that the way the keymap is generated means that each asm-mode buffer has its own independent comment key binding, so reverting a single buffer will not affect the pre-existing comment bindings in other asm-mode buffers, so reverting them all after a change to the global comment char option would make sense.


A quick hack to disable this confusing functionality entirely is:

(advice-add #'asm-comment :override #'self-insert-command)

Then pressing your comment character will just insert it like you were expecting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.