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