annotate lisp/progmodes/asm-mode.el @ 1550:279b5a572def

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