annotate lisp/modes/asm-mode.el @ 189:489f57a838ef r20-3b21

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