experiments/tng2.el
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Wed, 16 Jan 2019 17:15:58 +0000
changeset 438 1fe179d53161
parent 8 7e193a2d4679
permissions -rw-r--r--
Add missing primitive implementation for the plain interpreter.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     1
(defconst tng2-mode-file-extension-regexp "\\.tng2\\'")
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     2
(let ((cell (assoc tng2-mode-file-extension-regexp auto-mode-alist)))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     3
  (if cell
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     4
      (rplacd cell 'tng2-mode)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     5
    (setq auto-mode-alist (cons `(,tng2-mode-file-extension-regexp . tng2-mode) auto-mode-alist))))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     6
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     7
(defun tng2-mode ()
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     8
  "Major mode for editing TNG2 programs (tonyg)."
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
     9
  (interactive)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    10
  (kill-all-local-variables)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    11
  (setq major-mode 'tng2-mode)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    12
  (setq mode-name "Smalltalk-TNG Experimental Syntax 2 Mode")
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    13
  (set-syntax-table tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    14
  (make-local-variable 'font-lock-defaults)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    15
  (setq font-lock-defaults '(tng2-font-lock-keywords nil nil () ()))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    16
  (make-local-variable 'tab-stop-list)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    17
  (setq tab-stop-list (let ((x '()))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    18
			(dotimes (i 60) (push (* 2 (+ i 1)) x))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    19
			(reverse x)))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    20
  (font-lock-fontify-buffer))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    21
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    22
(defconst tng2-font-lock-keywords
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    23
  '(
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    24
;    ("\\<%%primitive\\.[0-9]+\\.[0-9]+" . font-lock-function-name-face)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    25
;    ("\\<%%machine-code\\>" . font-lock-warning-face)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    26
;    ("\\<define\\s-+\\(\\(\\w\\|\\s_\\)+\\)\\>" 1 font-lock-variable-name-face)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    27
    ("\\<\\([A-Z]\\w*\\)\\>" 0 font-lock-type-face)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    28
    ("\\<\\(\\(\\w\\|\\s_\\)+:\\)" 1 font-lock-function-name-face)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    29
    ("\\$" 0 font-lock-function-name-face)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    30
    ("!\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\>" 1 font-lock-variable-name-face)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    31
    ("\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-+:=" 1 font-lock-variable-name-face)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    32
    ("\\<\\(meta\\)\\>" 1 font-lock-keyword-face)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    33
   ))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    34
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    35
(defvar tng2-mode-syntax-table nil
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    36
  "Syntax table used while in TNG2 mode.")
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    37
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    38
(if tng2-mode-syntax-table
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    39
    ()
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    40
  (setq tng2-mode-syntax-table (make-syntax-table))
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    41
  (modify-syntax-entry ?\' "\"   " tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    42
  (modify-syntax-entry ?\" "!   " tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    43
  (modify-syntax-entry ?? "_ " tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    44
  (modify-syntax-entry ?- "_ " tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    45
  (modify-syntax-entry ?: "_ " tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    46
  (modify-syntax-entry ?\( "()" tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    47
  (modify-syntax-entry ?\) ")(" tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    48
  (modify-syntax-entry ?\[ "(]" tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    49
  (modify-syntax-entry ?\] ")[" tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    50
  (modify-syntax-entry ?\{ "(}" tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    51
  (modify-syntax-entry ?\} "){" tng2-mode-syntax-table)
7e193a2d4679 Experiments in TNG syntax; skeletal emacs-mode
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
diff changeset
    52
)