1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-09 21:20:45 -08:00

Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs

This commit is contained in:
Michael Albinus 2019-07-18 20:46:39 +02:00
commit 5130a95cd1
2 changed files with 83 additions and 13 deletions

View file

@ -1,4 +1,4 @@
;;; 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.
@ -54,8 +54,7 @@
(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)))
@ -127,10 +126,10 @@ Turning on Asm mode runs the hook `asm-mode-hook' at the end of initialization.
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
@ -140,12 +139,11 @@ Special commands:
(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 ()
@ -172,7 +170,7 @@ Special commands:
;; 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."

View file

@ -0,0 +1,72 @@
;;; 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