2 ;; st-mode.el: A simple Smalltalk editing mode
4 ;; Copyright (C) 2008 Vincent Geddes <vincent.geddes@gmail.com>
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.
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
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)
37 (defvar st-mode-hook nil
)
40 (let ((st-mode-map (make-keymap)))
41 (define-key st-mode-map
"\C-j" 'newline-and-indent
)
43 "Keymap for Smalltalk major mode")
45 (defconst st-font-lock-keywords-1
48 '("\\(false\\|nil\\|s\\(?:elf\\|uper\\)\\|t\\(?:hisContext\\|rue\\)\\)" . font-lock-keyword-face
)
50 '("\\(\$[]a-zA-Z0-9!@#$%^&*()\-_=+{};:,./<>?\\|]\\)" . font-lock-constant-face
)
52 '("\#[a-zA-Z][a-zA-Z0-9]*" . font-lock-constant-face
)
54 '("\\([0-9][0-9]r\\)?[0-9]\\(\.[0-9]\\(e-?[0-9]\\)?\\)?" . font-lock-constant-face
))
55 "Highlighting expressions for Smalltalk mode")
57 (defvar st-mode-syntax-table
58 (let ((st-mode-syntax-table (make-syntax-table)))
59 (modify-syntax-entry ?
' "|" st-mode-syntax-table
)
60 (modify-syntax-entry ?
\" "!" st-mode-syntax-table
)
62 "Syntax table for Smalltalk mode")
64 (defvar st-font-lock-keywords st-font-lock-keywords-1
65 "Default highlighting expressions for Smalltalk mode")
67 (defvar st-indent-level
4
68 "Default indent level for indenting")
70 (defun st-indent-line ()
71 "Indent current line as Smalltalk code"
72 ; Allows unrestricted indenting of current line unless
73 ; line happens to be the first in the buffer or a chunk.
80 (skip-chars-backward "\r\n\t ")
81 (if (char-equal (preceding-char) ?
!)
82 (setq can-indent nil
)))
84 (indent-line-to (+ (current-indentation) st-indent-level
))))))
87 "Major mode for editing ANSI Smalltalk Interchange files"
89 (kill-all-local-variables)
90 (set-syntax-table st-mode-syntax-table
)
91 (use-local-map st-mode-map
)
92 (set (make-local-variable 'font-lock-defaults
) '(st-font-lock-keywords))
93 (set (make-local-variable 'indent-line-function
) 'st-indent-line
)
94 (set (make-local-variable 'comment-start
) "\"")
95 (set (make-local-variable 'comment-end
) "\"")
96 (set (make-local-variable 'comment-padding
) nil
)
97 (set (make-local-variable 'comment-multi-line
) t
)
98 (set (make-local-variable 'tab-width
) st-indent-level
)
99 (setq major-mode
'st-mode
)
100 (setq mode-name
"Smalltalk")
101 (run-hooks 'st-mode-hook
))