Mercurial > emacs
comparison lisp/progmodes/asm-mode.el @ 473:999d0b38694e
Initial revision
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sat, 21 Dec 1991 08:23:15 +0000 |
parents | |
children | 8a533acedb77 |
comparison
equal
deleted
inserted
replaced
472:e6b49c51a9bb | 473:999d0b38694e |
---|---|
1 ;; Mode for editing assembler code | |
2 ;; Copyright (C) 1991 Free Software Foundation, Inc. | |
3 | |
4 ;; This file is part of GNU Emacs. | |
5 | |
6 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
7 ;; it under the terms of the GNU General Public License as published by | |
8 ;; the Free Software Foundation; either version 1, or (at your option) | |
9 ;; any later version. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 ;; GNU General Public License for more details. | |
15 | |
16 ;; You should have received a copy of the GNU General Public License | |
17 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | |
20 ;; This mode was written for Eric S. Raymond <eric@snark.thyrsus.com>, | |
21 ;; inspired by an earlier asm-mode by Martin Neitzel. | |
22 ;; @(#)asm-mode.el 1.1 | |
23 | |
24 ;; This minor mode is based on text mode. It defines a private abbrev table | |
25 ;; that can be used to save abbrevs for assembler mnemonics. It binds just | |
26 ;; five keys: | |
27 ;; | |
28 ;; TAB tab to next tab stop | |
29 ;; : outdent preceding label, tab to tab stop | |
30 ;; ; place or move comment | |
31 ;; C-j, C-m newline and tab to tab stop | |
32 ;; | |
33 ;; Code is indented to the first tab stop level. | |
34 ;; The ; key inserts copies of the value of asm-comment-char at an | |
35 ;; appropriate spot. | |
36 ;; This mode runs two hooks: | |
37 ;; 1) An asm-set-comment-hook before the part of the initialization | |
38 ;; depending on asm-comment-char, and | |
39 ;; 2) an asm-mode-hook at the end of initialization. | |
40 | |
41 (defvar asm-comment-char ?; | |
42 "*The comment-start character assumed by asm-mode.") | |
43 | |
44 (defvar asm-mode-syntax-table nil | |
45 "Syntax table used while in asm mode.") | |
46 | |
47 (defvar asm-mode-abbrev-table nil | |
48 "Abbrev table used while in asm mode.") | |
49 (define-abbrev-table 'asm-mode-abbrev-table ()) | |
50 | |
51 (defvar asm-mode-map nil | |
52 "Keymap for asm-mode") | |
53 | |
54 (if asm-mode-map | |
55 nil | |
56 (setq asm-mode-map (make-sparse-keymap)) | |
57 (define-key asm-mode-map ";" 'asm-comment) | |
58 (define-key asm-mode-map ":" 'asm-colon) | |
59 (define-key asm-mode-map "\C-i" 'tab-to-tab-stop) | |
60 (define-key asm-mode-map "\C-j" 'asm-newline) | |
61 (define-key asm-mode-map "\C-m" 'asm-newline) | |
62 ) | |
63 | |
64 (defvar asm-code-level-empty-comment-pattern nil) | |
65 (defvar asm-flush-left-empty-comment-pattern nil) | |
66 (defvar asm-inline-empty-comment-pattern nil) | |
67 | |
68 ;;;###autoload | |
69 (defun asm-mode () | |
70 "Major mode for editing typical assembler code. | |
71 Features a private asm-mode-abbrev-table and the following bindings: | |
72 | |
73 \\[asm-colon]\toutdent a preceding label, tab to next tab stop. | |
74 \\[tab-to-tab-stop]\ttab to next tab stop. | |
75 \\[asm-newline]\tnewline, then tab to next tab stop. | |
76 \\[asm-comment]\tsmart placement of assembler comments. | |
77 | |
78 The character used for making comments is set by the variable | |
79 asm-comment-char (which defaults to ?;). You may want to set this | |
80 appropriately for the assembler on your machine in defaults.el. | |
81 | |
82 Alternatively, you may set this variable in asm-set-comment-hook, which is | |
83 called near the beginning of mode initialization. | |
84 | |
85 Turning on asm-mode calls the value of the variable asm-mode-hook, | |
86 if that value is non-nil, at the end of initialization. | |
87 | |
88 Special commands:\\{asm-mode-map} | |
89 " | |
90 (interactive) | |
91 (kill-all-local-variables) | |
92 (use-local-map asm-mode-map) | |
93 (setq mode-name "Assembler") | |
94 (setq major-mode 'asm-mode) | |
95 (setq local-abbrev-table asm-mode-abbrev-table) | |
96 (make-local-variable 'asm-mode-syntax-table) | |
97 (setq asm-mode-syntax-table (make-syntax-table)) | |
98 (set-syntax-table asm-mode-syntax-table) | |
99 (run-hooks 'asm-mode-set-comment-hook) | |
100 (modify-syntax-entry asm-comment-char | |
101 "<" asm-mode-syntax-table) | |
102 (modify-syntax-entry ?\n | |
103 ">" asm-mode-syntax-table) | |
104 (let ((cs (regexp-quote (char-to-string asm-comment-char)))) | |
105 (make-local-variable 'comment-start) | |
106 (setq comment-start (concat cs " ")) | |
107 (make-local-variable 'comment-start-skip) | |
108 (setq comment-start-skip (concat cs "+[ \t]*")) | |
109 (setq asm-inline-empty-comment-pattern (concat "^.+" cs "+ *$")) | |
110 (setq asm-code-level-empty-comment-pattern (concat "^[\t ]+" cs cs " *$")) | |
111 (setq asm-flush-left-empty-comment-pattern (concat "^" cs cs cs " *$")) | |
112 ) | |
113 (make-local-variable 'comment-end) | |
114 (setq comment-end "") | |
115 (make-local-variable 'comment-column) | |
116 (setq comment-column 32) | |
117 (auto-fill-mode 1) | |
118 (setq fill-prefix "\t") | |
119 (run-hooks 'asm-mode-hook) | |
120 ) | |
121 | |
122 | |
123 (defun asm-colon () | |
124 "Insert a colon; if it follows a label, delete the label's indentation." | |
125 (interactive) | |
126 (save-excursion | |
127 (beginning-of-line) | |
128 (if (looking-at "[ \t]+\\(\\sw\\|\\s_\\)+$") | |
129 (delete-horizontal-space))) | |
130 (insert ":") | |
131 (tab-to-tab-stop) | |
132 ) | |
133 | |
134 (defun asm-newline () | |
135 "Insert LFD + fill-prefix, to bring us back to code-indent level." | |
136 (interactive) | |
137 (if (eolp) (delete-horizontal-space)) | |
138 (insert "\n") | |
139 (tab-to-tab-stop) | |
140 ) | |
141 | |
142 (defun asm-line-matches (pattern &optional withcomment) | |
143 (save-excursion | |
144 (beginning-of-line) | |
145 (looking-at pattern))) | |
146 | |
147 (defun asm-pop-comment-level () | |
148 ;; Delete an empty comment ending current line. Then set up for a new one, | |
149 ;; on the current line if it was all comment, otherwise above it | |
150 (end-of-line) | |
151 (delete-horizontal-space) | |
152 (while (= (preceding-char) asm-comment-char) | |
153 (delete-backward-char 1)) | |
154 (delete-horizontal-space) | |
155 (if (bolp) | |
156 nil | |
157 (beginning-of-line) | |
158 (open-line 1)) | |
159 ) | |
160 | |
161 | |
162 (defun asm-comment () | |
163 "Convert an empty comment to a `larger' kind, or start a new one. | |
164 These are the known comment classes: | |
165 | |
166 1 -- comment to the right of the code (at the comment-column) | |
167 2 -- comment on its own line, indented like code | |
168 3 -- comment on its own line, beginning at the left-most column. | |
169 | |
170 Suggested usage: while writing your code, trigger asm-comment | |
171 repeatedly until you are satisfied with the kind of comment." | |
172 (interactive) | |
173 (cond | |
174 | |
175 ;; Blank line? Then start comment at code indent level. | |
176 ((asm-line-matches "^[ \t]*$") | |
177 (delete-horizontal-space) | |
178 (tab-to-tab-stop) | |
179 (insert asm-comment-char comment-start)) | |
180 | |
181 ;; Nonblank line with no comment chars in it? | |
182 ;; Then start a comment at the current comment column | |
183 ((asm-line-matches (format "^[^%c]+$" asm-comment-char)) | |
184 (indent-for-comment)) | |
185 | |
186 ;; Flush-left comment present? Just insert character. | |
187 ((asm-line-matches asm-flush-left-empty-comment-pattern) | |
188 (insert asm-comment-char)) | |
189 | |
190 ;; Empty code-level comment already present? | |
191 ;; Then start flush-left comment, on line above if this one is nonempty. | |
192 ((asm-line-matches asm-code-level-empty-comment-pattern) | |
193 (asm-pop-comment-level) | |
194 (insert asm-comment-char asm-comment-char comment-start)) | |
195 | |
196 ;; Empty comment ends line? | |
197 ;; Then make code-level comment, on line above if this one is nonempty. | |
198 ((asm-line-matches asm-inline-empty-comment-pattern) | |
199 (asm-pop-comment-level) | |
200 (tab-to-tab-stop) | |
201 (insert asm-comment-char comment-start)) | |
202 | |
203 ;; If all else fails, insert character | |
204 (t | |
205 (insert asm-comment-char)) | |
206 | |
207 ) | |
208 (end-of-line)) | |
209 | |
210 ;;; asm-mode.el ends here |