-;;; asm-mode.el --- mode for editing assembler code
+;;; asm-mode.el --- mode for editing assembler code -*- lexical-binding: t; -*-
;; Copyright (C) 1991, 2001-2019 Free Software Foundation, Inc.
(defcustom asm-comment-char ?\;
"The `comment-start' character assumed by Asm mode."
- :type 'character
- :group 'asm)
+ :type 'character)
(defvar asm-mode-syntax-table
(let ((st (make-syntax-table)))
Special commands:
\\{asm-mode-map}"
(setq local-abbrev-table asm-mode-abbrev-table)
- (set (make-local-variable 'font-lock-defaults) '(asm-font-lock-keywords))
- (set (make-local-variable 'indent-line-function) 'asm-indent-line)
+ (setq-local font-lock-defaults '(asm-font-lock-keywords))
+ (setq-local indent-line-function #'asm-indent-line)
;; Stay closer to the old TAB behavior (was tab-to-tab-stop).
- (set (make-local-variable 'tab-always-indent) nil)
+ (setq-local tab-always-indent nil)
(run-hooks 'asm-mode-set-comment-hook)
;; Make our own local child of asm-mode-map
(set-syntax-table (make-syntax-table asm-mode-syntax-table))
(modify-syntax-entry asm-comment-char "< b")
- (set (make-local-variable 'comment-start) (string asm-comment-char))
- (set (make-local-variable 'comment-add) 1)
- (set (make-local-variable 'comment-start-skip)
- "\\(?:\\s<+\\|/[/*]+\\)[ \t]*")
- (set (make-local-variable 'comment-end-skip) "[ \t]*\\(\\s>\\|\\*+/\\)")
- (set (make-local-variable 'comment-end) "")
+ (setq-local comment-start (string asm-comment-char))
+ (setq-local comment-add 1)
+ (setq-local comment-start-skip "\\(?:\\s<+\\|/[/*]+\\)[ \t]*")
+ (setq-local comment-end-skip "[ \t]*\\(\\s>\\|\\*+/\\)")
+ (setq-local comment-end "")
(setq fill-prefix "\t"))
(defun asm-indent-line ()
;; Simple `;' comments go to the comment-column.
(and (looking-at "\\s<\\(\\S<\\|\\'\\)") comment-column)
;; The rest goes at the first tab stop.
- (or (indent-next-tab-stop 0))))
+ (indent-next-tab-stop 0)))
(defun asm-colon ()
"Insert a colon; if it follows a label, delete the label's indentation."
--- /dev/null
+;;; asm-mode-tests.el --- Tests for asm-mode.el -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Author: Simen Heggestøyl <simenheg@gmail.com>
+;; Keywords:
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'asm-mode)
+(require 'ert)
+
+(defmacro asm-mode-tests--with-temp-buffer (&rest body)
+ "Create a temporary Asm mode buffer and evaluate BODY there."
+ (declare (indent 0))
+ `(with-temp-buffer
+ (let ((asm-comment-char ?\;))
+ (asm-mode)
+ ,@body)))
+
+(ert-deftest asm-mode-tests-colon ()
+ (asm-mode-tests--with-temp-buffer
+ (let ((indent-tabs-mode t))
+ (insert "\t label")
+ (let ((last-command-event ?:))
+ (asm-colon))
+ (should (equal (buffer-string) "label:\t")))))
+
+(ert-deftest asm-mode-tests-colon-inside-comment ()
+ (asm-mode-tests--with-temp-buffer
+ (insert ";comment")
+ (let ((last-command-event ?:))
+ (asm-colon))
+ (should (equal (buffer-string) ";comment:"))))
+
+(ert-deftest asm-mode-tests-comment ()
+ (asm-mode-tests--with-temp-buffer
+ (insert "label:")
+ (goto-char (point-min))
+ ;; First invocation
+ (asm-comment)
+ (should (string-match-p "label:[ \t]+;" (buffer-string)))
+ (should (= (current-column) (+ comment-column 1)))
+ ;; Second invocation
+ (asm-comment)
+ (should (string-match-p "[ \t]+;; \nlabel:" (buffer-string)))
+ (should (= (current-column) (+ tab-width 3)))
+ ;; Third invocation
+ (asm-comment)
+ (should (string-match-p ";;; \nlabel:" (buffer-string)))
+ (should (= (current-column) 4))))
+
+;;; asm-mode-tests.el ends here