+ (run-mode-hooks 'asm-mode-hook))
+
+(defun asm-indent-line ()
+ "Auto-indent the current line."
+ (interactive)
+ (let* ((savep (point))
+ (indent (condition-case nil
+ (save-excursion
+ (forward-line 0)
+ (skip-chars-forward " \t")
+ (if (>= (point) savep) (setq savep nil))
+ (max (asm-calculate-indentation) 0))
+ (error 0))))
+ (if savep
+ (save-excursion (indent-line-to indent))
+ (indent-line-to indent))))
+
+(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)
+ ;; The rest goes at the first tab stop.
+ (or (car tab-stop-list) tab-width)))
+