Mercurial > emacs
annotate lisp/progmodes/asm-mode.el @ 53024:f63cd97f64fd
*** empty log message ***
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Sun, 09 Nov 2003 04:41:22 +0000 |
parents | 695cf19ef79e |
children | 7e610a0ca662 375f2633d815 |
rev | line source |
---|---|
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
1 ;;; asm-mode.el --- mode for editing assembler code |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
2 |
49570
288cda7c05fb
(asm-font-lock-keywords): Allow arbitrary
Andreas Schwab <schwab@suse.de>
parents:
49402
diff
changeset
|
3 ;; Copyright (C) 1991, 2003 Free Software Foundation, Inc. |
869 | 4 |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> |
11098 | 6 ;; Maintainer: FSF |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
7 ;; Keywords: tools, languages |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
8 |
473 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
869 | 13 ;; the Free Software Foundation; either version 2, or (at your option) |
473 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
473 | 25 |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
26 ;;; Commentary: |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
27 |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
28 ;; This mode was written by Eric S. Raymond <esr@snark.thyrsus.com>, |
473 | 29 ;; inspired by an earlier asm-mode by Martin Neitzel. |
30 | |
31 ;; This minor mode is based on text mode. It defines a private abbrev table | |
32 ;; that can be used to save abbrevs for assembler mnemonics. It binds just | |
33 ;; five keys: | |
34 ;; | |
35 ;; TAB tab to next tab stop | |
36 ;; : outdent preceding label, tab to tab stop | |
11105
8963d6de6f07
(asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents:
11098
diff
changeset
|
37 ;; comment char place or move comment |
8963d6de6f07
(asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents:
11098
diff
changeset
|
38 ;; asm-comment-char specifies which character this is; |
8963d6de6f07
(asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents:
11098
diff
changeset
|
39 ;; you can use a different character in different |
8963d6de6f07
(asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents:
11098
diff
changeset
|
40 ;; Asm mode buffers. |
473 | 41 ;; C-j, C-m newline and tab to tab stop |
42 ;; | |
43 ;; Code is indented to the first tab stop level. | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
44 |
473 | 45 ;; This mode runs two hooks: |
11098 | 46 ;; 1) An asm-mode-set-comment-hook before the part of the initialization |
473 | 47 ;; depending on asm-comment-char, and |
48 ;; 2) an asm-mode-hook at the end of initialization. | |
49 | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
50 ;;; Code: |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
51 |
20781 | 52 (defgroup asm nil |
53 "Mode for editing assembler code." | |
54 :group 'languages) | |
55 | |
23312 | 56 (defcustom asm-comment-char ?\; |
20781 | 57 "*The comment-start character assumed by Asm mode." |
58 :type 'character | |
59 :group 'asm) | |
473 | 60 |
50397
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
61 (defvar asm-mode-syntax-table |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
62 (let ((st (make-syntax-table))) |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
63 (modify-syntax-entry ?\n ">" st) |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
64 (modify-syntax-entry ?/ ". 14b" st) |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
65 (modify-syntax-entry ?* ". 23b" st) |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
66 st) |
2670 | 67 "Syntax table used while in Asm mode.") |
473 | 68 |
69 (defvar asm-mode-abbrev-table nil | |
2670 | 70 "Abbrev table used while in Asm mode.") |
473 | 71 (define-abbrev-table 'asm-mode-abbrev-table ()) |
72 | |
50397
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
73 (defvar asm-mode-map |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
74 (let ((map (make-sparse-keymap))) |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
75 ;; Note that the comment character isn't set up until asm-mode is called. |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
76 (define-key map ":" 'asm-colon) |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
77 (define-key map "\C-c;" 'comment-region) |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
78 (define-key map "\C-j" 'newline-and-indent) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
79 (define-key map "\C-m" 'newline-and-indent) |
50397
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
80 map) |
2670 | 81 "Keymap for Asm mode.") |
473 | 82 |
9385
297f0781c8ae
(asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7384
diff
changeset
|
83 (defconst asm-font-lock-keywords |
49570
288cda7c05fb
(asm-font-lock-keywords): Allow arbitrary
Andreas Schwab <schwab@suse.de>
parents:
49402
diff
changeset
|
84 '(("^\\(\\(\\sw\\|\\s_\\)+\\)\\>:?[ \t]*\\(\\sw+\\(\\.\\sw+\\)*\\)?" |
9385
297f0781c8ae
(asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7384
diff
changeset
|
85 (1 font-lock-function-name-face) (3 font-lock-keyword-face nil t)) |
51655
abc46b69deaa
* progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents:
50401
diff
changeset
|
86 ;; label started from ".". |
abc46b69deaa
* progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents:
50401
diff
changeset
|
87 ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>:" |
abc46b69deaa
* progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents:
50401
diff
changeset
|
88 1 font-lock-function-name-face) |
abc46b69deaa
* progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents:
50401
diff
changeset
|
89 ("^\\((\\sw+)\\)?\\s +\\(\\(\\.?\\sw\\|\\s_\\)+\\(\\.\\sw+\\)*\\)" |
abc46b69deaa
* progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents:
50401
diff
changeset
|
90 2 font-lock-keyword-face) |
abc46b69deaa
* progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents:
50401
diff
changeset
|
91 ;; directive started from ".". |
abc46b69deaa
* progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents:
50401
diff
changeset
|
92 ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>[^:]?" |
abc46b69deaa
* progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents:
50401
diff
changeset
|
93 1 font-lock-keyword-face)) |
9385
297f0781c8ae
(asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7384
diff
changeset
|
94 "Additional expressions to highlight in Assembler mode.") |
297f0781c8ae
(asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7384
diff
changeset
|
95 |
473 | 96 ;;;###autoload |
97 (defun asm-mode () | |
98 "Major mode for editing typical assembler code. | |
2670 | 99 Features a private abbrev table and the following bindings: |
473 | 100 |
101 \\[asm-colon]\toutdent a preceding label, tab to next tab stop. | |
102 \\[tab-to-tab-stop]\ttab to next tab stop. | |
103 \\[asm-newline]\tnewline, then tab to next tab stop. | |
104 \\[asm-comment]\tsmart placement of assembler comments. | |
105 | |
106 The character used for making comments is set by the variable | |
23312 | 107 `asm-comment-char' (which defaults to `?\\;'). |
473 | 108 |
11098 | 109 Alternatively, you may set this variable in `asm-mode-set-comment-hook', |
110 which is called near the beginning of mode initialization. | |
473 | 111 |
2670 | 112 Turning on Asm mode runs the hook `asm-mode-hook' at the end of initialization. |
473 | 113 |
6469 | 114 Special commands: |
50397
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
115 \\{asm-mode-map}" |
473 | 116 (interactive) |
117 (kill-all-local-variables) | |
118 (setq mode-name "Assembler") | |
119 (setq major-mode 'asm-mode) | |
120 (setq local-abbrev-table asm-mode-abbrev-table) | |
9472
06623e3543db
* asm-mode.el: (asm-mode): Set font-lock-defaults.
Simon Marshall <simon@gnu.org>
parents:
9385
diff
changeset
|
121 (make-local-variable 'font-lock-defaults) |
06623e3543db
* asm-mode.el: (asm-mode): Set font-lock-defaults.
Simon Marshall <simon@gnu.org>
parents:
9385
diff
changeset
|
122 (setq font-lock-defaults '(asm-font-lock-keywords)) |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
123 (set (make-local-variable 'indent-line-function) 'asm-indent-line) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
124 ;; Stay closer to the old TAB behavior (was tab-to-tab-stop). |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
125 (set (make-local-variable 'tab-always-indent) nil) |
11105
8963d6de6f07
(asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents:
11098
diff
changeset
|
126 |
473 | 127 (run-hooks 'asm-mode-set-comment-hook) |
11105
8963d6de6f07
(asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents:
11098
diff
changeset
|
128 ;; Make our own local child of asm-mode-map |
8963d6de6f07
(asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents:
11098
diff
changeset
|
129 ;; so we can define our own comment character. |
8963d6de6f07
(asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents:
11098
diff
changeset
|
130 (use-local-map (nconc (make-sparse-keymap) asm-mode-map)) |
8963d6de6f07
(asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents:
11098
diff
changeset
|
131 (local-set-key (vector asm-comment-char) 'asm-comment) |
50397
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
132 (set-syntax-table (make-syntax-table asm-mode-syntax-table)) |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
133 (modify-syntax-entry asm-comment-char "<") |
49402
99a31f21f1c9
(asm-mode): Added syntax table entries for /* */ comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
31983
diff
changeset
|
134 |
50397
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
135 (make-local-variable 'comment-start) |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
136 (setq comment-start (string asm-comment-char)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
137 (make-local-variable 'comment-add) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
138 (setq comment-add 1) |
50397
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
139 (make-local-variable 'comment-start-skip) |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
140 (setq comment-start-skip "\\(?:\\s<+\\|/\\*+\\)[ \t]*") |
a3e1934e4ead
(asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50352
diff
changeset
|
141 (make-local-variable 'comment-end-skip) |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
142 (setq comment-end-skip "[ \t]*\\(\\s>\\|\\*+/\\)") |
473 | 143 (make-local-variable 'comment-end) |
144 (setq comment-end "") | |
145 (setq fill-prefix "\t") | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
146 (run-mode-hooks 'asm-mode-hook)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
147 |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
148 (defun asm-indent-line () |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
149 "Auto-indent the current line." |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
150 (interactive) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
151 (let* ((savep (point)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
152 (indent (condition-case nil |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
153 (save-excursion |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
154 (forward-line 0) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
155 (skip-chars-forward " \t") |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
156 (if (>= (point) savep) (setq savep nil)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
157 (max (asm-calculate-indentation) 0)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
158 (error 0)))) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
159 (if savep |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
160 (save-excursion (indent-line-to indent)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
161 (indent-line-to indent)))) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
162 |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
163 (defun asm-calculate-indentation () |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
164 (or |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
165 ;; Flush labels to the left margin. |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
166 (and (looking-at "\\(\\sw\\|\\s_\\)+:") 0) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
167 ;; Same thing for `;;;' comments. |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
168 (and (looking-at "\\s<\\s<\\s<") 0) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
169 ;; Simple `;' comments go to the comment-column. |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
170 (and (looking-at "\\s<\\(\\S<\\|\\'\\)") comment-column) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
171 ;; The rest goes at the first tab stop. |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
172 (or (car tab-stop-list) tab-width))) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
173 |
473 | 174 (defun asm-colon () |
175 "Insert a colon; if it follows a label, delete the label's indentation." | |
176 (interactive) | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
177 (let ((labelp nil)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
178 (save-excursion |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
179 (skip-syntax-backward "w_") |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
180 (skip-syntax-backward " ") |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
181 (if (setq labelp (bolp)) (delete-horizontal-space))) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
182 (call-interactively 'self-insert-command) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
183 (when labelp |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
184 (delete-horizontal-space) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
185 (tab-to-tab-stop)))) |
473 | 186 |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
187 ;; Obsolete since Emacs-21.4. |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
188 (defalias 'asm-newline 'newline-and-indent) |
473 | 189 |
190 (defun asm-comment () | |
191 "Convert an empty comment to a `larger' kind, or start a new one. | |
192 These are the known comment classes: | |
193 | |
194 1 -- comment to the right of the code (at the comment-column) | |
195 2 -- comment on its own line, indented like code | |
196 3 -- comment on its own line, beginning at the left-most column. | |
197 | |
198 Suggested usage: while writing your code, trigger asm-comment | |
199 repeatedly until you are satisfied with the kind of comment." | |
200 (interactive) | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
201 (comment-normalize-vars) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
202 (let (comempty comment) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
203 (save-excursion |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
204 (beginning-of-line) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
205 (setq comment (comment-search-forward (line-end-position) t)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
206 (setq comempty (looking-at "[ \t]*$"))) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
207 |
473 | 208 (cond |
209 | |
210 ;; Blank line? Then start comment at code indent level. | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
211 ;; Just like `comment-dwim'. -stef |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
212 ((save-excursion (beginning-of-line) (looking-at "^[ \t]*$")) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
213 (indent-according-to-mode) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
214 (insert asm-comment-char asm-comment-char ?\ )) |
473 | 215 |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
216 ;; Nonblank line w/o comment => start a comment at comment-column. |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
217 ;; Also: point before the comment => jump inside. |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
218 ((or (null comment) (< (point) comment)) |
473 | 219 (indent-for-comment)) |
220 | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
221 ;; Flush-left or non-empty comment present => just insert character. |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
222 ((or (not comempty) (save-excursion (goto-char comment) (bolp))) |
473 | 223 (insert asm-comment-char)) |
224 | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
225 ;; Empty code-level comment => upgrade to next comment level. |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
226 ((save-excursion (goto-char comment) (skip-chars-backward " \t") (bolp)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
227 (goto-char comment) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
228 (insert asm-comment-char) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
229 (indent-for-comment)) |
473 | 230 |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
231 ;; Empty comment ends non-empty code line => new comment above. |
473 | 232 (t |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
233 (goto-char comment) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
234 (skip-chars-backward " \t") |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
235 (delete-region (point) (line-end-position)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
236 (beginning-of-line) (insert "\n") (backward-char) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
237 (asm-comment))))) |
473 | 238 |
18383 | 239 (provide 'asm-mode) |
240 | |
52401 | 241 ;;; arch-tag: 210e695f-f338-4376-8913-a4c5c72ac848 |
473 | 242 ;;; asm-mode.el ends here |