如何设置Emacs进行汇编编程和修复缩进? [英] How to set Emacs up for assembly programming and fix indentation?

查看:59
本文介绍了如何设置Emacs进行汇编编程和修复缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to set Emacs up for assembly programming and fix indentation?

Emacs烦人地缩进了某些指令.

Emacs is indenting some directives in an annoying way.

特别是,下面的 global extern section 关键字缩进为代码.

Especially, the global, extern and section keywords below are indented as code.

我希望这些关键字左对齐.该怎么办?

I want these keywords left-aligned. How can this be done?

此外,有什么值得推荐的好的汇编编程模式吗?

In addition, are there any good modes for assembly programming that is worth recommending?

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


语法突出显示确实可以在asm模式下工作:


Syntax highlighting does work in asm mode, though:

推荐答案

我在Linux上的〜/.emacs 中使用它来自定义asm模式,使其相当可用于NASM语法,并且对于GAS语法来说还可以.(语法突出显示等使用; 作为注释字符,因此带有#的GAS太糟了.我没有考虑更改它.)

I use this in my ~/.emacs on Linux to customize asm-mode, making it fairly usable for NASM syntax, and moderately ok for GAS syntax. (Syntax highlighting and so on use ; as the comment character, so GAS with # is a mess. I haven't looked into changing that).

我未定义电注释内容,因此可以输入; ,而无需使用asm-mode,前提是它知道我要在哪里注释.

I undefine the electric-comment thing so I can type ; without asm-mode assuming it knows where I want the comment.

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

I set up some regexes to set the indent column to 0 for %nasm_macro directive, global, section, and labels (ending with :)

(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)

按Enter键可自动缩进光标先前所在的行.按Control-O插入换行符而不会触发自动缩进.

Pressing enter auto-indents the line the cursor was previously on. Press control-O to insert a newline without triggering auto-indent.

Enter总是将您带到第4列.如果键入类似 .my_loop:的内容,则在您按回车键之前,它会缩进错误,因此需要一些时间来习惯快速键入和不需要按回车键后将其缩进一行.

Enter always takes you to column 4. If you type something like .my_loop:, it will be indented wrong until you press return, so it takes a bit of getting used to to type quickly and not expect to need to go back and fix the indent on a line after pressing enter.

按TAB键将自动缩进一行,但再次按该行将缩进下一个制表位.

Pressing TAB will auto-indent a line, but pressing it again will indent to the next tab stop.

Arch Linux上的Emacs 25.3.1,正在编辑正在进行的代码高尔夫球答案.(当然,我只是为了截屏目的而使窗口变小.)所有这些行都是其自然的缩进形式.注释大部分位于meta- ; 放置在其上的列.

Emacs 25.3.1 on Arch Linux, editing an in-progress code-golf answer. (I made the window small only for screenshot purposes, of course.) All of these lines are at their natural indentation. Comments are mostly at the column that meta-; places them on.

这篇关于如何设置Emacs进行汇编编程和修复缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆