branch: elpa/j-mode
commit 4f286fd9e69ed536f5088ccc4a6b01873fae049c
Author: LdBeth <andp...@foxmail.com>
Commit: LdBeth <andp...@foxmail.com>

    Support J Lab format
---
 j-font-lock.el | 45 +++++++++++++++++++++++++++++++++++----------
 j-mode.el      | 11 +++++++++--
 2 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/j-font-lock.el b/j-font-lock.el
index dd98458a3f..6728f7f181 100644
--- a/j-font-lock.el
+++ b/j-font-lock.el
@@ -102,7 +102,22 @@
     (0 (j-font-lock-nota-bene)))
    ("\\(?:0\\|noun\\)\s+\\(?::\s*0\\|define\\)"
     (0 (j-font-lock-multiline-string ?:)))
-   ("^\\()\\)" (1 (j-font-lock-multiline-string ?\))))
+   ("^\\()\\)$" (1 (j-font-lock-multiline-string ?\))))
+   ("{{)n" (0 (j-font-lock-multiline-string ?\{)))
+   ("}}" (0 (j-font-lock-multiline-string ?\})))
+   ("{{\\()\\)" (1 "."))
+   ("\\('\\)`?[0-9A-Z_a-z ]*\\('\\)\s*=[.:]" (1 ".") (2 "."))
+   ("\\('\\)\\(?:[^'\n]\\|''\\)*\\('\\)" (1 "\"") (2 "\""))))
+
+(defalias 'j-lab-mode-syntax-propertize
+  (syntax-propertize-rules
+   ("\\(N\\)\\(?:B\\.\s*\\(?:===\\|---\\)\\|ote\s*''\\)"
+    (1 (j-font-lock-multiline-string ?N)))
+   ("\\(N\\)\\(B\\)\\..*$" (1 "w 1") (2 "w 2")
+    (0 (j-font-lock-nota-bene)))
+   ("\\(?:0\\|noun\\)\s+\\(?::\s*0\\|define\\)"
+    (0 (j-font-lock-multiline-string ?:)))
+   ("^\\()\\)$" (1 (j-font-lock-multiline-string ?\))))
    ("{{)n" (0 (j-font-lock-multiline-string ?\{)))
    ("}}" (0 (j-font-lock-multiline-string ?\})))
    ("{{\\()\\)" (1 "."))
@@ -118,10 +133,16 @@
     (?: (let* ((ppss (syntax-ppss))
                (string-start (and (eq t (nth 3 ppss)) (nth 8 ppss)))
                (eol (pos-eol)))
-          (unless (or string-start (> (1+ eol) (point-max)))
+          (unless (or (or string-start (> (1+ eol) (point-max)))
+                      (save-excursion
+                        (goto-char (1+ eol))
+                        (looking-at "^)$")))
             (put-text-property eol (1+ eol)
                                'syntax-table (string-to-syntax "|")))
           nil))
+    (?N (let ((ppss (save-excursion (syntax-ppss (match-beginning 1)))))
+          (unless (and (eq t (nth 3 ppss)) (nth 8 ppss)) ; inside string
+            (string-to-syntax "|"))))
     (?\{ (let* ((ppss (save-excursion (backward-char 4) (syntax-ppss)))
                (string-start (and (eq t (nth 3 ppss)) (nth 8 ppss)))
                (quote-starting-pos (- (point) 4)))
@@ -134,8 +155,9 @@
     (?\) (let* ((ppss (save-excursion (backward-char 2) (syntax-ppss)))
                 (string-start (and (eq t (nth 3 ppss)) (nth 8 ppss)))
                 (quote-starting-pos (- (point) 1)))
-           (if (and string-start (eql (char-after string-start)
-                                      ?\n))
+           (if (and string-start (or
+                                  (eql (char-after string-start) ?\n)
+                                  (eql (char-after string-start) ?N)))
                (put-text-property (1- quote-starting-pos) quote-starting-pos
                                   'syntax-table (string-to-syntax "|")))
            (string-to-syntax ".")))
@@ -301,13 +323,16 @@
   "Function for detection of string vs. Comment. Note: J comments
 are three chars longs, there is no easy / evident way to handle
 this in emacs and it poses problems"
-  (let* ((start-pos (nth 8 state)))
+  (let ((start-pos (nth 8 state)))
     (cond
-     ((nth 3 state) (if (and
-                         (eql (char-after start-pos) ?\n)
-                         (j-font-lock-docstring-p state))
-                        font-lock-doc-face
-                      font-lock-string-face))
+     ((nth 3 state)
+      (if (or (and ; A free standing multiline string
+               (eql (char-after start-pos) ?\n)
+               (j-font-lock-docstring-p state))
+              ;; J Lab command
+              (eql (char-after start-pos) ?N))
+          font-lock-doc-face
+        font-lock-string-face))
      ((and (<= (+ start-pos 3) (point-max))
            (eql (char-after start-pos) ?N)
            (string= (buffer-substring-no-properties
diff --git a/j-mode.el b/j-mode.el
index f6e7cd15fc..63aeed7f5e 100644
--- a/j-mode.el
+++ b/j-mode.el
@@ -241,7 +241,7 @@ contents of current line."
 
 ;;;###autoload
 (define-derived-mode j-mode prog-mode "J"
-  "Major mode for editing J"
+  "Major mode for editing J."
   :group 'j
   :syntax-table j-font-lock-syntax-table
   (setq-local comment-start
@@ -266,9 +266,16 @@ contents of current line."
                 (font-lock-syntactic-face-function
                  . j-font-lock-syntactic-face-function))))
 
+;;;###autoload
+(define-derived-mode j-lab-mode j-mode "J Lab"
+  "Mojor mode for J Labs."
+  :group 'j
+  (setq-local syntax-propertize-function #'j-lab-mode-syntax-propertize))
 
 ;;;###autoload
-(add-to-list 'auto-mode-alist '("\\.ij[rstp]$" . j-mode))
+(progn
+  (add-to-list 'auto-mode-alist '("\\.ij[rsp]$" . j-mode))
+  (add-to-list 'auto-mode-alist '("\\.ijt$" . j-lab-mode)))
 
 (provide 'j-mode)
 

Reply via email to