Harry Weston
Harry Weston

Reputation: 716

How do I set up emacs for PIC assembler code

I want to use emacs for drafting and editing assembler code that I can insert into Microchip MPLAB IDE for PIC projects. If I use .asm as the file extension I get a funny effect when I use a semi-colon in column one to start off a comment line -- the next line is always indented. How can I avoid this? I have "gas" as the major mode for .asm files to try to do this, but it has no effect.

Perhaps the real problem is that I do not understand the descriptions of how these modes work.

Upvotes: 4

Views: 834

Answers (1)

Cory Koch
Cory Koch

Reputation: 514

You can redefine asm-calculate-indentation by placing the function below in your init.el. To "test drive" the function you can paste it in your scratch buffer, eval it, and perform some editing in an asm file to see if this is what you want.

(defun asm-calculate-indentation ()
  (or
   ;; Flush labels to the left margin.
   (and (looking-at "\\(\\sw\\|\\s_\\)+:") 0)
   ;; Same thing for `;;;' comments.
   (and (looking-at "\\s<\\s<\\s<") 0)
   ;; Simple `;' comments go to the comment-column.
   (and (looking-at "\\s<\\(\\S<\\|\\'\\)") comment-column)
   ;; Do not indent after ';;;' comments.
   (and (progn
          (previous-line)
          (beginning-of-line)
          (looking-at "\\s<\\s<\\s<")) 0)
   ;;The rest goes at the first tab stop.
   (or (car tab-stop-list) tab-width))

This will make it so that line directly below the ;;; will not auto indent. I do not know if you noticed, but if you leave the definition as is; if the next thing you put under the comment is a label when you enter the : the label will auto indent to the left, and everything below the label auto indents. I can see where this would be annoying for commenting directives or header comments though.

Upvotes: 2

Related Questions