annotate lisp/progmodes/asm-mode.el @ 83384:08b4dd6a6e87

Merged from miles@gnu.org--gnu-2005 (patch 578-592) Patches applied: * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-578 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-579 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-580 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-581 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-582 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-583 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-584 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-585 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-586 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-587 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-588 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-589 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-590 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-591 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-592 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-424
author Karoly Lorentey <lorentey@elte.hu>
date Wed, 12 Oct 2005 16:14:04 +0000
parents 629afbe74e61
children a11fdee52c05 edf295560b5a
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
64699
629afbe74e61 Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents: 64394
diff changeset
3 ;; Copyright (C) 1991, 2001, 2002, 2003, 2004, 2005
629afbe74e61 Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents: 64394
diff changeset
4 ;; Free Software Foundation, Inc.
869
7861f8756850 entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 810
diff changeset
5
810
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
6 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
11098
03b481b6cec2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 9472
diff changeset
7 ;; Maintainer: FSF
810
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
8 ;; Keywords: tools, languages
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
9
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; 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
14 ;; the Free Software Foundation; either version 2, or (at your option)
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; any later version.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;; 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
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 59996
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 59996
diff changeset
25 ;; Boston, MA 02110-1301, USA.
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26
810
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
27 ;;; Commentary:
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
28
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
29 ;; This mode was written by Eric S. Raymond <esr@snark.thyrsus.com>,
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 ;; inspired by an earlier asm-mode by Martin Neitzel.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 ;; This minor mode is based on text mode. It defines a private abbrev table
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ;; that can be used to save abbrevs for assembler mnemonics. It binds just
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;; five keys:
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 ;;
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;; TAB tab to next tab stop
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 ;; : outdent preceding label, tab to tab stop
11105
8963d6de6f07 (asm-mode): Make a per-buffer child keymap here.
Richard M. Stallman <rms@gnu.org>
parents: 11098
diff changeset
38 ;; 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
39 ;; 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
40 ;; 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
41 ;; Asm mode buffers.
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;; C-j, C-m newline and tab to tab stop
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 ;;
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 ;; 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
45
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;; This mode runs two hooks:
11098
03b481b6cec2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 9472
diff changeset
47 ;; 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
48 ;; depending on asm-comment-char, and
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 ;; 2) an asm-mode-hook at the end of initialization.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50
810
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
51 ;;; Code:
80303373daae *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 803
diff changeset
52
20781
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
53 (defgroup asm nil
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
54 "Mode for editing assembler code."
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
55 :group 'languages)
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
56
23312
6f7f0f3876e3 (asm-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 20781
diff changeset
57 (defcustom asm-comment-char ?\;
20781
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
58 "*The comment-start character assumed by Asm mode."
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
59 :type 'character
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 18383
diff changeset
60 :group 'asm)
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61
50397
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
62 (defvar asm-mode-syntax-table
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
63 (let ((st (make-syntax-table)))
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
64 (modify-syntax-entry ?\n ">" st)
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
65 (modify-syntax-entry ?/ ". 14b" st)
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
66 (modify-syntax-entry ?* ". 23b" st)
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
67 st)
2670
7c9deb765a64 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 869
diff changeset
68 "Syntax table used while in Asm mode.")
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 (defvar asm-mode-abbrev-table nil
2670
7c9deb765a64 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 869
diff changeset
71 "Abbrev table used while in Asm mode.")
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 (define-abbrev-table 'asm-mode-abbrev-table ())
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
50397
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
74 (defvar asm-mode-map
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
75 (let ((map (make-sparse-keymap)))
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
76 ;; Note that the comment character isn't set up until asm-mode is called.
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
77 (define-key map ":" 'asm-colon)
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
78 (define-key map "\C-c;" 'comment-region)
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
79 (define-key map "\C-j" 'newline-and-indent)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
80 (define-key map "\C-m" 'newline-and-indent)
50397
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
81 map)
2670
7c9deb765a64 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 869
diff changeset
82 "Keymap for Asm mode.")
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83
9385
297f0781c8ae (asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7384
diff changeset
84 (defconst asm-font-lock-keywords
49570
288cda7c05fb (asm-font-lock-keywords): Allow arbitrary
Andreas Schwab <schwab@suse.de>
parents: 49402
diff changeset
85 '(("^\\(\\(\\sw\\|\\s_\\)+\\)\\>:?[ \t]*\\(\\sw+\\(\\.\\sw+\\)*\\)?"
9385
297f0781c8ae (asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7384
diff changeset
86 (1 font-lock-function-name-face) (3 font-lock-keyword-face nil t))
51655
abc46b69deaa * progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents: 50401
diff changeset
87 ;; label started from ".".
abc46b69deaa * progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents: 50401
diff changeset
88 ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>:"
abc46b69deaa * progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents: 50401
diff changeset
89 1 font-lock-function-name-face)
abc46b69deaa * progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents: 50401
diff changeset
90 ("^\\((\\sw+)\\)?\\s +\\(\\(\\.?\\sw\\|\\s_\\)+\\(\\.\\sw+\\)*\\)"
abc46b69deaa * progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents: 50401
diff changeset
91 2 font-lock-keyword-face)
abc46b69deaa * progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents: 50401
diff changeset
92 ;; directive started from ".".
abc46b69deaa * progmodes/asm-mode.el (asm-font-lock-keywords): Support
Masatake YAMATO <jet@gyve.org>
parents: 50401
diff changeset
93 ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>[^:]?"
57662
7e610a0ca662 (asm-font-lock-keywords): Use font-lock-variable-name-face for registers.
Nick Roberts <nickrob@snap.net.nz>
parents: 52401
diff changeset
94 1 font-lock-keyword-face)
7e610a0ca662 (asm-font-lock-keywords): Use font-lock-variable-name-face for registers.
Nick Roberts <nickrob@snap.net.nz>
parents: 52401
diff changeset
95 ;; %register
7e610a0ca662 (asm-font-lock-keywords): Use font-lock-variable-name-face for registers.
Nick Roberts <nickrob@snap.net.nz>
parents: 52401
diff changeset
96 ("%\\sw+" . font-lock-variable-name-face))
9385
297f0781c8ae (asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7384
diff changeset
97 "Additional expressions to highlight in Assembler mode.")
297f0781c8ae (asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7384
diff changeset
98
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 ;;;###autoload
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 (defun asm-mode ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 "Major mode for editing typical assembler code.
2670
7c9deb765a64 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 869
diff changeset
102 Features a private abbrev table and the following bindings:
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 \\[asm-colon]\toutdent a preceding label, tab to next tab stop.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 \\[tab-to-tab-stop]\ttab to next tab stop.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 \\[asm-newline]\tnewline, then tab to next tab stop.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 \\[asm-comment]\tsmart placement of assembler comments.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 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
110 `asm-comment-char' (which defaults to `?\\;').
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111
11098
03b481b6cec2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 9472
diff changeset
112 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
113 which is called near the beginning of mode initialization.
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114
2670
7c9deb765a64 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 869
diff changeset
115 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
116
6469
4cf30ff89a5e (asm-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5268
diff changeset
117 Special commands:
50397
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
118 \\{asm-mode-map}"
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 (interactive)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 (kill-all-local-variables)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 (setq mode-name "Assembler")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 (setq major-mode 'asm-mode)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 (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
124 (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
125 (setq font-lock-defaults '(asm-font-lock-keywords))
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
126 (set (make-local-variable 'indent-line-function) 'asm-indent-line)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
127 ;; Stay closer to the old TAB behavior (was tab-to-tab-stop).
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
128 (set (make-local-variable 'tab-always-indent) nil)
11105
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 (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
131 ;; 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
132 ;; 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
133 (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
134 (local-set-key (vector asm-comment-char) 'asm-comment)
50397
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
135 (set-syntax-table (make-syntax-table asm-mode-syntax-table))
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
136 (modify-syntax-entry asm-comment-char "<")
49402
99a31f21f1c9 (asm-mode): Added syntax table entries for /* */ comments.
Juanma Barranquero <lekktu@gmail.com>
parents: 31983
diff changeset
137
50397
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
138 (make-local-variable 'comment-start)
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
139 (setq comment-start (string asm-comment-char))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
140 (make-local-variable 'comment-add)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
141 (setq comment-add 1)
50397
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
142 (make-local-variable 'comment-start-skip)
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
143 (setq comment-start-skip "\\(?:\\s<+\\|/\\*+\\)[ \t]*")
a3e1934e4ead (asm-mode-syntax-table): Setup entries that do not depend on asm-comment-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50352
diff changeset
144 (make-local-variable 'comment-end-skip)
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
145 (setq comment-end-skip "[ \t]*\\(\\s>\\|\\*+/\\)")
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 (make-local-variable 'comment-end)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 (setq comment-end "")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 (setq fill-prefix "\t")
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
149 (run-mode-hooks 'asm-mode-hook))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
150
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
151 (defun asm-indent-line ()
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
152 "Auto-indent the current line."
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
153 (interactive)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
154 (let* ((savep (point))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
155 (indent (condition-case nil
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
156 (save-excursion
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
157 (forward-line 0)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
158 (skip-chars-forward " \t")
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
159 (if (>= (point) savep) (setq savep nil))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
160 (max (asm-calculate-indentation) 0))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
161 (error 0))))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
162 (if savep
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
163 (save-excursion (indent-line-to indent))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
164 (indent-line-to indent))))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
165
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
166 (defun asm-calculate-indentation ()
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
167 (or
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
168 ;; Flush labels to the left margin.
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
169 (and (looking-at "\\(\\sw\\|\\s_\\)+:") 0)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
170 ;; Same thing for `;;;' comments.
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
171 (and (looking-at "\\s<\\s<\\s<") 0)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
172 ;; Simple `;' comments go to the comment-column.
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
173 (and (looking-at "\\s<\\(\\S<\\|\\'\\)") comment-column)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
174 ;; The rest goes at the first tab stop.
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
175 (or (car tab-stop-list) tab-width)))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
176
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 (defun asm-colon ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 "Insert a colon; if it follows a label, delete the label's indentation."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (interactive)
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
180 (let ((labelp nil))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
181 (save-excursion
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
182 (skip-syntax-backward "w_")
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
183 (skip-syntax-backward " ")
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
184 (if (setq labelp (bolp)) (delete-horizontal-space)))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
185 (call-interactively 'self-insert-command)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
186 (when labelp
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
187 (delete-horizontal-space)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
188 (tab-to-tab-stop))))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57662
diff changeset
190 ;; Obsolete since Emacs-22.1.
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
191 (defalias 'asm-newline 'newline-and-indent)
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 (defun asm-comment ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 "Convert an empty comment to a `larger' kind, or start a new one.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 These are the known comment classes:
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 1 -- comment to the right of the code (at the comment-column)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 2 -- comment on its own line, indented like code
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 3 -- comment on its own line, beginning at the left-most column.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 Suggested usage: while writing your code, trigger asm-comment
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 repeatedly until you are satisfied with the kind of comment."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 (interactive)
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
204 (comment-normalize-vars)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
205 (let (comempty comment)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
206 (save-excursion
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
207 (beginning-of-line)
64394
f0ee06ae643c (asm-comment): Use with-no-warnings.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
208 (with-no-warnings
f0ee06ae643c (asm-comment): Use with-no-warnings.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
209 (setq comment (comment-search-forward (line-end-position) t)))
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
210 (setq comempty (looking-at "[ \t]*$")))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
211
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 (cond
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 ;; Blank line? Then start comment at code indent level.
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
215 ;; Just like `comment-dwim'. -stef
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
216 ((save-excursion (beginning-of-line) (looking-at "^[ \t]*$"))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
217 (indent-according-to-mode)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
218 (insert asm-comment-char asm-comment-char ?\ ))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
220 ;; Nonblank line w/o comment => start a comment at comment-column.
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
221 ;; Also: point before the comment => jump inside.
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
222 ((or (null comment) (< (point) comment))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (indent-for-comment))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
225 ;; Flush-left or non-empty comment present => just insert character.
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
226 ((or (not comempty) (save-excursion (goto-char comment) (bolp)))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 (insert asm-comment-char))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
229 ;; Empty code-level comment => upgrade to next comment level.
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
230 ((save-excursion (goto-char comment) (skip-chars-backward " \t") (bolp))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
231 (goto-char comment)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
232 (insert asm-comment-char)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
233 (indent-for-comment))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
235 ;; Empty comment ends non-empty code line => new comment above.
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 (t
50401
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
237 (goto-char comment)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
238 (skip-chars-backward " \t")
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
239 (delete-region (point) (line-end-position))
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
240 (beginning-of-line) (insert "\n") (backward-char)
465c72f54419 (asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50397
diff changeset
241 (asm-comment)))))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242
18383
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 15481
diff changeset
243 (provide 'asm-mode)
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 15481
diff changeset
244
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51655
diff changeset
245 ;;; arch-tag: 210e695f-f338-4376-8913-a4c5c72ac848
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 ;;; asm-mode.el ends here