annotate lisp/modes/asm-mode.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; asm-mode.el --- mode for editing assembler code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1991 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: tools, languages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; This mode was written by Eric S. Raymond <esr@snark.thyrsus.com>,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; inspired by an earlier asm-mode by Martin Neitzel.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; This minor mode is based on text mode. It defines a private abbrev table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; that can be used to save abbrevs for assembler mnemonics. It binds just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; five keys:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; TAB tab to next tab stop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; : outdent preceding label, tab to tab stop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; comment char place or move comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; asm-comment-char specifies which character this is;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; you can use a different character in different
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; Asm mode buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; C-j, C-m newline and tab to tab stop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; Code is indented to the first tab stop level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; This mode runs two hooks:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; 1) An asm-mode-set-comment-hook before the part of the initialization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; depending on asm-comment-char, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; 2) an asm-mode-hook at the end of initialization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (defvar asm-comment-char ?;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 "*The comment-start character assumed by Asm mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defvar asm-support-c-comments-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "*Support C style comments. If t C style comments will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 supported. This is mainly for the benefit of font-lock.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (defvar asm-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "Syntax table used while in Asm mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defvar asm-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 "Abbrev table used while in Asm mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (define-abbrev-table 'asm-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (defvar asm-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 "Keymap for Asm mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (if asm-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (setq asm-mode-map (make-sparse-keymap 'asm-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; Note that the comment character isn't set up until asm-mode is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (define-key asm-mode-map ":" 'asm-colon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (define-key asm-mode-map "\C-i" 'tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (define-key asm-mode-map "\C-j" 'asm-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (define-key asm-mode-map "\C-m" 'asm-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defvar asm-code-level-empty-comment-pattern nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defvar asm-flush-left-empty-comment-pattern nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defvar asm-inline-empty-comment-pattern nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defconst asm-font-lock-keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 '(("^\\(\\(\\sw\\|\\s_\\)+\\)\\>:?[ \t]*\\(\\sw+\\)?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (1 font-lock-function-name-face) (3 font-lock-keyword-face nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ("^\\s +\\(\\(\\sw\\|\\s_\\)+\\)" 1 font-lock-keyword-face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "Additional expressions to highlight in Assembler mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (put 'asm-mode 'font-lock-defaults '(asm-font-lock-keywords))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defun asm-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 "Major mode for editing typical assembler code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 Features a private abbrev table and the following bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 \\[asm-colon]\toutdent a preceding label, tab to next tab stop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 \\[tab-to-tab-stop]\ttab to next tab stop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 \\[asm-newline]\tnewline, then tab to next tab stop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 \\[asm-comment]\tsmart placement of assembler comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 The character used for making comments is set by the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 `asm-comment-char' (which defaults to `?;').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 Alternatively, you may set this variable in `asm-mode-set-comment-hook',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 which is called near the beginning of mode initialization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 Turning on Asm mode runs the hook `asm-mode-hook' at the end of initialization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 Special commands:\\{asm-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (setq mode-name "Assembler")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (setq major-mode 'asm-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (setq local-abbrev-table asm-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (make-local-variable 'asm-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (setq asm-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (set-syntax-table asm-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (run-hooks 'asm-mode-set-comment-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; Make our own local child of asm-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;; so we can define our own comment character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (let ((ourmap (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (set-keymap-parents ourmap (list asm-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (use-local-map ourmap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (local-set-key (vector asm-comment-char) 'asm-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (if asm-support-c-comments-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (modify-syntax-entry ?/ ". 14" asm-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (modify-syntax-entry ?* ". 23" asm-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (modify-syntax-entry asm-comment-char "< b" asm-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (modify-syntax-entry ?\n "> b" asm-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (modify-syntax-entry asm-comment-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 "<" asm-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (modify-syntax-entry ?\n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ">" asm-mode-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (let ((cs (regexp-quote (char-to-string asm-comment-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (make-local-variable 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (setq comment-start (concat cs " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (make-local-variable 'comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq comment-start-skip (concat cs "+[ \t]*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (setq asm-inline-empty-comment-pattern (concat "^.+" cs "+ *$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (setq asm-code-level-empty-comment-pattern (concat "^[\t ]+" cs cs " *$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (setq asm-flush-left-empty-comment-pattern (concat "^" cs cs cs " *$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (make-local-variable 'comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (setq comment-end "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (make-local-variable 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (setq comment-column 32)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq fill-prefix "\t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (run-hooks 'asm-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defun asm-colon ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "Insert a colon; if it follows a label, delete the label's indentation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (if (looking-at "[ \t]+\\(\\sw\\|\\s_\\)+$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (delete-horizontal-space)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (insert ":")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (defun asm-newline ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 "Insert LFD + fill-prefix, to bring us back to code-indent level."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (if (eolp) (delete-horizontal-space))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (defun asm-line-matches (pattern &optional withcomment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (looking-at pattern)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (defun asm-pop-comment-level ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; Delete an empty comment ending current line. Then set up for a new one,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;; on the current line if it was all comment, otherwise above it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (while (= (preceding-char) asm-comment-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (delete-backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (open-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (defun asm-comment ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 "Convert an empty comment to a `larger' kind, or start a new one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 These are the known comment classes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 1 -- comment to the right of the code (at the comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 2 -- comment on its own line, indented like code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 3 -- comment on its own line, beginning at the left-most column.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 Suggested usage: while writing your code, trigger asm-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 repeatedly until you are satisfied with the kind of comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; Blank line? Then start comment at code indent level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ((asm-line-matches "^[ \t]*$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (insert asm-comment-char comment-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; Nonblank line with no comment chars in it?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;; Then start a comment at the current comment column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ((asm-line-matches (format "^[^%c\n]+$" asm-comment-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (indent-for-comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; Flush-left comment present? Just insert character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ((asm-line-matches asm-flush-left-empty-comment-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (insert asm-comment-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; Empty code-level comment already present?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;; Then start flush-left comment, on line above if this one is nonempty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ((asm-line-matches asm-code-level-empty-comment-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (asm-pop-comment-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (insert asm-comment-char asm-comment-char comment-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; Empty comment ends line?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;; Then make code-level comment, on line above if this one is nonempty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ((asm-line-matches asm-inline-empty-comment-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (asm-pop-comment-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (insert asm-comment-char comment-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; If all else fails, insert character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (insert asm-comment-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;;; asm-mode.el ends here