branch: elpa/j-mode commit 01c6e26d48e0e6d124bed57cc761ce4689c0fc22 Author: LdBeth <andp...@foxmail.com> Commit: LdBeth <andp...@foxmail.com>
better highlighting and proper indentation --- j-console.el | 4 ---- j-font-lock.el | 44 +++++++++++++++++++++++++++++--------------- j-help.el | 2 +- j-mode.el | 24 +++++++++++++++++------- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/j-console.el b/j-console.el index ff7cc50b21..ff8418a14e 100644 --- a/j-console.el +++ b/j-console.el @@ -37,10 +37,6 @@ (require 'comint) - -;; (defconst j-console-version "1.1.1" -;; "`j-console' version") - (defgroup j-console nil "REPL integration extention for `j-mode'" :group 'applications diff --git a/j-font-lock.el b/j-font-lock.el index 3cb0ea46be..1606204108 100644 --- a/j-font-lock.el +++ b/j-font-lock.el @@ -83,13 +83,13 @@ (let ((table (make-syntax-table))) (modify-syntax-entry ?\{ "." table) (modify-syntax-entry ?\} "." table) - (modify-syntax-entry ?\[ "." table) - (modify-syntax-entry ?\] "." table) - (modify-syntax-entry ?\" "." table) + (modify-syntax-entry '(?! . ?&) "." table) + (modify-syntax-entry '(?* . ?/) "." table) + (modify-syntax-entry '(?: . ?@) "." table) + (modify-syntax-entry '(?\[ . ?^) "." table) (modify-syntax-entry ?\\ "." table) - (modify-syntax-entry ?\. "w" table) - (modify-syntax-entry ?\: "w" table) - (modify-syntax-entry ?\_ "w" table) + ;; (modify-syntax-entry ?\. "_" table) + ;; (modify-syntax-entry ?\: "_" table) (modify-syntax-entry ?\( "()" table) (modify-syntax-entry ?\) ")(" table) (modify-syntax-entry ?\' "\"" table) @@ -100,6 +100,11 @@ table) "Syntax table for j-mode") +(defalias 'j-mode-syntax-propertize + (syntax-propertize-rules + ("^\\()\\)" (1 ".")) + ("{{\\()\\)\s" (1 ".")))) + (defvar j-font-lock-constants '( ;; char codes @@ -171,11 +176,11 @@ (append j-font-lock-len-3-others j-font-lock-len-2-others j-font-lock-len-1-others)) (defvar j-font-lock-len-3-conjunctions - '("&.:" "F.." "F.:" "F:." "F::")) + '("&.:" "F.." "F.:" "F:." "F::" " ::" " :.")) (defvar j-font-lock-len-2-conjunctions '("t." "S:" "L:" "H." "D:" "D." "d." "F." "F:" "m." "&:" "&." "@:" "@." "`:" "!:" "!." ";." - "::" ":." ".:" ".." "^:" " ." " :")) + "^:" " ." " :")) (defvar j-font-lock-len-1-conjunctions '("&" "@" "`" "\"")) (defvar j-font-lock-conjunctions @@ -186,25 +191,34 @@ (defvar j-font-lock-keywords `( - (,(rx (seq (group (regexp "[_a-zA-Z0-9]+")) + (,(rx (seq (group (* (any "_a-zA-Z0-9"))) (* "\s") (group "=" (or "." ":")))) (1 font-lock-variable-name-face) (2 j-other-face)) + (,(rx bow (any "a-zA-Z") + (* (any "_a-zA-Z0-9")) + "_:") ;; Self-Effacing References + . font-lock-warning-face) (,(regexp-opt j-font-lock-foreign-conjunctions) . font-lock-warning-face) - (,(rx bow (or (regexp (regexp-opt j-font-lock-control-structures)) - (seq (or "for" "goto" "label") - (regexp "_[a-zA-Z]+\\.")))) + (,(rx symbol-start + (or (regexp (regexp-opt j-font-lock-control-structures)) + (seq (or "for" "goto" "label") + "_" (+ (any "a-zA-Z")) "."))) . font-lock-keyword-face) - (,(rx bow (regexp (regexp-opt j-font-lock-builtins)) eow) + (,(rx symbol-start (regexp (regexp-opt j-font-lock-builtins)) eow) . font-lock-builtin-face) - (,(regexp-opt j-font-lock-constants) . font-lock-constant-face) + (,(rx symbol-start + (regexp + (regexp-opt j-font-lock-constants)) + eow) + . font-lock-constant-face) (,(regexp-opt j-font-lock-len-3-verbs) . j-verb-face) (,(regexp-opt j-font-lock-len-3-adverbs) . j-adverb-face) (,(regexp-opt j-font-lock-len-3-conjunctions) . j-conjunction-face) ;;(,(regexp-opt j-font-lock-len-3-others) . ) (,(rx (or (regexp (regexp-opt j-font-lock-len-2-verbs)) - (seq bow (opt "_") (regexp "[0-9_]") ":"))) + (seq symbol-start (opt "_") (regexp "[0-9_]") ":"))) . j-verb-face) (,(regexp-opt j-font-lock-len-2-adverbs) . j-adverb-face) (,(regexp-opt j-font-lock-len-2-conjunctions) . j-conjunction-face) diff --git a/j-help.el b/j-help.el index d28c930809..08f9ba1fe6 100644 --- a/j-help.el +++ b/j-help.el @@ -48,7 +48,7 @@ (if list (let* ((head (car list)) (tail (cdr list))) - (if (eq (funcall fn head) (funcall fn prev)) + (if (eql (funcall fn head) (funcall fn prev)) (group-by* tail fn head (cons head coll) agr) (group-by* tail fn head '() (cons coll agr)))) (cons coll agr))) diff --git a/j-mode.el b/j-mode.el index 4a63a01b36..f5ea9489a1 100644 --- a/j-mode.el +++ b/j-mode.el @@ -54,10 +54,6 @@ (require 'j-help) (eval-when-compile (require 'rx)) - -(defconst j-mode-version "1.1.1" - "`j-mode' version") - (defgroup j nil "A mode for J" :group 'languages @@ -88,9 +84,16 @@ (regexp "_[a-zA-Z]+\\.")))) (seq (regexp "[_a-zA-Z0-9]+") (* "\s") "=" (or "." ":") (* "\s") - "{{")))) + (or "{{" + (seq "0" (+ "\s") ":" (* "\s") + (regexp + (regexp-opt + '("dyad" "monad" "adverb" "verb" "conjunction" + "1" "2" "3" "4"))) + eol)))))) (defconst j-dedenting-keywords-regexp (rx (or "}}" + (seq bol ")" eol) (seq bow (regexp (regexp-opt '("end." "else." "elseif." @@ -126,7 +129,10 @@ contents of current line." (if (and (looking-at j-indenting-keywords-regexp) (progn (goto-char (match-end 0)) - (not (j-thing-outside-string "\\<end\\.")))) + (not (j-thing-outside-string + (rx (or (seq word-start "end.") + "}}" + (seq bol ")" eol))))))) (+ (current-indentation) j-indent-offset) (current-indentation)))) nil)))) @@ -181,8 +187,12 @@ contents of current line." (setq-local comment-start "NB. " comment-start-skip - "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)NB. *" + (rx (group (group (or bol (not (any "\\" "\n" )))) + (* (group "\\\\"))) + "NB." + (* "\s")) comment-column 40 + syntax-propertize-function #'j-mode-syntax-propertize indent-tabs-mode nil indent-line-function #'j-indent-line font-lock-comment-start-skip