comparison lisp/progmodes/scheme.el @ 21133:ea8428070d53

(scheme-mode-variables): Set font-lock-defaults locally. (scheme-font-lock-keywords-1, scheme-font-lock-keywords-2, scheme-font-lock-keywords): Moved here from font-lock.el. (dsssl-mode): Move font-lock-defaults setting and running hooks.
author Dave Love <fx@gnu.org>
date Tue, 10 Mar 1998 22:51:23 +0000
parents f3f9df46d008
children 1f3afd785962
comparison
equal deleted inserted replaced
21132:75c6408013e5 21133:ea8428070d53
1 ;;; scheme.el --- Scheme (and DSSSL) editing mode. 1 ;;; scheme.el --- Scheme (and DSSSL) editing mode.
2 2
3 ;; Copyright (C) 1986, 87, 88, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1986, 87, 88, 97, 1998 Free Software Foundation, Inc.
4 4
5 ;; Author: Bill Rozas <jinx@martigny.ai.mit.edu> 5 ;; Author: Bill Rozas <jinx@martigny.ai.mit.edu>
6 ;; Adapted-by: Dave Love <d.love@dl.ac.uk> 6 ;; Adapted-by: Dave Love <d.love@dl.ac.uk>
7 ;; Keywords: languages, lisp 7 ;; Keywords: languages, lisp
8 8
161 (make-local-variable 'imenu-case-fold-search) 161 (make-local-variable 'imenu-case-fold-search)
162 (setq imenu-case-fold-search t) 162 (setq imenu-case-fold-search t)
163 (make-local-variable 'imenu-generic-expression) 163 (make-local-variable 'imenu-generic-expression)
164 (setq imenu-generic-expression scheme-imenu-generic-expression) 164 (setq imenu-generic-expression scheme-imenu-generic-expression)
165 (make-local-variable 'imenu-syntax-alist) 165 (make-local-variable 'imenu-syntax-alist)
166 (setq imenu-syntax-alist '(("+-*/.<>=?!$%_&~^:" . "w")))) 166 (setq imenu-syntax-alist '(("+-*/.<>=?!$%_&~^:" . "w")))
167 (make-local-variable 'font-lock-defaults)
168 (setq font-lock-defaults
169 '((scheme-font-lock-keywords
170 scheme-font-lock-keywords-1 scheme-font-lock-keywords-2)
171 nil t (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun
172 (font-lock-mark-block-function . mark-defun))))
167 173
168 (defvar scheme-mode-line-process "") 174 (defvar scheme-mode-line-process "")
169 175
170 (defvar scheme-mode-map nil 176 (defvar scheme-mode-map nil
171 "Keymap for Scheme mode. 177 "Keymap for Scheme mode.
246 :type '(choice (string :tag "Specified string") 252 :type '(choice (string :tag "Specified string")
247 (const :tag "None" :value nil)) 253 (const :tag "None" :value nil))
248 :group 'scheme) 254 :group 'scheme)
249 255
250 (defcustom scheme-mode-hook nil 256 (defcustom scheme-mode-hook nil
251 "*Normal hook (list of functions) run when entering scheme-mode. 257 "Normal hook (list of functions) run when entering scheme-mode.
252 See `run-hooks'." 258 See `run-hooks'."
253 :type 'hook 259 :type 'hook
254 :group 'scheme) 260 :group 'scheme)
255 261
256 (defcustom dsssl-mode-hook nil 262 (defcustom dsssl-mode-hook nil
257 "*Normal hook (list of functions) run when entering dsssl-mode. 263 "Normal hook (list of functions) run when entering dsssl-mode.
258 See `run-hooks'." 264 See `run-hooks'."
259 :type 'hook 265 :type 'hook
260 :group 'scheme) 266 :group 'scheme)
261 267
262 (defvar dsssl-imenu-generic-expression 268 (defvar dsssl-imenu-generic-expression
274 "^\\s-*(element\\s-+(?\\(\\(\\sw\\|\\s-\\)+\\))?" 1) 280 "^\\s-*(element\\s-+(?\\(\\(\\sw\\|\\s-\\)+\\))?" 1)
275 (" Declarations" 281 (" Declarations"
276 "^(declare\\(-\\sw+\\)+\\>\\s-+\\(\\sw+\\)" 2)) 282 "^(declare\\(-\\sw+\\)+\\>\\s-+\\(\\sw+\\)" 2))
277 "Imenu generic expression for DSSSL mode. See `imenu-generic-expression'.") 283 "Imenu generic expression for DSSSL mode. See `imenu-generic-expression'.")
278 284
285 (defconst scheme-font-lock-keywords-1
286 (eval-when-compile
287 (list
288 ;;
289 ;; Declarations. Hannes Haug <hannes.haug@student.uni-tuebingen.de> says
290 ;; this works for SOS, STklos, SCOOPS, Meroon and Tiny CLOS.
291 (list (concat "(\\(define\\("
292 ;; Function names.
293 "\\(\\|-method\\|-generic\\(-procedure\\)?\\)\\|"
294 ;; Macro names, as variable names. A bit dubious, this.
295 "\\(-syntax\\)\\|"
296 ;; Class names.
297 "-class"
298 "\\)\\)\\>"
299 ;; Any whitespace and declared object.
300 "[ \t]*(?"
301 "\\(\\sw+\\)?")
302 '(1 font-lock-keyword-face)
303 '(6 (cond ((match-beginning 3) font-lock-function-name-face)
304 ((match-beginning 5) font-lock-variable-name-face)
305 (t font-lock-type-face))
306 nil t))
307 ))
308 "Subdued expressions to highlight in Scheme modes.")
309
310 (defconst scheme-font-lock-keywords-2
311 (append scheme-font-lock-keywords-1
312 (eval-when-compile
313 (list
314 ;;
315 ;; Control structures.
316 (cons
317 (concat
318 "(" (regexp-opt
319 '("begin" "call-with-current-continuation" "call/cc"
320 "call-with-input-file" "call-with-output-file" "case" "cond"
321 "do" "else" "for-each" "if" "lambda"
322 "let" "let*" "let-syntax" "letrec" "letrec-syntax"
323 ;; Hannes Haug <hannes.haug@student.uni-tuebingen.de> wants:
324 "and" "or" "delay"
325 ;; Stefan Monnier <stefan.monnier@epfl.ch> says don't bother:
326 ;;"quasiquote" "quote" "unquote" "unquote-splicing"
327 "map" "syntax" "syntax-rules") t)
328 "\\>") 1)
329 ;;
330 ;; David Fox <fox@graphics.cs.nyu.edu> for SOS/STklos class specifiers.
331 '("\\<<\\sw+>\\>" . font-lock-type-face)
332 ;;
333 ;; Scheme `:' keywords as builtins.
334 '("\\<:\\sw+\\>" . font-lock-builtin-face)
335 )))
336 "Gaudy expressions to highlight in Scheme modes.")
337
338 (defvar scheme-font-lock-keywords scheme-font-lock-keywords-1
339 "Default expressions to highlight in Scheme modes.")
340
279 ;;;###autoload 341 ;;;###autoload
280 (defun dsssl-mode () 342 (defun dsssl-mode ()
281 "Major mode for editing DSSSL code. 343 "Major mode for editing DSSSL code.
282 Editing commands are similar to those of lisp-mode. 344 Editing commands are similar to those of lisp-mode.
283 345
284 Commands: 346 Commands:
285 Delete converts tabs to spaces as it moves back. 347 Delete converts tabs to spaces as it moves back.
286 Blank lines separate paragraphs. Semicolons start comments. 348 Blank lines separate paragraphs. Semicolons start comments.
287 \\{scheme-mode-map} 349 \\{scheme-mode-map}
288 Entry to this mode calls the value of dsssl-mode-hook 350 Entering this mode runs the hooks `scheme-mode-hook' and then
289 if that value is non-nil and inserts the value of 351 `dsssl-mode-hook' and inserts the value of `dsssl-sgml-declaration' if
290 `dsssl-sgml-declaration' if that variable's value is a string." 352 that variable's value is a string."
291 (interactive) 353 (interactive)
292 (kill-all-local-variables) 354 (kill-all-local-variables)
293 (use-local-map scheme-mode-map) 355 (use-local-map scheme-mode-map)
294 (scheme-mode-initialize) 356 (scheme-mode-initialize)
295 (make-local-variable 'font-lock-defaults)
296 (setq font-lock-defaults '(dsssl-font-lock-keywords
297 nil t (("+-*/.<>=?$%_&~^:" . "w"))
298 beginning-of-defun
299 (font-lock-comment-start-regexp . ";")
300 (font-lock-mark-block-function . mark-defun)))
301 (make-local-variable 'page-delimiter) 357 (make-local-variable 'page-delimiter)
302 (setq page-delimiter "^;;;" ; ^L not valid SGML char 358 (setq page-delimiter "^;;;" ; ^L not valid SGML char
303 major-mode 'dsssl-mode 359 major-mode 'dsssl-mode
304 mode-name "DSSSL") 360 mode-name "DSSSL")
305 ;; Insert a suitable SGML declaration into an empty buffer. 361 ;; Insert a suitable SGML declaration into an empty buffer.
306 (and (zerop (buffer-size)) 362 (and (zerop (buffer-size))
307 (stringp dsssl-sgml-declaration) 363 (stringp dsssl-sgml-declaration)
308 (not buffer-read-only) 364 (not buffer-read-only)
309 (insert dsssl-sgml-declaration)) 365 (insert dsssl-sgml-declaration))
310 (run-hooks 'scheme-mode-hook)
311 (run-hooks 'dsssl-mode-hook)
312 (scheme-mode-variables) 366 (scheme-mode-variables)
367 (setq font-lock-defaults '(dsssl-font-lock-keywords
368 nil t (("+-*/.<>=?$%_&~^:" . "w"))
369 beginning-of-defun
370 (font-lock-mark-block-function . mark-defun)))
313 (setq imenu-case-fold-search nil) 371 (setq imenu-case-fold-search nil)
314 (setq imenu-generic-expression dsssl-imenu-generic-expression) 372 (setq imenu-generic-expression dsssl-imenu-generic-expression)
315 (setq imenu-syntax-alist '(("+-*/.<>=?$%_&~^:" . "w")))) 373 (setq imenu-syntax-alist '(("+-*/.<>=?$%_&~^:" . "w")))
374 (run-hooks 'scheme-mode-hook)
375 (run-hooks 'dsssl-mode-hook))
316 376
317 ;; Extra syntax for DSSSL. This isn't separated from Scheme, but 377 ;; Extra syntax for DSSSL. This isn't separated from Scheme, but
318 ;; shouldn't cause much trouble in scheme-mode. 378 ;; shouldn't cause much trouble in scheme-mode.
319 (put 'element 'scheme-indent-function 1) 379 (put 'element 'scheme-indent-function 1)
320 (put 'mode 'scheme-indent-function 1) 380 (put 'mode 'scheme-indent-function 1)