From 2dbfab8cf5e5390bae53b340cbf487369a017832 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 5 Jul 2022 00:09:18 +0300 Subject: [PATCH 01/10] Replace mapconcat with regexp-opt --- mint-mode.el | 89 +++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/mint-mode.el b/mint-mode.el index 94a144a..4d3dd76 100644 --- a/mint-mode.el +++ b/mint-mode.el @@ -104,74 +104,79 @@ ;; For compound type constructors like `Maybe(Number)` (regex-compound-type-constructors - (mapconcat (lambda (type) - (concat (regexp-quote type) "[[:space:]]*" "(")) - - mint-lang-compound-types - "\\|") ) - + (regexp-opt + (mapcar (lambda (type) + (concat (regexp-quote type) "[[:space:]]*" "(")) + mint-lang-compound-types))) ;; For compound type classes like `Maybe.just` (regex-compound-type-classes - (mapconcat (lambda (type) - (concat (regexp-quote type) "\\.")) - - mint-lang-compound-types - "\\|") ) + (regexp-opt + (mapcar (lambda (type) + (concat (regexp-quote type) "\\.")) + mint-lang-compound-types))) ;; For operators like `=>` (regex-operators - (mapconcat (lambda (type) - (concat "[[:space:]]+" (regexp-quote type) "[[:space:]]*")) - - mint-lang-operators - "\\|") ) + (regexp-opt + (mapcar (lambda (type) + (concat "[[:space:]]+" (regexp-quote type) + "[[:space:]]*")) + mint-lang-operators))) ;; For html tag-open (no style applied) (regex-html-tag-open - (mapconcat (lambda (type) - (concat "<" "[[:space:]]*" (regexp-quote type) "[[:space:]]*" ">")) - mint-html-tags - "\\|") ) + (regexp-opt + (mapcar (lambda (type) + (concat "<" "[[:space:]]*" + (regexp-quote type) + "[[:space:]]*" ">")) + mint-html-tags))) (regex-html-tag-open-with-attr - (mapconcat (lambda (type) - (concat "<" "[[:space:]]*" (regexp-quote type) "[[:space:]]+" "[a-zA-Z\\-]+" "[[:space:]]*" "=")) - mint-html-tags - "\\|") ) + (regexp-opt + (mapcar (lambda (type) + (concat "<" "[[:space:]]*" + (regexp-quote type) + "[[:space:]]+" "[a-zA-Z\\-]+" + "[[:space:]]*" "=")) + mint-html-tags))) ;; For html tag-open (style applied) (regex-html-tag-open-with-style - (mapconcat (lambda (type) - (concat "<" "[[:space:]]*" (regexp-quote type) "[[:space:]]*" "::")) - mint-html-tags - "\\|") ) + (regexp-opt + (mapcar (lambda (type) + (concat "<" "[[:space:]]*" + (regexp-quote type) + "[[:space:]]*" "::")) + mint-html-tags))) ;; For html tag-close (regex-html-tag-close - (mapconcat (lambda (type) - (concat "<" "/" "[[:space:]]*" (regexp-quote type) "[[:space:]]*" ">")) - mint-html-tags - "\\|") ) + (regexp-opt + (mapcar (lambda (type) + (concat "<" "/" "[[:space:]]*" + (regexp-quote type) + "[[:space:]]*" ">")) + mint-html-tags))) ;; ;; For style colors (regex-style-colors (regexp-opt mint-style-colors 'words)) ;; For style property names (regex-style-properties - (mapconcat (lambda (type) - (concat (regexp-quote type) "[[:space:]]*" ":")) - - mint-style-properties - "\\|") ) + (regexp-opt + (mapcar (lambda (type) + (concat (regexp-quote type) "[[:space:]]*" ":")) + mint-style-properties))) ;; For style units (regex-style-units - (mapconcat (lambda (type) - (concat "[[:digit:]]+" "[[:space:]]*" (regexp-quote type))) - - mint-style-units - "\\|") ) + (regexp-opt + (mapcar (lambda (type) + (concat "[[:digit:]]+" "[[:space:]]*" + (regexp-quote type))) + mint-style-units))) ;; Other misc categories (regex-inline-marker "`")) From 13dae5e1d81dca9648d24685984a737d70f0dd80 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 5 Jul 2022 00:11:52 +0300 Subject: [PATCH 02/10] Disable hook for now @purcell from MELPA said: "Don't use your own major mode hook like this. Instead, provide a defcustom called something like "mint-format-on-save", and then add mint-format-on-save-maybe to before-save-hook. Note that I say before-save-hook, while you're currently using after-save-hook: mint-format-file wrongly assumes that every buffer will have an associated file, which is not true. mint-format-file should instead either copy the current buffer's contents to a temporary file, or you can use call-process-region/shell-command-on-region if mint format can read from STDIN." --- mint-mode.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mint-mode.el b/mint-mode.el index 4d3dd76..f902715 100644 --- a/mint-mode.el +++ b/mint-mode.el @@ -271,7 +271,10 @@ (push 'mint-keyword-completion-at-point completion-at-point-functions) ;; hook for formatting on save - (add-hook 'mint-mode-hook (lambda () (add-hook 'after-save-hook #'mint-format-file nil 'local))) + + ;; (add-hook 'mint-mode-hook + ;; (lambda () + ;; (add-hook 'after-save-hook #'mint-format-file nil 'local))) ;; For correctly formatting ansi terminal color codes (add-to-list 'comint-output-filter-functions 'ansi-color-process-output) From ec48b8cbc690beb1b88a614a36e0e7c81a0497c4 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 5 Jul 2022 00:12:23 +0300 Subject: [PATCH 03/10] Avoid byte-compiler warning --- mint-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mint-mode.el b/mint-mode.el index f902715..cfbd9a6 100644 --- a/mint-mode.el +++ b/mint-mode.el @@ -92,7 +92,7 @@ (defvar mint-all-tokens (append mint-all-lang-tokens mint-all-style-tokens mint-html-tags)) ;; Define regular expressions for syntax highlighting -(setq mint-font-lock-keywords +(defvar mint-font-lock-keywords ;; For simple keywords like `do`, `fun` etc. (let* ((regex-blocks (regexp-opt mint-lang-blocks 'words)) From cf088db3e354f2f08eb8176ecbded32098f8c657 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 5 Jul 2022 00:12:53 +0300 Subject: [PATCH 04/10] Add .elc to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e7de127..dcc5012 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.elc *.FASL *.fasl *.lisp-temp From 8ce8295f1623829e777356ca1c323bdd1e10ac79 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 5 Jul 2022 00:14:33 +0300 Subject: [PATCH 05/10] Break long lines --- mint-mode.el | 56 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/mint-mode.el b/mint-mode.el index cfbd9a6..22dbe11 100644 --- a/mint-mode.el +++ b/mint-mode.el @@ -63,33 +63,47 @@ ;; For highlighting language tokens ;; Simple -(defvar mint-lang-blocks (mint-get-tokens "./tokens/lang/blocks.txt")) -(defvar mint-lang-declarators (mint-get-tokens "./tokens/lang/declarators.txt")) -(defvar mint-lang-initializers (mint-get-tokens "./tokens/lang/initializers.txt")) -(defvar mint-lang-keywords (mint-get-tokens "./tokens/lang/keywords.txt")) -(defvar mint-lang-specifiers (mint-get-tokens "./tokens/lang/specifiers.txt")) -(defvar mint-lang-literal-types (mint-get-tokens "./tokens/lang/literal-types.txt")) +(defvar mint-lang-blocks + (mint-get-tokens "./tokens/lang/blocks.txt")) +(defvar mint-lang-declarators + (mint-get-tokens "./tokens/lang/declarators.txt")) +(defvar mint-lang-initializers + (mint-get-tokens "./tokens/lang/initializers.txt")) +(defvar mint-lang-keywords + (mint-get-tokens "./tokens/lang/keywords.txt")) +(defvar mint-lang-specifiers + (mint-get-tokens "./tokens/lang/specifiers.txt")) +(defvar mint-lang-literal-types + (mint-get-tokens "./tokens/lang/literal-types.txt")) ;; Compound -(defvar mint-lang-compound-types (mint-get-tokens "./tokens/lang/compound-types.txt")) -(defvar mint-lang-operators (mint-get-tokens "./tokens/lang/operators.txt")) +(defvar mint-lang-compound-types + (mint-get-tokens "./tokens/lang/compound-types.txt")) +(defvar mint-lang-operators + (mint-get-tokens "./tokens/lang/operators.txt")) ;; For highlighting html tags -(defvar mint-html-tags (mint-get-tokens "./tokens/html/tags.txt")) +(defvar mint-html-tags + (mint-get-tokens "./tokens/html/tags.txt")) ;; For highlighting css tokens -(defvar mint-style-colors (mint-get-tokens "./tokens/style/colors.txt")) -(defvar mint-style-properties (mint-get-tokens "./tokens/style/properties.txt")) -(defvar mint-style-units (mint-get-tokens "./tokens/style/units.txt")) +(defvar mint-style-colors + (mint-get-tokens "./tokens/style/colors.txt")) +(defvar mint-style-properties + (mint-get-tokens "./tokens/style/properties.txt")) +(defvar mint-style-units + (mint-get-tokens "./tokens/style/units.txt")) ;; All combined -(defvar mint-all-style-tokens (append mint-style-units mint-style-properties mint-style-colors)) -(defvar mint-all-lang-tokens (append - mint-lang-operators mint-lang-compound-types mint-lang-literal-types - mint-lang-specifiers mint-lang-keywords mint-lang-initializers - mint-lang-declarators mint-lang-blocks)) +(defvar mint-all-style-tokens + (append mint-style-units mint-style-properties mint-style-colors)) +(defvar mint-all-lang-tokens + (append mint-lang-operators mint-lang-compound-types mint-lang-literal-types + mint-lang-specifiers mint-lang-keywords mint-lang-initializers + mint-lang-declarators mint-lang-blocks)) -(defvar mint-all-tokens (append mint-all-lang-tokens mint-all-style-tokens mint-html-tags)) +(defvar mint-all-tokens + (append mint-all-lang-tokens mint-all-style-tokens mint-html-tags)) ;; Define regular expressions for syntax highlighting (defvar mint-font-lock-keywords @@ -219,8 +233,10 @@ :exclusive 'no :company-docsig #'identity - :company-doc-buffer (lambda (cand) - (company-doc-buffer (format "'%s' is defined in mint-mode plugin" cand))) )) )) + :company-doc-buffer + (lambda (cand) + (company-doc-buffer + (format "'%s' is defined in mint-mode plugin" cand))))))) ;; Function for reformatting .mint source files (defun mint-format-file () From b88f89fc981fe0f8a785c0a9dd63d1327354069b Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 5 Jul 2022 00:16:39 +0300 Subject: [PATCH 06/10] Edit package summary and docstring --- mint-mode.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mint-mode.el b/mint-mode.el index 22dbe11..df566ac 100644 --- a/mint-mode.el +++ b/mint-mode.el @@ -1,4 +1,4 @@ -;;; mint-mode.el --- major mode for editing .mint files. -*- coding: utf-8; lexical-binding: t; -*- +;;; mint-mode.el --- Major mode for the Mint programming language -*- coding: utf-8; lexical-binding: t; -*- ;; Author: Diwank Tomer ( singh@diwank.name ) ;; Summary: Major mode for editing .mint files. @@ -281,7 +281,7 @@ ;;;###autoload (define-derived-mode mint-mode js-jsx-mode "mint mode" - "Major mode for writing programs in mint lang." + "Major mode for writing programs in the Mint programming language." ;; Register auto complete fn (push 'mint-keyword-completion-at-point completion-at-point-functions) From 3cc9c2cc9ccbccd250afe503c90d026454afdea1 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 5 Jul 2022 00:17:13 +0300 Subject: [PATCH 07/10] Get seq package by depending on Emacs 25.1 Easier than a separate Package-Requires declaration for `seq`. --- mint-mode.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mint-mode.el b/mint-mode.el index df566ac..9660b4d 100644 --- a/mint-mode.el +++ b/mint-mode.el @@ -7,7 +7,7 @@ ;; URL: https://github.com/creatorrr/emacs-mint-mode ;; Created: 18 Nov 2018 ;; Keywords: mint languages processes convenience tools files -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "25.1")) ;;; License: @@ -39,7 +39,6 @@ ;;; Code: (require 'js) -(require 'seq) (require 'subr-x) ;; Utils From 579fc7bfd4a1ac49e83ff2b2e9c3edc96689fe72 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 5 Jul 2022 00:18:26 +0300 Subject: [PATCH 08/10] Appease checkdoc --- mint-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mint-mode.el b/mint-mode.el index 9660b4d..ed3560a 100644 --- a/mint-mode.el +++ b/mint-mode.el @@ -219,7 +219,7 @@ ;; Auto complete at point table (defun mint-keyword-completion-at-point () - "Provide completion at point table to company-mode." + "Provide completion at point table to `company-mode'." (interactive) (let ((bounds (bounds-of-thing-at-point 'word))) From 13f401b31395584d855e4319c2c3085e04d86715 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 5 Jul 2022 00:30:26 +0300 Subject: [PATCH 09/10] Fix regexp-opt usage --- mint-mode.el | 71 ++++++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 47 deletions(-) diff --git a/mint-mode.el b/mint-mode.el index ed3560a..e6b4fbe 100644 --- a/mint-mode.el +++ b/mint-mode.el @@ -117,79 +117,56 @@ ;; For compound type constructors like `Maybe(Number)` (regex-compound-type-constructors - (regexp-opt - (mapcar (lambda (type) - (concat (regexp-quote type) "[[:space:]]*" "(")) - mint-lang-compound-types))) + (concat (regexp-opt mint-lang-compound-types) + "[[:space:]]*" "(")) ;; For compound type classes like `Maybe.just` (regex-compound-type-classes - (regexp-opt - (mapcar (lambda (type) - (concat (regexp-quote type) "\\.")) - mint-lang-compound-types))) + (concat (regexp-opt mint-lang-compound-types) + "\\.")) ;; For operators like `=>` (regex-operators - (regexp-opt - (mapcar (lambda (type) - (concat "[[:space:]]+" (regexp-quote type) - "[[:space:]]*")) - mint-lang-operators))) + (concat "[[:space:]]+" + (regexp-opt mint-lang-operators) + "[[:space:]]*")) ;; For html tag-open (no style applied) (regex-html-tag-open - (regexp-opt - (mapcar (lambda (type) - (concat "<" "[[:space:]]*" - (regexp-quote type) - "[[:space:]]*" ">")) - mint-html-tags))) + (concat "<" "[[:space:]]*" + (regexp-opt mint-html-tags) + "[[:space:]]*" ">")) (regex-html-tag-open-with-attr - (regexp-opt - (mapcar (lambda (type) - (concat "<" "[[:space:]]*" - (regexp-quote type) - "[[:space:]]+" "[a-zA-Z\\-]+" - "[[:space:]]*" "=")) - mint-html-tags))) + (concat "<" "[[:space:]]*" + (regexp-opt mint-html-tags) + "[[:space:]]+" "[a-zA-Z\\-]+" + "[[:space:]]*" "=")) ;; For html tag-open (style applied) (regex-html-tag-open-with-style - (regexp-opt - (mapcar (lambda (type) - (concat "<" "[[:space:]]*" - (regexp-quote type) - "[[:space:]]*" "::")) - mint-html-tags))) + (concat "<" "[[:space:]]*" + (regexp-opt mint-html-tags) + "[[:space:]]*" "::")) ;; For html tag-close (regex-html-tag-close - (regexp-opt - (mapcar (lambda (type) - (concat "<" "/" "[[:space:]]*" - (regexp-quote type) - "[[:space:]]*" ">")) - mint-html-tags))) + (concat "<" "/" "[[:space:]]*" + (regexp-opt mint-html-tags) + "[[:space:]]*" ">")) ;; ;; For style colors (regex-style-colors (regexp-opt mint-style-colors 'words)) ;; For style property names (regex-style-properties - (regexp-opt - (mapcar (lambda (type) - (concat (regexp-quote type) "[[:space:]]*" ":")) - mint-style-properties))) + (concat (regexp-opt mint-style-properties) + "[[:space:]]*" ":")) ;; For style units (regex-style-units - (regexp-opt - (mapcar (lambda (type) - (concat "[[:digit:]]+" "[[:space:]]*" - (regexp-quote type))) - mint-style-units))) + (concat "[[:digit:]]+" "[[:space:]]*" + (regexp-opt mint-style-units))) ;; Other misc categories (regex-inline-marker "`")) From 9cae04fa8fb8d2e023ca5268a884c25fad0d4d32 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Tue, 5 Jul 2022 00:32:14 +0300 Subject: [PATCH 10/10] Say "regexp" instead of "regex" The former is the standard spelling in Emacs. --- mint-mode.el | 76 ++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/mint-mode.el b/mint-mode.el index e6b4fbe..222f867 100644 --- a/mint-mode.el +++ b/mint-mode.el @@ -108,91 +108,91 @@ (defvar mint-font-lock-keywords ;; For simple keywords like `do`, `fun` etc. - (let* ((regex-blocks (regexp-opt mint-lang-blocks 'words)) - (regex-declarators (regexp-opt mint-lang-declarators 'words)) - (regex-initializers (regexp-opt mint-lang-initializers 'words)) - (regex-keywords (regexp-opt mint-lang-keywords 'words)) - (regex-specifiers (regexp-opt mint-lang-specifiers 'words)) - (regex-literal-types (regexp-opt mint-lang-literal-types 'words)) + (let* ((regexp-blocks (regexp-opt mint-lang-blocks 'words)) + (regexp-declarators (regexp-opt mint-lang-declarators 'words)) + (regexp-initializers (regexp-opt mint-lang-initializers 'words)) + (regexp-keywords (regexp-opt mint-lang-keywords 'words)) + (regexp-specifiers (regexp-opt mint-lang-specifiers 'words)) + (regexp-literal-types (regexp-opt mint-lang-literal-types 'words)) ;; For compound type constructors like `Maybe(Number)` - (regex-compound-type-constructors + (regexp-compound-type-constructors (concat (regexp-opt mint-lang-compound-types) "[[:space:]]*" "(")) ;; For compound type classes like `Maybe.just` - (regex-compound-type-classes + (regexp-compound-type-classes (concat (regexp-opt mint-lang-compound-types) "\\.")) ;; For operators like `=>` - (regex-operators + (regexp-operators (concat "[[:space:]]+" (regexp-opt mint-lang-operators) "[[:space:]]*")) ;; For html tag-open (no style applied) - (regex-html-tag-open + (regexp-html-tag-open (concat "<" "[[:space:]]*" (regexp-opt mint-html-tags) "[[:space:]]*" ">")) - (regex-html-tag-open-with-attr + (regexp-html-tag-open-with-attr (concat "<" "[[:space:]]*" (regexp-opt mint-html-tags) "[[:space:]]+" "[a-zA-Z\\-]+" "[[:space:]]*" "=")) ;; For html tag-open (style applied) - (regex-html-tag-open-with-style + (regexp-html-tag-open-with-style (concat "<" "[[:space:]]*" (regexp-opt mint-html-tags) "[[:space:]]*" "::")) ;; For html tag-close - (regex-html-tag-close + (regexp-html-tag-close (concat "<" "/" "[[:space:]]*" (regexp-opt mint-html-tags) "[[:space:]]*" ">")) ;; ;; For style colors - (regex-style-colors (regexp-opt mint-style-colors 'words)) + (regexp-style-colors (regexp-opt mint-style-colors 'words)) ;; For style property names - (regex-style-properties + (regexp-style-properties (concat (regexp-opt mint-style-properties) "[[:space:]]*" ":")) ;; For style units - (regex-style-units + (regexp-style-units (concat "[[:digit:]]+" "[[:space:]]*" (regexp-opt mint-style-units))) ;; Other misc categories - (regex-inline-marker "`")) + (regexp-inline-marker "`")) ;; Set font-lock mode face for each category - `((,regex-blocks . font-lock-constant-face) - (,regex-declarators . font-lock-constant-face) - (,regex-initializers . font-lock-type-face) - (,regex-keywords . font-lock-warning-face) - (,regex-specifiers . font-lock-builtin-face) - (,regex-literal-types . font-lock-variable-name-face) - - (,regex-compound-type-constructors . font-lock-type-face) - (,regex-compound-type-classes . font-lock-string-face) - (,regex-operators . font-lock-variable-name-face) - - (,regex-html-tag-open . font-lock-variable-name-face) - (,regex-html-tag-open-with-attr . font-lock-variable-name-face) - (,regex-html-tag-open-with-style . font-lock-variable-name-face) - (,regex-html-tag-close . font-lock-variable-name-face) - - (,regex-style-colors . font-lock-constant-face) - (,regex-style-properties . font-lock-variable-name-face) - (,regex-style-units . font-lock-builtin-face) - - (,regex-inline-marker . font-lock-warning-face) ))) + `((,regexp-blocks . font-lock-constant-face) + (,regexp-declarators . font-lock-constant-face) + (,regexp-initializers . font-lock-type-face) + (,regexp-keywords . font-lock-warning-face) + (,regexp-specifiers . font-lock-builtin-face) + (,regexp-literal-types . font-lock-variable-name-face) + + (,regexp-compound-type-constructors . font-lock-type-face) + (,regexp-compound-type-classes . font-lock-string-face) + (,regexp-operators . font-lock-variable-name-face) + + (,regexp-html-tag-open . font-lock-variable-name-face) + (,regexp-html-tag-open-with-attr . font-lock-variable-name-face) + (,regexp-html-tag-open-with-style . font-lock-variable-name-face) + (,regexp-html-tag-close . font-lock-variable-name-face) + + (,regexp-style-colors . font-lock-constant-face) + (,regexp-style-properties . font-lock-variable-name-face) + (,regexp-style-units . font-lock-builtin-face) + + (,regexp-inline-marker . font-lock-warning-face) ))) ;; Auto complete at point table (defun mint-keyword-completion-at-point ()