Removed the notion of a "large" context. For simplicity, all contexts
[panda.git] / st-mode.el
blob2e2071df09f3ee6e8e04f6479e97a8e4ed403f79
1 ;;
2 ;; st-mode.el: A simple Smalltalk editing mode
3 ;;
4 ;; Copyright (C) 2008 Vincent Geddes <vincent.geddes@gmail.com>
5 ;;
6 ;; Permission is hereby granted, free of charge, to any person obtaining a copy
7 ;; of this software and associated documentation files (the "Software"), to deal
8 ;; in the Software without restriction, including without limitation the rights
9 ;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 ;; copies of the Software, and to permit persons to whom the Software is
11 ;; furnished to do so, subject to the following conditions:
13 ;; The above copyright notice and this permission notice shall be included in
14 ;; all copies or substantial portions of the Software.
15 ;;
16 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 ;; THE SOFTWARE.
25 ;; This mode is intended for editing Smalltalk file-outs that use the chunk syntax.
27 ;; To install st-mode.el:
29 ;; 1. Put st-mode.el somewhere in your load-path
30 ;; 2. Add the following line to your .emacs file:
31 ;; (add-to-list 'auto-mode-alist '("\\.st\\'" . st-mode))
32 ;; (autoload 'st-mode "st-mode" nil t)
35 (require 'font-lock)
37 (defvar st-mode-hook nil)
39 (defvar st-mode-map
40 (let ((st-mode-map (make-keymap)))
41 (define-key st-mode-map "\C-j" 'newline-and-indent)
42 st-mode-map)
43 "Keymap for Smalltalk major mode")
45 ;;; ; "pseudo" keywords
46 ;;; '("\\(false\\|nil\\|s\\(?:elf\\|uper\\)\\|t\\(?:hisContext\\|rue\\)\\)" . font-lock-keyword-face)
47 ;;; ; character constants
48 ;;; '("\\(\$[]a-zA-Z0-9!@#$%^&*()\-_=+{};:,./<>?\\|]\\)" . font-lock-constant-face)
49 ;;; ; symbol constants
50 ;;; '("\#[a-zA-Z][a-zA-Z0-9]*" . font-lock-constant-face)
51 ;;; ; number constants
52 ;;; '("\\([0-9][0-9]r\\)?[0-9]\\(\.[0-9]\\(e-?[0-9]\\)?\\)?" . font-lock-constant-face))
54 (defvar st-font-lock-keywords
55 `((,(rx symbol-start
56 (or "false" "true" "nil" "self" "super" "thisContext")
57 symbol-end)
58 . font-lock-keyword-face)
59 (,(rx (regexp "\\([0-9][0-9]r\\)?[0-9]\\(\.[0-9]\\(e-?[0-9]\\)?\\)?"))
60 . font-lock-constant-face)
61 (,(rx (regexp "\#[a-zA-Z][a-zA-Z0-9]*"))
62 . font-lock-constant-face)
63 (,(rx (regexp "\\(\$[]a-zA-Z0-9!@#$%^&*()\-_=+{};:,./<>?\\|]\\)"))
64 . font-lock-constant-face))
65 "Highlighting expressions for Smalltalk mode")
68 (defvar st-mode-syntax-table
69 (let ((st-mode-syntax-table (make-syntax-table)))
70 (modify-syntax-entry ?' "|" st-mode-syntax-table)
71 (modify-syntax-entry ?\" "!" st-mode-syntax-table)
72 st-mode-syntax-table)
73 "Syntax table for Smalltalk mode")
75 (defvar st-indent-level 4
76 "Default indent level for indenting")
78 (defun st-indent-line ()
79 "Indent current line as Smalltalk code"
80 ; Allows unrestricted indenting of current line unless
81 ; line happens to be the first in the buffer or a chunk.
82 (interactive)
83 (beginning-of-line)
84 (if (bobp)
85 (indent-line-to 0)
86 (let ((can-indent t))
87 (save-excursion
88 (skip-chars-backward "\r\n\t ")
89 (if (char-equal (preceding-char) ?!)
90 (setq can-indent nil)))
91 (if can-indent
92 (indent-line-to (+ (current-indentation) st-indent-level))))))
94 (defun st-mode ()
95 "Major mode for editing ANSI Smalltalk Interchange files"
96 (interactive)
97 (kill-all-local-variables)
98 (set-syntax-table st-mode-syntax-table)
99 (use-local-map st-mode-map)
100 (set (make-local-variable 'font-lock-defaults) '(st-font-lock-keywords))
101 (set (make-local-variable 'indent-line-function) 'st-indent-line)
102 (set (make-local-variable 'comment-start) "\"")
103 (set (make-local-variable 'comment-end) "\"")
104 (set (make-local-variable 'comment-padding) nil)
105 (set (make-local-variable 'comment-multi-line) t)
106 (set (make-local-variable 'tab-width) st-indent-level)
107 (setq major-mode 'st-mode)
108 (setq mode-name "Smalltalk")
109 (run-hooks 'st-mode-hook))
111 (provide 'st-mode)