aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/progmodes/asm-mode.el24
-rw-r--r--test/lisp/progmodes/asm-mode-tests.el72
2 files changed, 83 insertions, 13 deletions
diff --git a/lisp/progmodes/asm-mode.el b/lisp/progmodes/asm-mode.el
index d6e155997d4..017a5b5bace 100644
--- a/lisp/progmodes/asm-mode.el
+++ b/lisp/progmodes/asm-mode.el
@@ -1,4 +1,4 @@
1;;; asm-mode.el --- mode for editing assembler code 1;;; asm-mode.el --- mode for editing assembler code -*- lexical-binding: t; -*-
2 2
3;; Copyright (C) 1991, 2001-2019 Free Software Foundation, Inc. 3;; Copyright (C) 1991, 2001-2019 Free Software Foundation, Inc.
4 4
@@ -54,8 +54,7 @@
54 54
55(defcustom asm-comment-char ?\; 55(defcustom asm-comment-char ?\;
56 "The `comment-start' character assumed by Asm mode." 56 "The `comment-start' character assumed by Asm mode."
57 :type 'character 57 :type 'character)
58 :group 'asm)
59 58
60(defvar asm-mode-syntax-table 59(defvar asm-mode-syntax-table
61 (let ((st (make-syntax-table))) 60 (let ((st (make-syntax-table)))
@@ -127,10 +126,10 @@ Turning on Asm mode runs the hook `asm-mode-hook' at the end of initialization.
127Special commands: 126Special commands:
128\\{asm-mode-map}" 127\\{asm-mode-map}"
129 (setq local-abbrev-table asm-mode-abbrev-table) 128 (setq local-abbrev-table asm-mode-abbrev-table)
130 (set (make-local-variable 'font-lock-defaults) '(asm-font-lock-keywords)) 129 (setq-local font-lock-defaults '(asm-font-lock-keywords))
131 (set (make-local-variable 'indent-line-function) 'asm-indent-line) 130 (setq-local indent-line-function #'asm-indent-line)
132 ;; Stay closer to the old TAB behavior (was tab-to-tab-stop). 131 ;; Stay closer to the old TAB behavior (was tab-to-tab-stop).
133 (set (make-local-variable 'tab-always-indent) nil) 132 (setq-local tab-always-indent nil)
134 133
135 (run-hooks 'asm-mode-set-comment-hook) 134 (run-hooks 'asm-mode-set-comment-hook)
136 ;; Make our own local child of asm-mode-map 135 ;; Make our own local child of asm-mode-map
@@ -140,12 +139,11 @@ Special commands:
140 (set-syntax-table (make-syntax-table asm-mode-syntax-table)) 139 (set-syntax-table (make-syntax-table asm-mode-syntax-table))
141 (modify-syntax-entry asm-comment-char "< b") 140 (modify-syntax-entry asm-comment-char "< b")
142 141
143 (set (make-local-variable 'comment-start) (string asm-comment-char)) 142 (setq-local comment-start (string asm-comment-char))
144 (set (make-local-variable 'comment-add) 1) 143 (setq-local comment-add 1)
145 (set (make-local-variable 'comment-start-skip) 144 (setq-local comment-start-skip "\\(?:\\s<+\\|/[/*]+\\)[ \t]*")
146 "\\(?:\\s<+\\|/[/*]+\\)[ \t]*") 145 (setq-local comment-end-skip "[ \t]*\\(\\s>\\|\\*+/\\)")
147 (set (make-local-variable 'comment-end-skip) "[ \t]*\\(\\s>\\|\\*+/\\)") 146 (setq-local comment-end "")
148 (set (make-local-variable 'comment-end) "")
149 (setq fill-prefix "\t")) 147 (setq fill-prefix "\t"))
150 148
151(defun asm-indent-line () 149(defun asm-indent-line ()
@@ -172,7 +170,7 @@ Special commands:
172 ;; Simple `;' comments go to the comment-column. 170 ;; Simple `;' comments go to the comment-column.
173 (and (looking-at "\\s<\\(\\S<\\|\\'\\)") comment-column) 171 (and (looking-at "\\s<\\(\\S<\\|\\'\\)") comment-column)
174 ;; The rest goes at the first tab stop. 172 ;; The rest goes at the first tab stop.
175 (or (indent-next-tab-stop 0)))) 173 (indent-next-tab-stop 0)))
176 174
177(defun asm-colon () 175(defun asm-colon ()
178 "Insert a colon; if it follows a label, delete the label's indentation." 176 "Insert a colon; if it follows a label, delete the label's indentation."
diff --git a/test/lisp/progmodes/asm-mode-tests.el b/test/lisp/progmodes/asm-mode-tests.el
new file mode 100644
index 00000000000..a10add0680d
--- /dev/null
+++ b/test/lisp/progmodes/asm-mode-tests.el
@@ -0,0 +1,72 @@
1;;; asm-mode-tests.el --- Tests for asm-mode.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2019 Free Software Foundation, Inc.
4
5;; Author: Simen Heggestøyl <simenheg@gmail.com>
6;; Keywords:
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;;
26
27;;; Code:
28
29(require 'asm-mode)
30(require 'ert)
31
32(defmacro asm-mode-tests--with-temp-buffer (&rest body)
33 "Create a temporary Asm mode buffer and evaluate BODY there."
34 (declare (indent 0))
35 `(with-temp-buffer
36 (let ((asm-comment-char ?\;))
37 (asm-mode)
38 ,@body)))
39
40(ert-deftest asm-mode-tests-colon ()
41 (asm-mode-tests--with-temp-buffer
42 (let ((indent-tabs-mode t))
43 (insert "\t label")
44 (let ((last-command-event ?:))
45 (asm-colon))
46 (should (equal (buffer-string) "label:\t")))))
47
48(ert-deftest asm-mode-tests-colon-inside-comment ()
49 (asm-mode-tests--with-temp-buffer
50 (insert ";comment")
51 (let ((last-command-event ?:))
52 (asm-colon))
53 (should (equal (buffer-string) ";comment:"))))
54
55(ert-deftest asm-mode-tests-comment ()
56 (asm-mode-tests--with-temp-buffer
57 (insert "label:")
58 (goto-char (point-min))
59 ;; First invocation
60 (asm-comment)
61 (should (string-match-p "label:[ \t]+;" (buffer-string)))
62 (should (= (current-column) (+ comment-column 1)))
63 ;; Second invocation
64 (asm-comment)
65 (should (string-match-p "[ \t]+;; \nlabel:" (buffer-string)))
66 (should (= (current-column) (+ tab-width 3)))
67 ;; Third invocation
68 (asm-comment)
69 (should (string-match-p ";;; \nlabel:" (buffer-string)))
70 (should (= (current-column) 4))))
71
72;;; asm-mode-tests.el ends here