diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 106f067..bdf074a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,53 +5,57 @@ on: push jobs: test: strategy: + fail-fast: false matrix: - os: [ubuntu-latest] - emacs_version: - - '24.3' - - '25.1' - - '25.3' - - '26.1' - - '26.2' + os: [ubuntu-latest, macos-latest, windows-latest] + emacs-version: - '26.3' - - '27.1' + - '27.2' + - '28.2' + - '29.4' + - '30.2' + experimental: [false] include: - # - emacs_version: 'snapshot' - # os: ubuntu-latest - # allow_failure: true - # - os: macos-latest - # emacs_version: '24.3' + - os: ubuntu-latest + emacs-version: snapshot + experimental: true + - os: macos-latest + emacs-version: snapshot + experimental: true + - os: windows-latest + emacs-version: snapshot + experimental: true + exclude: - os: macos-latest - emacs_version: '25.1' + emacs-version: 26.3 - os: macos-latest - emacs_version: '27.1' + emacs-version: 27.2 runs-on: ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v6 - name: Set up Emacs - uses: purcell/setup-emacs@master + uses: jcs090218/setup-emacs@master with: - version: ${{ matrix.emacs_version }} - - - name: Set up Cask - uses: conao3/setup-cask@master - - - name: Install Lua (Ubuntu) - if: matrix.os != 'macos-latest' - run: sudo apt install lua5.2 && echo 'print(123)' | lua -i - - - name: Install Lua (MacOS) - if: matrix.os == 'macos-latest' - uses: xpol/setup-lua@master + version: ${{ matrix.emacs-version }} + + - name: Set up Eask + uses: emacs-eask/setup-eask@master + with: + version: 'snapshot' + + - uses: ilammy/msvc-dev-cmd@v1 + + - name: Install Lua + uses: leafo/gh-actions-lua@v12 with: - lua-version: "5.2.4" + luaVersion: "5.2.4" - name: Run tests if: matrix.allow_failure != true - run: 'cask && make test' + run: 'make test' - name: Run tests (allow failure) if: matrix.allow_failure == true - run: 'cask && make test || true' + run: 'make test || true' diff --git a/.gitignore b/.gitignore index 566d49f..19adcf8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ release-notes-* *~ *.elc -/.cask +/.eask +/dist diff --git a/Eask b/Eask new file mode 100644 index 0000000..1a65e5a --- /dev/null +++ b/Eask @@ -0,0 +1,23 @@ +;; -*- mode: eask; lexical-binding: t -*- + +(package "lua-mode" + "20221027" + "a major-mode for editing Lua scripts") + +(website-url "https://immerrr.github.io/lua-mode") +(keywords "languages" "processes" "tools") + +(package-file "lua-mode.el") +(files "lua-mode-*.el") + +(script "test" "echo \"Error: no test specified\" && exit 1") + +(source 'gnu) +(source 'melpa) + +(depends-on "emacs" "26.1") + +(development + (depends-on "buttercup")) + +(setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432 diff --git a/Makefile b/Makefile index c6af0ff..820baf3 100644 --- a/Makefile +++ b/Makefile @@ -19,34 +19,38 @@ default: %.elc: %.el $(EMACS_BATCH) -f batch-byte-compile $< -compile: $(LUA_MODE_ELC) +compile: + eask compile dist: - rm -f $(DISTFILE) && \ - git archive --format=zip -o $(DISTFILE) --prefix=lua-mode/ HEAD + eask package -.PHONY: test-compiled-nocask test-uncompiled-nocask test-compiled test-uncompiled +.PHONY: test-compiled-noeask test-uncompiled-noeask test-compiled test-uncompiled # check both regular and compiled versions -test-nocask: test-compiled-nocask test-uncompiled-nocask +test-noeask: test-compiled-noeask test-uncompiled-noeask test: test-compiled test-uncompiled -test-compiled-nocask: $(LUA_MODE_ELC) +test-compiled-noeask: $(LUA_MODE_ELC) $(EMACS) -batch -l $(LUA_MODE_ELC) -l buttercup -f buttercup-run-discover -test-uncompiled-nocask: +test-uncompiled-noeask: $(EMACS) -batch -l lua-mode.el -l buttercup -f buttercup-run-discover -test-compiled: $(LUA_MODE_ELC) - EMACS=$(EMACS) cask exec buttercup -l $(LUA_MODE_ELC) +test-compiled: + eask install-deps --dev + eask compile + eask test buttercup test-uncompiled: - EMACS=$(EMACS) cask exec buttercup -l lua-mode.el + eask install-deps --dev + eask clean elc + eask test buttercup tryout: - cask exec $(EMACS) -Q -l init-tryout.el test.lua + eask exec $(EMACS) -Q -l init-tryout.el test.lua -tryout-nocask: +tryout-noeask: $(EMACS) -Q -l init-tryout.el test.lua release: diff --git a/lua-mode.el b/lua-mode.el index be56111..2e1dda5 100644 --- a/lua-mode.el +++ b/lua-mode.el @@ -13,7 +13,7 @@ ;; ;; URL: https://immerrr.github.io/lua-mode ;; Version: 20221027 -;; Package-Requires: ((emacs "24.3")) +;; Package-Requires: ((emacs "26.1")) ;; ;; This file is NOT part of Emacs. ;; diff --git a/test/test-indentation.el b/test/test-indentation.el index fff9bdd..22abeba 100644 --- a/test/test-indentation.el +++ b/test/test-indentation.el @@ -1,8 +1,8 @@ ;; -*- flycheck-disabled-checkers: (emacs-lisp-checkdoc) ; lexical-binding:t -*- ;; -*- lexical-binding: t -*- (load (concat (file-name-directory (or load-file-name (buffer-file-name) - default-directory)) - "utils.el") nil 'nomessage 'nosuffix) + default-directory)) + "utils.el") nil 'nomessage 'nosuffix) (require 'buttercup) (require 'cl-lib) @@ -10,69 +10,73 @@ (defun lua--get-indentation-test-sections (file-path) (with-temp-buffer - (insert-file-contents-literally file-path) - (hack-local-variables) - (let (results - section-name - (begin (point-min)) - end - cur-str - (next-section-name "start")) - (goto-char (point-min)) - (while next-section-name - ;; Scan towards the next comment or end of file, save the comment as - ;; the name for the section that comes AFTER the current one. - (setq next-section-name - (when (re-search-forward "^--\\(.*\\)" nil 'noerror) (lua--string-trim (match-string-no-properties 1)))) - ;; Record current section bounds and contents - (setq end (if next-section-name (match-beginning 0) (point-max))) - (setq cur-str (lua--string-trim (buffer-substring-no-properties begin end))) - ;; Save current section to be returned - (if (> (length cur-str) 0) - (push (list (or section-name (format "section %d" (1+ (length results)))) - cur-str - file-local-variables-alist) - results)) - ;; Transition to the next iteration of the loop. - (setq section-name next-section-name) - (setq begin (point))) - (nreverse results)))) + (insert-file-contents-literally file-path) + ;; XXX: Avoid error `Local variables entry is missing the suffix' + ;; on Windows with Emacs version lower than 29. + (if (fboundp #'eask-ignore-errors) + (eask-ignore-errors (hack-local-variables)) + (hack-local-variables)) + (let (results + section-name + (begin (point-min)) + end + cur-str + (next-section-name "start")) + (goto-char (point-min)) + (while next-section-name + ;; Scan towards the next comment or end of file, save the comment as + ;; the name for the section that comes AFTER the current one. + (setq next-section-name + (when (re-search-forward "^--\\(.*\\)" nil 'noerror) (lua--string-trim (match-string-no-properties 1)))) + ;; Record current section bounds and contents + (setq end (if next-section-name (match-beginning 0) (point-max))) + (setq cur-str (lua--string-trim (buffer-substring-no-properties begin end))) + ;; Save current section to be returned + (if (> (length cur-str) 0) + (push (list (or section-name (format "section %d" (1+ (length results)))) + cur-str + file-local-variables-alist) + results)) + ;; Transition to the next iteration of the loop. + (setq section-name next-section-name) + (setq begin (point))) + (nreverse results)))) (defun lua--indentation-test-make-it-or-xit-clause (x) (let ((it-or-xit (if (string-match "XFAIL" (car x)) 'xit 'it))) - (eval `(,it-or-xit ,(format "%s" (car x)) - (let ((lua-code ,(cadr x)) - ,@(mapcar (lambda (alist-cons) - (list (car alist-cons) (cdr alist-cons))) - ;; cl-caddr here is to support Emacs<26 that don't have caddr. - (cl-caddr x))) - (expect lua-code :to-be-reindented-the-same-way)))))) + (eval `(,it-or-xit ,(format "%s" (car x)) + (let ((lua-code ,(cadr x)) + ,@(mapcar (lambda (alist-cons) + (list (car alist-cons) (cdr alist-cons))) + ;; cl-caddr here is to support Emacs<26 that don't have caddr. + (cl-caddr x))) + (expect lua-code :to-be-reindented-the-same-way)))))) (let* ((current-path (or load-file-name (buffer-file-name) default-directory)) - (indentation-tests-dir (concat (file-name-directory current-path) "indentation-tests")) - (indentation-tests (directory-files indentation-tests-dir nil ".*\.lua$" 'nosort))) + (indentation-tests-dir (concat (file-name-directory current-path) "indentation-tests")) + (indentation-tests (directory-files indentation-tests-dir nil ".*\.lua$" 'nosort))) (mapcar (lambda (test-file) - (let ((file-path (expand-file-name test-file indentation-tests-dir))) - (describe (format "Indentation test `%s'" test-file) - (mapcar #'lua--indentation-test-make-it-or-xit-clause - (lua--get-indentation-test-sections file-path))))) - indentation-tests)) + (let ((file-path (expand-file-name test-file indentation-tests-dir))) + (describe (format "Indentation test `%s'" test-file) + (mapcar #'lua--indentation-test-make-it-or-xit-clause + (lua--get-indentation-test-sections file-path))))) + indentation-tests)) (describe "Continuation lines" (lua--parametrize-tests (binop) (("+") ("-") ("*") ("/") ("^") ("%") ("..") - ("<") ("<=") (">") (">=") ("==") ("~=") ("and") ("or")) + ("<") ("<=") (">") (">=") ("==") ("~=") ("and") ("or")) :it (format "are indented before/after binary operators: %s" binop) (expect (replace-regexp-in-string "BINOP" binop "\ a = foo BINOP bar" 'fixedcase) - :to-be-reindented-the-same-way) + :to-be-reindented-the-same-way) (expect (replace-regexp-in-string "BINOP" binop "\ a = foo BINOP bar" 'fixedcase) - :to-be-reindented-the-same-way)) + :to-be-reindented-the-same-way)) ) ;; ( @@ -110,112 +114,112 @@ a = foo (describe "Function indentation" (it "indents function call arguments" - (expect "\ + (expect "\ foobar( a, b, c)" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ foobar( a, b, c)" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ foobar( a, b, c )" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ foobar(a, - b, - c)" :to-be-reindented-the-same-way) + b, + c)" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ foobar{ a, b, c }" :to-be-reindented-the-same-way)) (it "indent blocks with lua-indent-nested-block-content-align" - (let ((lua-indent-nested-block-content-align nil)) - (expect "\ + (let ((lua-indent-nested-block-content-align nil)) + (expect "\ call_some_fn( something, { - val = 5, - another = 6, + val = 5, + another = 6, } )" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ local def = { some_very_long_name = { fn = - function() - return true - end + function() + return true + end } }" :to-be-reindented-the-same-way) - )) + )) (it "indent blocks with lua-indent-close-paren-align" - (let ((lua-indent-close-paren-align nil)) - (expect "\ + (let ((lua-indent-close-paren-align nil)) + (expect "\ local foo = setmetatable( { - a = 4, - b = 5, + a = 4, + b = 5, }, { - __index = some_func, + __index = some_func, } )" :to-be-reindented-the-same-way) - )) + )) (it "indents nested tables with alternative block indenting" - (let ((lua-indent-nested-block-content-align nil) + (let ((lua-indent-nested-block-content-align nil) (lua-indent-close-paren-align nil)) - (expect "\ + (expect "\ foobar({ - a, b, c + a, b, c })" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ foobar(a, { - b, - c + b, + c })" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ foobar( a, { - b, - c + b, + c })" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ foobar( a, { - b, - c + b, + c } )" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ foobar(a, { - b, - c + b, + c })" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ foobar(a, { - b, - c + b, + c } )" :to-be-reindented-the-same-way) - (expect "\ + (expect "\ foobar( { - a, - b + a, + b }, c, d )" :to-be-reindented-the-same-way) - ))) + ))) (ert-deftest lua-indentation-keywords-with-special-characters ()