Mercurial > emacs
annotate lisp/progmodes/asm-mode.el @ 102408:2bb42d0dca71
Change from author without assignment is thankfully tiny.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 05 Mar 2009 03:48:25 +0000 |
parents | a9dc0e7c3f2b |
children | 1d1d5d9bd884 |
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 |
100908 | 3 ;; Copyright (C) 1991, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
64699
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 | 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 | 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 | 10 ;; This file is part of GNU Emacs. |
11 | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94206
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
473 | 13 ;; it under the terms of the GNU General Public License as published by |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94206
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94206
diff
changeset
|
15 ;; (at your option) any later version. |
473 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94206
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
473 | 24 |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
25 ;;; Commentary: |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
26 |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
27 ;; This mode was written by Eric S. Raymond <esr@snark.thyrsus.com>, |
473 | 28 ;; inspired by an earlier asm-mode by Martin Neitzel. |
29 | |
30 ;; This minor mode is based on text mode. It defines a private abbrev table | |
31 ;; that can be used to save abbrevs for assembler mnemonics. It binds just | |
32 ;; five keys: | |
33 ;; | |
34 ;; TAB tab to next tab stop | |
35 ;; : 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
|
36 ;; 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
|
37 ;; 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
|
38 ;; 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
|
39 ;; Asm mode buffers. |
473 | 40 ;; C-j, C-m newline and tab to tab stop |
41 ;; | |
42 ;; 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
|
43 |
473 | 44 ;; This mode runs two hooks: |
11098 | 45 ;; 1) An asm-mode-set-comment-hook before the part of the initialization |
473 | 46 ;; depending on asm-comment-char, and |
47 ;; 2) an asm-mode-hook at the end of initialization. | |
48 | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
49 ;;; Code: |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
803
diff
changeset
|
50 |
20781 | 51 (defgroup asm nil |
52 "Mode for editing assembler code." | |
66963
a11fdee52c05
Add :link (custom-group-link font-lock-faces) to defgroup.
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
53 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) |
20781 | 54 :group 'languages) |
55 | |
23312 | 56 (defcustom asm-comment-char ?\; |
20781 | 57 "*The comment-start character assumed by Asm mode." |
58 :type 'character | |
59 :group 'asm) | |
473 | 60 |
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
|
61 (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
|
62 (let ((st (make-syntax-table))) |
70227
3f695578124f
(asm-mode, asm-mode-syntax-table): Add
Masatake YAMATO <jet@gyve.org>
parents:
68773
diff
changeset
|
63 (modify-syntax-entry ?\n "> b" st) |
3f695578124f
(asm-mode, asm-mode-syntax-table): Add
Masatake YAMATO <jet@gyve.org>
parents:
68773
diff
changeset
|
64 (modify-syntax-entry ?/ ". 124b" st) |
3f695578124f
(asm-mode, asm-mode-syntax-table): Add
Masatake YAMATO <jet@gyve.org>
parents:
68773
diff
changeset
|
65 (modify-syntax-entry ?* ". 23" st) |
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
|
66 st) |
2670 | 67 "Syntax table used while in Asm mode.") |
473 | 68 |
69 (defvar asm-mode-abbrev-table nil | |
2670 | 70 "Abbrev table used while in Asm mode.") |
473 | 71 (define-abbrev-table 'asm-mode-abbrev-table ()) |
72 | |
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
|
73 (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
|
74 (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
|
75 ;; 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
|
76 (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
|
77 (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
|
78 (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
|
79 (define-key map "\C-m" 'newline-and-indent) |
79625
63628cd913b8
(asm-mode-map): Add a major mode menu.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78234
diff
changeset
|
80 (define-key map [menu-bar] (make-sparse-keymap)) |
63628cd913b8
(asm-mode-map): Add a major mode menu.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78234
diff
changeset
|
81 (define-key map [menu-bar asm-mode] (cons "Asm" map)) |
94206
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
93975
diff
changeset
|
82 (define-key map [comment-region] |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
93975
diff
changeset
|
83 '(menu-item "Comment Region" comment-region |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
93975
diff
changeset
|
84 :help "Comment or uncomment each line in the region")) |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
93975
diff
changeset
|
85 (define-key map [newline-and-indent] |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
93975
diff
changeset
|
86 '(menu-item "Insert Newline and Indent" newline-and-indent |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
93975
diff
changeset
|
87 :help "Insert a newline, then indent according to major mode")) |
79625
63628cd913b8
(asm-mode-map): Add a major mode menu.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78234
diff
changeset
|
88 (define-key map [asm-colon] |
94206
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
93975
diff
changeset
|
89 '(menu-item "Insert Colon" asm-colon |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
93975
diff
changeset
|
90 :help "Insert a colon; if it follows a label, delete the label's indentation")) |
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
|
91 map) |
2670 | 92 "Keymap for Asm mode.") |
473 | 93 |
9385
297f0781c8ae
(asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7384
diff
changeset
|
94 (defconst asm-font-lock-keywords |
68134
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
95 (append |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
96 '(("^\\(\\(\\sw\\|\\s_\\)+\\)\\>:?[ \t]*\\(\\sw+\\(\\.\\sw+\\)*\\)?" |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
97 (1 font-lock-function-name-face) (3 font-lock-keyword-face nil t)) |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
98 ;; label started from ".". |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
99 ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>:" |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
100 1 font-lock-function-name-face) |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
101 ("^\\((\\sw+)\\)?\\s +\\(\\(\\.?\\sw\\|\\s_\\)+\\(\\.\\sw+\\)*\\)" |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
102 2 font-lock-keyword-face) |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
103 ;; directive started from ".". |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
104 ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>[^:]?" |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
105 1 font-lock-keyword-face) |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
106 ;; %register |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
107 ("%\\sw+" . font-lock-variable-name-face)) |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
108 cpp-font-lock-keywords) |
48bf79d0aede
2006-01-06 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
66963
diff
changeset
|
109 "Additional expressions to highlight in Assembler mode.") |
9385
297f0781c8ae
(asm-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7384
diff
changeset
|
110 |
473 | 111 ;;;###autoload |
112 (defun asm-mode () | |
113 "Major mode for editing typical assembler code. | |
2670 | 114 Features a private abbrev table and the following bindings: |
473 | 115 |
116 \\[asm-colon]\toutdent a preceding label, tab to next tab stop. | |
117 \\[tab-to-tab-stop]\ttab to next tab stop. | |
118 \\[asm-newline]\tnewline, then tab to next tab stop. | |
119 \\[asm-comment]\tsmart placement of assembler comments. | |
120 | |
121 The character used for making comments is set by the variable | |
23312 | 122 `asm-comment-char' (which defaults to `?\\;'). |
473 | 123 |
11098 | 124 Alternatively, you may set this variable in `asm-mode-set-comment-hook', |
125 which is called near the beginning of mode initialization. | |
473 | 126 |
2670 | 127 Turning on Asm mode runs the hook `asm-mode-hook' at the end of initialization. |
473 | 128 |
6469 | 129 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
|
130 \\{asm-mode-map}" |
473 | 131 (interactive) |
132 (kill-all-local-variables) | |
133 (setq mode-name "Assembler") | |
134 (setq major-mode 'asm-mode) | |
135 (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
|
136 (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
|
137 (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
|
138 (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
|
139 ;; 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
|
140 (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
|
141 |
473 | 142 (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
|
143 ;; 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
|
144 ;; 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
|
145 (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
|
146 (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
|
147 (set-syntax-table (make-syntax-table asm-mode-syntax-table)) |
70227
3f695578124f
(asm-mode, asm-mode-syntax-table): Add
Masatake YAMATO <jet@gyve.org>
parents:
68773
diff
changeset
|
148 (modify-syntax-entry asm-comment-char "< b") |
49402
99a31f21f1c9
(asm-mode): Added syntax table entries for /* */ comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
31983
diff
changeset
|
149 |
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
|
150 (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
|
151 (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
|
152 (make-local-variable 'comment-add) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
153 (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
|
154 (make-local-variable 'comment-start-skip) |
70227
3f695578124f
(asm-mode, asm-mode-syntax-table): Add
Masatake YAMATO <jet@gyve.org>
parents:
68773
diff
changeset
|
155 (setq comment-start-skip "\\(?:\\s<+\\|/[/*]+\\)[ \t]*") |
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
|
156 (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
|
157 (setq comment-end-skip "[ \t]*\\(\\s>\\|\\*+/\\)") |
473 | 158 (make-local-variable 'comment-end) |
159 (setq comment-end "") | |
160 (setq fill-prefix "\t") | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
161 (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
|
162 |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
163 (defun asm-indent-line () |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
164 "Auto-indent the current line." |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
165 (interactive) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
166 (let* ((savep (point)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
167 (indent (condition-case nil |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
168 (save-excursion |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
169 (forward-line 0) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
170 (skip-chars-forward " \t") |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
171 (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
|
172 (max (asm-calculate-indentation) 0)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
173 (error 0)))) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
174 (if savep |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
175 (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
|
176 (indent-line-to indent)))) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
177 |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
178 (defun asm-calculate-indentation () |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
179 (or |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
180 ;; 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
|
181 (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
|
182 ;; Same thing for `;;;' comments. |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
183 (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
|
184 ;; 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
|
185 (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
|
186 ;; 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
|
187 (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
|
188 |
473 | 189 (defun asm-colon () |
190 "Insert a colon; if it follows a label, delete the label's indentation." | |
191 (interactive) | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
192 (let ((labelp nil)) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
193 (save-excursion |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
194 (skip-syntax-backward "w_") |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
195 (skip-syntax-backward " ") |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
196 (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
|
197 (call-interactively 'self-insert-command) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
198 (when labelp |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
199 (delete-horizontal-space) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
200 (tab-to-tab-stop)))) |
473 | 201 |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
57662
diff
changeset
|
202 ;; 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
|
203 (defalias 'asm-newline 'newline-and-indent) |
473 | 204 |
205 (defun asm-comment () | |
206 "Convert an empty comment to a `larger' kind, or start a new one. | |
207 These are the known comment classes: | |
208 | |
209 1 -- comment to the right of the code (at the comment-column) | |
210 2 -- comment on its own line, indented like code | |
211 3 -- comment on its own line, beginning at the left-most column. | |
212 | |
213 Suggested usage: while writing your code, trigger asm-comment | |
214 repeatedly until you are satisfied with the kind of comment." | |
215 (interactive) | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
216 (comment-normalize-vars) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
217 (let (comempty comment) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
218 (save-excursion |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
219 (beginning-of-line) |
64394
f0ee06ae643c
(asm-comment): Use with-no-warnings.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
220 (with-no-warnings |
f0ee06ae643c
(asm-comment): Use with-no-warnings.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
221 (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
|
222 (setq comempty (looking-at "[ \t]*$"))) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
223 |
473 | 224 (cond |
225 | |
226 ;; 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
|
227 ;; Just like `comment-dwim'. -stef |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
228 ((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
|
229 (indent-according-to-mode) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
230 (insert asm-comment-char asm-comment-char ?\ )) |
473 | 231 |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
232 ;; 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
|
233 ;; 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
|
234 ((or (null comment) (< (point) comment)) |
473 | 235 (indent-for-comment)) |
236 | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
237 ;; 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
|
238 ((or (not comempty) (save-excursion (goto-char comment) (bolp))) |
473 | 239 (insert asm-comment-char)) |
240 | |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
241 ;; 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
|
242 ((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
|
243 (goto-char comment) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
244 (insert asm-comment-char) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
245 (indent-for-comment)) |
473 | 246 |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
247 ;; Empty comment ends non-empty code line => new comment above. |
473 | 248 (t |
50401
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
249 (goto-char comment) |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
250 (skip-chars-backward " \t") |
465c72f54419
(asm-calculate-indentation, asm-indent-line): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50397
diff
changeset
|
251 (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
|
252 (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
|
253 (asm-comment))))) |
473 | 254 |
18383 | 255 (provide 'asm-mode) |
256 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79717
diff
changeset
|
257 ;; arch-tag: 210e695f-f338-4376-8913-a4c5c72ac848 |
473 | 258 ;;; asm-mode.el ends here |