123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- (require 'lisp-mode)
- (defvar scheme-mode-syntax-table
- (let ((st (make-syntax-table))
- (i 0))
-
-
-
-
- (while (< i ?0)
- (modify-syntax-entry i "_ " st)
- (setq i (1+ i)))
- (setq i (1+ ?9))
- (while (< i ?A)
- (modify-syntax-entry i "_ " st)
- (setq i (1+ i)))
- (setq i (1+ ?Z))
- (while (< i ?a)
- (modify-syntax-entry i "_ " st)
- (setq i (1+ i)))
- (setq i (1+ ?z))
- (while (< i 128)
- (modify-syntax-entry i "_ " st)
- (setq i (1+ i)))
-
- (modify-syntax-entry ?\t " " st)
- (modify-syntax-entry ?\n "> " st)
- (modify-syntax-entry ?\f " " st)
- (modify-syntax-entry ?\r " " st)
- (modify-syntax-entry ?\s " " st)
-
-
- (modify-syntax-entry ?\[ "(] " st)
- (modify-syntax-entry ?\] ")[ " st)
- (modify-syntax-entry ?{ "(} " st)
- (modify-syntax-entry ?} "){ " st)
- (modify-syntax-entry ?\| "\" 23bn" st)
-
-
-
-
-
-
- (modify-syntax-entry ?\( "() " st)
- (modify-syntax-entry ?\) ")( " st)
-
- (modify-syntax-entry ?\
- (modify-syntax-entry ?\" "\" " st)
- (modify-syntax-entry ?' "' " st)
- (modify-syntax-entry ?` "' " st)
-
- (modify-syntax-entry ?, "' " st)
- (modify-syntax-entry ?@ "' " st)
- (modify-syntax-entry ?# "' 14" st)
- (modify-syntax-entry ?\\ "\\ " st)
- st))
- (defvar scheme-mode-abbrev-table nil)
- (define-abbrev-table 'scheme-mode-abbrev-table ())
- (defvar scheme-imenu-generic-expression
- `((nil
- ,(rx bol (zero-or-more space)
- "(define"
- (zero-or-one "*")
- (zero-or-one "-public")
- (one-or-more space)
- (zero-or-one "(")
- (group (one-or-more (or word (syntax symbol)))))
- 1)
- ("Methods"
- ,(rx bol (zero-or-more space)
- "(define-"
- (or "generic" "method" "accessor")
- (one-or-more space)
- (zero-or-one "(")
- (group (one-or-more (or word (syntax symbol)))))
- 1)
- ("Classes"
- ,(rx bol (zero-or-more space)
- "(define-class"
- (one-or-more space)
- (zero-or-one "(")
- (group (one-or-more (or word (syntax symbol)))))
- 1)
- ("Records"
- ,(rx bol (zero-or-more space)
- "(define-record-type"
- (zero-or-one "*")
- (one-or-more space)
- (group (one-or-more (or word (syntax symbol)))))
- 1)
- ("Conditions"
- ,(rx bol (zero-or-more space)
- "(define-condition-type"
- (one-or-more space)
- (group (one-or-more (or word (syntax symbol)))))
- 1)
- ("Modules"
- ,(rx bol (zero-or-more space)
- "(define-module"
- (one-or-more space)
- (group "(" (one-or-more any) ")"))
- 1)
- ("Macros"
- ,(rx bol (zero-or-more space) "("
- (or (and "defmacro"
- (zero-or-one "*")
- (zero-or-one "-public"))
- "define-macro" "define-syntax" "define-syntax-rule")
- (one-or-more space)
- (zero-or-one "(")
- (group (one-or-more (or word (syntax symbol)))))
- 1))
- "Imenu generic expression for Scheme mode. See `imenu-generic-expression'.")
- (defun scheme-mode-variables ()
- (set-syntax-table scheme-mode-syntax-table)
- (setq local-abbrev-table scheme-mode-abbrev-table)
- (setq-local paragraph-start (concat "$\\|" page-delimiter))
- (setq-local paragraph-separate paragraph-start)
- (setq-local paragraph-ignore-fill-prefix t)
- (setq-local fill-paragraph-function 'lisp-fill-paragraph)
-
-
-
- (setq-local adaptive-fill-mode nil)
- (setq-local indent-line-function 'lisp-indent-line)
- (setq-local parse-sexp-ignore-comments t)
- (setq-local outline-regexp ";;; \\|(....")
- (setq-local add-log-current-defun-function #'lisp-current-defun-name)
- (setq-local comment-start ";")
- (setq-local comment-add 1)
- (setq-local comment-start-skip ";+[ \t]*")
- (setq-local comment-use-syntax t)
- (setq-local comment-column 40)
- (setq-local lisp-indent-function 'scheme-indent-function)
- (setq mode-line-process '("" scheme-mode-line-process))
- (setq-local imenu-case-fold-search t)
- (setq-local imenu-generic-expression scheme-imenu-generic-expression)
- (setq-local imenu-syntax-alist '(("+-*/.<>=?!$%_&~^:" . "w")))
- (setq-local syntax-propertize-function #'scheme-syntax-propertize)
- (setq font-lock-defaults
- '((scheme-font-lock-keywords
- scheme-font-lock-keywords-1 scheme-font-lock-keywords-2)
- nil t (("+-*/.<>=!?$%_&~^:" . "w") (?#. "w 14"))
- beginning-of-defun
- (font-lock-mark-block-function . mark-defun)))
- (setq-local prettify-symbols-alist lisp-prettify-symbols-alist)
- (setq-local lisp-doc-string-elt-property 'scheme-doc-string-elt))
- (defvar scheme-mode-line-process "")
- (defvar scheme-mode-map
- (let ((map (make-sparse-keymap)))
- (set-keymap-parent map lisp-mode-shared-map)
- map)
- "Keymap for Scheme mode.
- All commands in `lisp-mode-shared-map' are inherited by this map.")
- (easy-menu-define scheme-mode-menu scheme-mode-map
- "Menu for Scheme mode."
- '("Scheme"
- ["Indent Line" lisp-indent-line]
- ["Indent Region" indent-region
- :enable mark-active]
- ["Comment Out Region" comment-region
- :enable mark-active]
- ["Uncomment Out Region" (lambda (beg end)
- (interactive "r")
- (-region beg end '(4)))
- :enable mark-active]
- ["Run Inferior Scheme" run-scheme]))
- (defun scheme-mode-commands (map)
-
- (define-key map "\177" 'backward-delete-char-untabify)
- (define-key map "\e\C-q" 'indent-sexp))
- (define-derived-mode scheme-mode prog-mode "Scheme"
- "Major mode for editing Scheme code.
- Editing commands are similar to those of `lisp-mode'.
- In addition, if an inferior Scheme process is running, some additional
- commands will be defined, for evaluating expressions and controlling
- the interpreter, and the state of the process will be displayed in the
- mode line of all Scheme buffers. The names of commands that interact
- with the Scheme process start with \"xscheme-\" if you use the MIT
- Scheme-specific `xscheme' package; for more information see the
- documentation for `xscheme-interaction-mode'. Use \\[run-scheme] to
- start an inferior Scheme using the more general `cmuscheme' package.
- Commands:
- Delete converts tabs to spaces as it moves back.
- Blank lines separate paragraphs. Semicolons start comments.
- \\{scheme-mode-map}"
- (scheme-mode-variables))
- (defgroup scheme nil
- "Editing Scheme code."
- :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
- :group 'lisp)
- (defcustom scheme-mit-dialect t
- "If non-nil, scheme mode is specialized for MIT Scheme.
- Set this to nil if you normally use another dialect."
- :type 'boolean)
- (defcustom dsssl-sgml-declaration
- "<!DOCTYPE style-sheet PUBLIC \"-//James Clark//DTD DSSSL Style Sheet//EN\">
- "
- "An SGML declaration for the DSSSL file.
- If it is defined as a string this will be inserted into an empty buffer
- which is in `dsssl-mode'. It is typically James Clark's style-sheet
- doctype, as required for Jade."
- :type '(choice (string :tag "Specified string")
- (const :tag "None" :value nil)))
- (defcustom scheme-mode-hook nil
- "Normal hook run when entering `scheme-mode'.
- See `run-hooks'."
- :type 'hook)
- (defcustom dsssl-mode-hook nil
- "Normal hook run when entering `dsssl-mode'.
- See `run-hooks'."
- :type 'hook)
- (defcustom scheme-program-name "scheme"
- "Program invoked by the `run-scheme' command."
- :type 'string)
- (defvar dsssl-imenu-generic-expression
-
-
-
-
- '(("Defines"
- "^(define\\s-+(?\\(\\sw+\\)" 1)
- ("Modes"
- "^\\s-*(mode\\s-+\\(\\(\\sw\\|\\s-\\)+\\)" 1)
- ("Elements"
-
-
- "^\\s-*(element\\s-+(?\\(\\(\\sw\\|\\s-\\)+\\))?" 1)
- ("Declarations"
- "^(declare\\(-\\sw+\\)+\\>\\s-+\\(\\sw+\\)" 2))
- "Imenu generic expression for DSSSL mode. See `imenu-generic-expression'.")
- (defconst scheme-font-lock-keywords-1
- (eval-when-compile
- (list
-
-
-
- (list (concat "(\\(define\\*?\\("
-
- "\\(\\|-public\\|-method\\|-generic\\(-procedure\\)?\\)\\|"
-
- "\\(-syntax\\|-macro\\)\\|"
-
- "-class"
-
- "\\|-module"
- "\\)\\)\\>"
-
-
-
- "[ \t]*(*"
- "\\(\\sw+\\)?")
- '(1 font-lock-keyword-face)
- '(6 (cond ((match-beginning 3) font-lock-function-name-face)
- ((match-beginning 5) font-lock-variable-name-face)
- (t font-lock-type-face))
- nil t))
- ))
- "Subdued expressions to highlight in Scheme modes.")
- (defconst scheme-font-lock-keywords-2
- (append scheme-font-lock-keywords-1
- (eval-when-compile
- (list
-
-
- (cons
- (concat
- "(" (regexp-opt
- '("begin" "call-with-current-continuation" "call/cc"
- "call-with-input-file" "call-with-output-file"
- "call-with-port"
- "case" "cond"
- "do" "else" "for-each" "if" "lambda" "λ"
- "let" "let*" "let-syntax" "letrec" "letrec-syntax"
-
- "export" "import"
-
- "let-values" "let*-values"
-
- "and" "or" "delay" "force"
-
-
- "map" "syntax" "syntax-rules"
-
- "when" "unless" "letrec*" "include" "include-ci" "cond-expand"
- "delay-force" "parameterize" "guard" "case-lambda"
- "syntax-error" "only" "except" "prefix" "rename" "define-values"
- "define-record-type" "define-library"
- "include-library-declarations"
-
- "receive"
- ) t)
- "\\>") 1)
-
-
- '("(let\\s-+\\(\\sw+\\)"
- (1 font-lock-function-name-face))
-
-
- '("\\<<\\sw+>\\>" . font-lock-type-face)
-
-
- '("\\<#?:\\sw+\\>" . font-lock-builtin-face)
-
- '("(\\(\\<library\\>\\)\\s-*(?\\(\\sw+\\)?"
- (1 font-lock-keyword-face)
- (2 font-lock-type-face))
- )))
- "Gaudy expressions to highlight in Scheme modes.")
- (defvar scheme-font-lock-keywords scheme-font-lock-keywords-1
- "Default expressions to highlight in Scheme modes.")
- (defconst scheme-sexp-comment-syntax-table
- (let ((st (make-syntax-table scheme-mode-syntax-table)))
- (modify-syntax-entry ?\
- (modify-syntax-entry ?\n " " st)
- (modify-syntax-entry ?# "'" st)
- st))
- (put 'lambda 'scheme-doc-string-elt 2)
- (put 'lambda* 'scheme-doc-string-elt 2)
- (put 'define 'scheme-doc-string-elt
- (lambda ()
-
- (forward-comment (point-max))
- (if (eq (char-after) ?\() 2 0)))
- (put 'define* 'scheme-doc-string-elt 2)
- (put 'case-lambda 'scheme-doc-string-elt 1)
- (put 'case-lambda* 'scheme-doc-string-elt 1)
- (put 'define-syntax-rule 'scheme-doc-string-elt 2)
- (put 'syntax-rules 'scheme-doc-string-elt 2)
- (defun scheme-syntax-propertize (beg end)
- (goto-char beg)
- (scheme-syntax-propertize-sexp-comment (point) end)
- (funcall
- (syntax-propertize-rules
- ("\\(#\\);" (1 (prog1 "< cn"
- (scheme-syntax-propertize-sexp-comment (point) end)))))
- (point) end))
- (defun scheme-syntax-propertize-sexp-comment (_ end)
- (let ((state (syntax-ppss)))
- (when (eq 2 (nth 7 state))
-
- (condition-case nil
- (progn
- (goto-char (+ 2 (nth 8 state)))
-
-
- (forward-sexp 1)
- (put-text-property (1- (point)) (point)
- 'syntax-table (string-to-syntax "> cn")))
- (scan-error (goto-char end))))))
- (define-derived-mode dsssl-mode scheme-mode "DSSSL"
- "Major mode for editing DSSSL code.
- Editing commands are similar to those of `lisp-mode'.
- Commands:
- Delete converts tabs to spaces as it moves back.
- Blank lines separate paragraphs. Semicolons start comments.
- \\{scheme-mode-map}
- Entering this mode runs the hooks `scheme-mode-hook' and then
- `dsssl-mode-hook' and inserts the value of `dsssl-sgml-declaration' if
- that variable's value is a string."
- (setq-local page-delimiter "^;;;")
-
-
- (and (zerop (buffer-size))
- (stringp dsssl-sgml-declaration)
- (not buffer-read-only)
- (insert dsssl-sgml-declaration))
- (setq font-lock-defaults '(dsssl-font-lock-keywords
- nil t (("+-*/.<>=?$%_&~^:" . "w"))
- beginning-of-defun
- (font-lock-mark-block-function . mark-defun)))
- (setq-local add-log-current-defun-function #'lisp-current-defun-name)
- (setq-local imenu-case-fold-search nil)
- (setq imenu-generic-expression dsssl-imenu-generic-expression)
- (setq-local imenu-syntax-alist '(("+-*/.<>=?$%_&~^:" . "w"))))
- (put 'element 'scheme-indent-function 1)
- (put 'mode 'scheme-indent-function 1)
- (put 'with-mode 'scheme-indent-function 1)
- (put 'make 'scheme-indent-function 1)
- (put 'style 'scheme-indent-function 1)
- (put 'root 'scheme-indent-function 1)
- (put 'λ 'scheme-indent-function 1)
- (defvar dsssl-font-lock-keywords
- (eval-when-compile
- (list
-
- (list "(\\(define\\(-\\w+\\)?\\)\\>[ \t]*\\((?\\)\\(\\sw+\\)\\>"
- '(1 font-lock-keyword-face)
- '(4 font-lock-function-name-face))
- (cons
- (concat "(" (regexp-opt
- '("case" "cond" "else" "if" "lambda"
- "let" "let*" "letrec" "and" "or" "map" "with-mode")
- 'words))
- 1)
-
- '("(\\(element\\|mode\\|declare-\\w+\\)\\>[ \t]*\\(\\sw+\\)"
- (1 font-lock-keyword-face)
- (2 font-lock-type-face))
- '("(\\(element\\)\\>[ \t]*(\\(\\S)+\\))"
- (1 font-lock-keyword-face)
- (2 font-lock-type-face))
- '("\\<\\sw+:\\>" . font-lock-constant-face)
-
- '("<\\([!?][-a-z0-9]+\\)" 1 font-lock-keyword-face)
- '("<\\(/?[-a-z0-9]+\\)" 1 font-lock-function-name-face)))
- "Default expressions to highlight in DSSSL mode.")
- (defvar calculate-lisp-indent-last-sexp)
- (defun scheme-indent-function (indent-point state)
- "Scheme mode function for the value of the variable `lisp-indent-function'.
- This behaves like the function `lisp-indent-function', except that:
- i) it checks for a non-nil value of the property `scheme-indent-function'
- \(or the deprecated `scheme-indent-hook'), rather than `lisp-indent-function'.
- ii) if that property specifies a function, it is called with three
- arguments (not two), the third argument being the default (i.e., current)
- indentation."
- (let ((normal-indent (current-column)))
- (goto-char (1+ (elt state 1)))
- (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
- (if (and (elt state 2)
- (not (looking-at "\\sw\\|\\s_")))
-
- (progn
- (if (not (> (save-excursion (forward-line 1) (point))
- calculate-lisp-indent-last-sexp))
- (progn (goto-char calculate-lisp-indent-last-sexp)
- (beginning-of-line)
- (parse-partial-sexp (point)
- calculate-lisp-indent-last-sexp 0 t)))
-
-
-
-
- (backward-prefix-chars)
- (current-column))
- (let ((function (buffer-substring (point)
- (progn (forward-sexp 1) (point))))
- method)
- (setq method (or (get (intern-soft function) 'scheme-indent-function)
- (get (intern-soft function) 'scheme-indent-hook)))
- (cond ((or (eq method 'defun)
- (and (null method)
- (> (length function) 3)
- (string-match "\\`def" function)))
- (lisp-indent-defform state indent-point))
- ((and (null method)
- (> (length function) 1)
-
- (string-match "\\`:" function))
- (let ((lisp-body-indent 1))
- (lisp-indent-defform state indent-point)))
- ((integerp method)
- (lisp-indent-specform method state
- indent-point normal-indent))
- (method
- (funcall method state indent-point normal-indent)))))))
- (defun scheme-let-indent (state indent-point normal-indent)
- (skip-chars-forward " \t")
- (if (looking-at "[-a-zA-Z0-9+*/?!@$%^&_:~]")
- (lisp-indent-specform 2 state indent-point normal-indent)
- (lisp-indent-specform 1 state indent-point normal-indent)))
- (put 'begin 'scheme-indent-function 0)
- (put 'case 'scheme-indent-function 1)
- (put 'delay 'scheme-indent-function 0)
- (put 'do 'scheme-indent-function 2)
- (put 'lambda 'scheme-indent-function 1)
- (put 'let 'scheme-indent-function 'scheme-let-indent)
- (put 'let* 'scheme-indent-function 1)
- (put 'letrec 'scheme-indent-function 1)
- (put 'let-values 'scheme-indent-function 1)
- (put 'let*-values 'scheme-indent-function 1)
- (put 'and-let* 'scheme-indent-function 1)
- (put 'sequence 'scheme-indent-function 0)
- (put 'let-syntax 'scheme-indent-function 1)
- (put 'letrec-syntax 'scheme-indent-function 1)
- (put 'syntax-rules 'scheme-indent-function 'defun)
- (put 'syntax-case 'scheme-indent-function 2)
- (put 'with-syntax 'scheme-indent-function 1)
- (put 'library 'scheme-indent-function 1)
- (put 'eval-when 'scheme-indent-function 1)
- (put 'call-with-input-file 'scheme-indent-function 1)
- (put 'call-with-port 'scheme-indent-function 1)
- (put 'with-input-from-file 'scheme-indent-function 1)
- (put 'with-input-from-port 'scheme-indent-function 1)
- (put 'call-with-output-file 'scheme-indent-function 1)
- (put 'with-output-to-file 'scheme-indent-function 1)
- (put 'with-output-to-port 'scheme-indent-function 1)
- (put 'call-with-values 'scheme-indent-function 1)
- (put 'dynamic-wind 'scheme-indent-function 3)
- (put 'when 'scheme-indent-function 1)
- (put 'unless 'scheme-indent-function 1)
- (put 'letrec* 'scheme-indent-function 1)
- (put 'parameterize 'scheme-indent-function 1)
- (put 'define-values 'scheme-indent-function 1)
- (put 'define-record-type 'scheme-indent-function 1)
- (put 'define-library 'scheme-indent-function 1)
- (put 'receive 'scheme-indent-function 2)
- (put 'match 'scheme-indent-function 1)
- (put 'match-lambda 'scheme-indent-function 0)
- (put 'match-lambda* 'scheme-indent-function 0)
- (put 'match-let 'scheme-indent-function 'scheme-let-indent)
- (put 'match-let* 'scheme-indent-function 1)
- (put 'match-letrec 'scheme-indent-function 1)
- (if scheme-mit-dialect
- (progn
- (put 'fluid-let 'scheme-indent-function 1)
- (put 'in-package 'scheme-indent-function 1)
- (put 'local-declare 'scheme-indent-function 1)
- (put 'macro 'scheme-indent-function 1)
- (put 'make-environment 'scheme-indent-function 0)
- (put 'named-lambda 'scheme-indent-function 1)
- (put 'using-syntax 'scheme-indent-function 1)
- (put 'with-input-from-string 'scheme-indent-function 1)
- (put 'with-output-to-string 'scheme-indent-function 0)
- (put 'with-values 'scheme-indent-function 1)
- (put 'syntax-table-define 'scheme-indent-function 2)
- (put 'list-transform-positive 'scheme-indent-function 1)
- (put 'list-transform-negative 'scheme-indent-function 1)
- (put 'list-search-positive 'scheme-indent-function 1)
- (put 'list-search-negative 'scheme-indent-function 1)
- (put 'access-components 'scheme-indent-function 1)
- (put 'assignment-components 'scheme-indent-function 1)
- (put 'combination-components 'scheme-indent-function 1)
- (put 'comment-components 'scheme-indent-function 1)
- (put 'conditional-components 'scheme-indent-function 1)
- (put 'disjunction-components 'scheme-indent-function 1)
- (put 'declaration-components 'scheme-indent-function 1)
- (put 'definition-components 'scheme-indent-function 1)
- (put 'delay-components 'scheme-indent-function 1)
- (put 'in-package-components 'scheme-indent-function 1)
- (put 'lambda-components 'scheme-indent-function 1)
- (put 'lambda-components* 'scheme-indent-function 1)
- (put 'lambda-components** 'scheme-indent-function 1)
- (put 'open-block-components 'scheme-indent-function 1)
- (put 'pathname-components 'scheme-indent-function 1)
- (put 'procedure-components 'scheme-indent-function 1)
- (put 'sequence-components 'scheme-indent-function 1)
- (put 'unassigned\?-components 'scheme-indent-function 1)
- (put 'unbound\?-components 'scheme-indent-function 1)
- (put 'variable-components 'scheme-indent-function 1)))
- (add-to-list 'auto-mode-alist '("\\.\\(scm\\|sls\\|sld\\|stk\\|ss\\|sch\\)\\'" . scheme-mode))
- (provide 'scheme)
|