12

When I write C or Java code it's extremely regular, but with assembly (asm-mode), it's so disorganized.

I'm using auto-complete and yasnippet. I created snippets and am using them, but the code organization and indentation are disorganized.

What package(s) would help me:

  • easily indent code and comments properly, so that I can see what each piece of code is doing;
  • navigate that large mass of code, so I can easily jump between pieces of code?
Vivian Maya
  • 787
  • 1
  • 6
  • 17
  • 3
    Please try to make your question more specific. For example: what do you think `asm-mode` should do, but does not? (What features are missing?) – Constantine Dec 13 '14 at 23:23
  • 2
    The [EmacsWiki](http://www.emacswiki.org/emacs/AssemblyProgramming) has a few options listed for assembly. But please edit your question to be more specific about the problem and what you've done so far. "Any useful package" covers a lot of ground. – Dan Dec 13 '14 at 23:51
  • Why close this question? Making indentation works (`asm-mode` behaves differently to everything else) and configuring a decent environment (jump around, code completion) is a valid concert. – Tu Do Dec 15 '14 at 16:32
  • 1
    For users who wanted this question reopened, please see [this meta discussion](http://meta.emacs.stackexchange.com/questions/233/reopen-this-package-recommendation-question). Please help to clean up the question and clarify it, or else it stands a non-trivial chance that other users will vote to close it again. – Dan Dec 15 '14 at 18:59

2 Answers2

11

Just use the built-in asm-mode. It gives you syntax highlighting for any assembly languages. gas-mode does not do that and is not usable with AT&T syntax.

If you want to set indentation for asm-mode, note that you cannot use tab-width but tab-stop-list that specifies spaces that 1 tab, 2 tabs, 3 tabs... can display:

(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60
                      64 68 72 76 80 84 88 92 96 100 104 108 112
                      116 120))

The above example means that the fist tab has 4 spaces, 2nd tab (next to the first tab) has 8 spaces, 3rd tab (next to the second tab) has 12 spaces... and so on.

You can also generate the list like this:

(setq tab-stop-list (number-sequence 2 60 2))

number-sequence generates a list of number, with starting number 2 (the first argument) upto 60 (the second argument), each number differs by 2 to the number next to it. And remember to bind newline-and-indent to RET, so Emacs automatically indents for you.

If you want to jump around, use Ctags like this:

ctags -e -R

-e means generate tag database to be used by Emacs. -R means recursively generate tags for files in sub-directories from project root.

After that, you can use helm-etags-select to jump around or another etags client in Emacs if you don't use Helm.

EDIT: Here is a sample setup:

(require 'asm-mode)
(add-hook 'asm-mode-hook (lambda ()
                           (setq indent-tabs-mode nil) ; use spaces to indent
                           (electric-indent-mode -1) ; indentation in asm-mode is annoying
                           (setq tab-stop-list (number-sequence 2 60 2))))

(define-key asm-mode-map (kbd "<ret>") 'newline-and-indent)
(define-key asm-mode-map (kbd "M-.") 'helm-etags-select)

You can also have basic completion with company-complete when pressing S-TAB:

(define-key asm-mode-map (kbd "<backtab>") 'company-complete)

You can use <tab> to trigger completion because both <tab> and M-i run the same command tab-to-tab-stop that inserts spaces or tabs depends on your setting of indent-tabs-mode. The nice thing with company-mode is that you get a brief description of currently highlighted candidate in the minibuffer, if available. For example, if you have a definition like this:

KeyStrokes  word    0

When you move the cursor to KeyStrokes candidate, it prints word 0 in the minibuffer.

Tu Do
  • 6,772
  • 20
  • 39
3

You might try Gas Mode. It should help you with your issue.

http://www.emacswiki.org/GasMode

kmarker
  • 31
  • 2