annotate lisp/progmodes/asm-mode.el @ 27522:65d84be1e92d

(command-line): Use w32-tty-standard-colors when in w32 console mode.
author Jason Rumney <jasonr@gnu.org>
date Sun, 30 Jan 2000 19:02:51 +0000
parents f26b378dc6a2
children eb15bee6f5e7
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>
11098
03b481b6cec2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 9472
diff changeset
6 ;; Maintainer: FSF
810
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
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; 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
13 ;; the Free Software Foundation; either version 2, or (at your option)
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; any later version.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 11105
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 11105
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 11105
diff changeset
24 ;; Boston, MA 02111-1307, USA.
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
810
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
26 ;;; Commentary:
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
27
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
28 ;; This mode was written by Eric S. Raymond <esr@snark.thyrsus.com>,
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 ;; inspired by an earlier asm-mode by Martin Neitzel.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 ;; 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
32 ;; that can be used to save abbrevs for assembler mnemonics. It binds just
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ;; five keys:
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;;
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 ;; TAB tab to next tab stop
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;; : outdent preceding label, tab to tab stop
11105
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
37 ;; comment char place or move comment
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
38 ;; asm-comment-char specifies which character this is;
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
39 ;; you can use a different character in different
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
40 ;; Asm mode buffers.
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 ;; C-j, C-m newline and tab to tab stop
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;;
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 ;; Code is indented to the first tab stop level.
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:
11098
03b481b6cec2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 9472
diff changeset
46 ;; 1) An asm-mode-set-comment-hook before the part of the initialization
473
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
20781
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
52 (defgroup asm nil
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
53 "Mode for editing assembler code."
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
54 :group 'languages)
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
55
23312
6f7f0f3876e3 (asm-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 20781
diff changeset
56 (defcustom asm-comment-char ?\;
20781
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
57 "*The comment-start character assumed by Asm mode."
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
58 :type 'character
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
59 :group 'asm)
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 (defvar asm-mode-syntax-table nil
2670
7c9deb765a64 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 869
diff changeset
62 "Syntax table used while in Asm mode.")
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 (defvar asm-mode-abbrev-table nil
2670
7c9deb765a64 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 869
diff changeset
65 "Abbrev table used while in Asm mode.")
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 (define-abbrev-table 'asm-mode-abbrev-table ())
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 (defvar asm-mode-map nil
2670
7c9deb765a64 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 869
diff changeset
69 "Keymap for Asm mode.")
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 (if asm-mode-map
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 nil
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 (setq asm-mode-map (make-sparse-keymap))
11105
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
74 ;; Note that the comment character isn't set up until asm-mode is called.
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 (define-key asm-mode-map ":" 'asm-colon)
15481
a54558280682 (asm-mode-map): Fix typo.
Erik Naggum <erik@naggum.no>
parents: 15477
diff changeset
76 (define-key asm-mode-map "\C-c;" 'comment-region)
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 (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
78 (define-key asm-mode-map "\C-j" 'asm-newline)
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
79 (define-key asm-mode-map "\C-m" 'asm-newline)
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
80 )
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81
9385
297f0781c8ae (asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7384
diff changeset
82 (defconst asm-font-lock-keywords
25481
f26b378dc6a2 (asm-mode): Set comment-start properly from asm-comment-char.
Richard M. Stallman <rms@gnu.org>
parents: 23312
diff changeset
83 '(("^\\(\\(\\sw\\|\\s_\\)+\\)\\>:?[ \t]*\\(\\sw+\\(\\.[lLwWbBsS]\\)?\\)?"
9385
297f0781c8ae (asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7384
diff changeset
84 (1 font-lock-function-name-face) (3 font-lock-keyword-face nil t))
25481
f26b378dc6a2 (asm-mode): Set comment-start properly from asm-comment-char.
Richard M. Stallman <rms@gnu.org>
parents: 23312
diff changeset
85 ("^\\s +\\(\\(\\sw\\|\\s_\\)+\\(\\.[lLwWbBsS]\\)?\\)" 1 font-lock-keyword-face))
9385
297f0781c8ae (asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7384
diff changeset
86 "Additional expressions to highlight in Assembler mode.")
297f0781c8ae (asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7384
diff changeset
87
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 (defvar asm-code-level-empty-comment-pattern nil)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 (defvar asm-flush-left-empty-comment-pattern nil)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 (defvar asm-inline-empty-comment-pattern nil)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 ;;;###autoload
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 (defun asm-mode ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 "Major mode for editing typical assembler code.
2670
7c9deb765a64 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 869
diff changeset
95 Features a private abbrev table and the following bindings:
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 \\[asm-colon]\toutdent a preceding label, tab to next tab stop.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 \\[tab-to-tab-stop]\ttab to next tab stop.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 \\[asm-newline]\tnewline, then tab to next tab stop.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 \\[asm-comment]\tsmart placement of assembler comments.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 The character used for making comments is set by the variable
23312
6f7f0f3876e3 (asm-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 20781
diff changeset
103 `asm-comment-char' (which defaults to `?\\;').
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104
11098
03b481b6cec2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 9472
diff changeset
105 Alternatively, you may set this variable in `asm-mode-set-comment-hook',
03b481b6cec2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 9472
diff changeset
106 which is called near the beginning of mode initialization.
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107
2670
7c9deb765a64 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 869
diff changeset
108 Turning on Asm mode runs the hook `asm-mode-hook' at the end of initialization.
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109
6469
4cf30ff89a5e (asm-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5268
diff changeset
110 Special commands:
4cf30ff89a5e (asm-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5268
diff changeset
111 \\{asm-mode-map}
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 "
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 (interactive)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 (kill-all-local-variables)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 (setq mode-name "Assembler")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (setq major-mode 'asm-mode)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 (setq local-abbrev-table asm-mode-abbrev-table)
9472
06623e3543db * asm-mode.el: (asm-mode): Set font-lock-defaults.
Simon Marshall <simon@gnu.org>
parents: 9385
diff changeset
118 (make-local-variable 'font-lock-defaults)
06623e3543db * asm-mode.el: (asm-mode): Set font-lock-defaults.
Simon Marshall <simon@gnu.org>
parents: 9385
diff changeset
119 (setq font-lock-defaults '(asm-font-lock-keywords))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 (make-local-variable 'asm-mode-syntax-table)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 (setq asm-mode-syntax-table (make-syntax-table))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 (set-syntax-table asm-mode-syntax-table)
11105
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
123
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (run-hooks 'asm-mode-set-comment-hook)
11105
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
125 ;; Make our own local child of asm-mode-map
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
126 ;; so we can define our own comment character.
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
127 (use-local-map (nconc (make-sparse-keymap) asm-mode-map))
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
128 (local-set-key (vector asm-comment-char) 'asm-comment)
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
129
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 (modify-syntax-entry asm-comment-char
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 "<" asm-mode-syntax-table)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 (modify-syntax-entry ?\n
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 ">" asm-mode-syntax-table)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (let ((cs (regexp-quote (char-to-string asm-comment-char))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 (make-local-variable 'comment-start)
25481
f26b378dc6a2 (asm-mode): Set comment-start properly from asm-comment-char.
Richard M. Stallman <rms@gnu.org>
parents: 23312
diff changeset
136 (setq comment-start (concat (char-to-string asm-comment-char) " "))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 (make-local-variable 'comment-start-skip)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 (setq comment-start-skip (concat cs "+[ \t]*"))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 (setq asm-inline-empty-comment-pattern (concat "^.+" cs "+ *$"))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 (setq asm-code-level-empty-comment-pattern (concat "^[\t ]+" cs cs " *$"))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 (setq asm-flush-left-empty-comment-pattern (concat "^" cs cs cs " *$"))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 )
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 (make-local-variable 'comment-end)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 (setq comment-end "")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 (make-local-variable 'comment-column)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 (setq comment-column 32)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 (setq fill-prefix "\t")
11105
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
148 (run-hooks 'asm-mode-hook))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (defun asm-colon ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 "Insert a colon; if it follows a label, delete the label's indentation."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (interactive)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 (save-excursion
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 (beginning-of-line)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 (if (looking-at "[ \t]+\\(\\sw\\|\\s_\\)+$")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 (delete-horizontal-space)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 (insert ":")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 (tab-to-tab-stop)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 )
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 (defun asm-newline ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 "Insert LFD + fill-prefix, to bring us back to code-indent level."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 (interactive)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 (if (eolp) (delete-horizontal-space))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 (insert "\n")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 (tab-to-tab-stop)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 )
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 (defun asm-line-matches (pattern &optional withcomment)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 (save-excursion
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 (beginning-of-line)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 (looking-at pattern)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 (defun asm-pop-comment-level ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 ;; 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
176 ;; on the current line if it was all comment, otherwise above it
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 (end-of-line)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 (delete-horizontal-space)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (while (= (preceding-char) asm-comment-char)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 (delete-backward-char 1))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 (delete-horizontal-space)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 (if (bolp)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 nil
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 (beginning-of-line)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 (open-line 1))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 )
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (defun asm-comment ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 "Convert an empty comment to a `larger' kind, or start a new one.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 These are the known comment classes:
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 1 -- comment to the right of the code (at the comment-column)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 2 -- comment on its own line, indented like code
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 3 -- comment on its own line, beginning at the left-most column.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 Suggested usage: while writing your code, trigger asm-comment
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 repeatedly until you are satisfied with the kind of comment."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 (interactive)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 (cond
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 ;; Blank line? Then start comment at code indent level.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 ((asm-line-matches "^[ \t]*$")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (delete-horizontal-space)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 (tab-to-tab-stop)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 (insert asm-comment-char comment-start))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 ;; Nonblank line with no comment chars in it?
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 ;; Then start a comment at the current comment column
7384
2395bbd3dd6e (asm-comment): Don't match newline.
Karl Heuer <kwzh@gnu.org>
parents: 6469
diff changeset
210 ((asm-line-matches (format "^[^%c\n]+$" asm-comment-char))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 (indent-for-comment))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 ;; Flush-left comment present? Just insert character.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 ((asm-line-matches asm-flush-left-empty-comment-pattern)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (insert asm-comment-char))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 ;; Empty code-level comment already present?
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 ;; Then start flush-left comment, on line above if this one is nonempty.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 ((asm-line-matches asm-code-level-empty-comment-pattern)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (asm-pop-comment-level)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (insert asm-comment-char asm-comment-char comment-start))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 ;; Empty comment ends line?
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 ;; Then make code-level comment, on line above if this one is nonempty.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 ((asm-line-matches asm-inline-empty-comment-pattern)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (asm-pop-comment-level)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 (tab-to-tab-stop)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (insert asm-comment-char comment-start))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 ;; If all else fails, insert character
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 (t
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (insert asm-comment-char))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 )
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 (end-of-line))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236
18383
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 15481
diff changeset
237 (provide 'asm-mode)
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 15481
diff changeset
238
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 ;;; asm-mode.el ends here