annotate lisp/modes/asm-mode.el @ 80:1ce6082ce73f r20-0b90

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