如何设置Emacs进行汇编编程并修复缩进?

时间:2016-07-30 10:35:47

标签: windows assembly emacs

  

如何设置Emacs进行汇编编程并修复缩进?

Emacs正在以令人讨厌的方式缩进某些指令。

特别是,下面的globalexternsection关键字缩进为代码。

我希望这些关键字左对齐。怎么办呢?

此外,是否有值得推荐的汇编编程模式?

        global _main
        extern _printf
        section .text
_main:
        push msg
        call _printf
        add esp, 4
        ret
msg:
        db 'HelloWorld', 0

语法高亮显示在asm模式下有效:

enter image description here

1 个答案:

答案 0 :(得分:0)

我在Linux上的~/.emacs中使用它来自定义asm-mode,使其可用于NASM语法,并且适用于GAS语法。 (语法突出显示等等使用;作为注释字符,因此带有#的GAS是一团糟。我没有考虑改变它。)

我取消定义电子评论的内容,因此我可以在没有asm-mode的情况下键入;,假设它知道我想要评论的位置。

我设置了一些正则表达式,将{1}}指令的缩进列设置为0,%nasm_macroglobal和标签(以section结尾)

:

按Enter键自动缩进光标之前的行。按control-O插入换行符而不触发自动缩进。

Enter总是将您带到第4列。如果您键入类似(defun my-asm-mode-hook () ;; you can use `comment-dwim' (M-;) for this kind of behaviour anyway (local-unset-key (vector asm-comment-char)) ;; (local-unset-key "<return>") ; doesn't work. "RET" in a terminal. http://emacs.stackexchange.com/questions/13286/how-can-i-stop-the-enter-key-from-triggering-a-completion-in-company-mode (electric-indent-local-mode) ; toggle off ; (setq tab-width 4) (setq indent-tabs-mode nil) ;; asm-mode sets it locally to nil, to "stay closer to the old TAB behaviour". ;; (setq tab-always-indent (default-value 'tab-always-indent)) (defun asm-calculate-indentation () (or ;; Flush labels to the left margin. ; (and (looking-at "\\(\\.\\|\\sw\\|\\s_\\)+:") 0) (and (looking-at "[.@_[:word:]]+:") 0) ;; Same thing for `;;;' comments. (and (looking-at "\\s<\\s<\\s<") 0) ;; %if nasm macro stuff goes to the left margin (and (looking-at "%") 0) (and (looking-at "c?global\\|section\\|default\\|align\\|INIT_..X") 0) ;; Simple `;' comments go to the comment-column ;(and (looking-at "\\s<\\(\\S<\\|\\'\\)") comment-column) ;; The rest goes at column 4 (or 4))) ) (add-hook 'asm-mode-hook #'my-asm-mode-hook) 的内容,则在按下return之前会缩进错误,因此需要一些时间来习惯快速键入并且不需要按回车键后返回并在行上修复缩进。

按TAB键将自动缩进一行,但再次按下它将缩进到下一个制表位。

在Arch Linux上使用Emacs 25.3.1,编辑正在进行的代码 - 高尔夫答案。 (当然,我只是为了屏幕截图而使窗口很小。)所有这些线条都处于自然缩进状态。评论主要位于元 - .my_loop:将其放置的列上。

enter image description here

相关问题