editors

changeset 12:86c44acdeb0d

Created basic font-lock mode for Euphoria. Automatic-indentation is not yet supported.
author Jeremy Cowgar <jeremy@cowgar.com>
date Tue Oct 26 10:04:00 2010 +0000 (2010-10-26)
parents 6dd6e48ae896
children ca68b3aee940
files emacs/euphoria-mode.el
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emacs/euphoria-mode.el	Tue Oct 26 10:04:00 2010 +0000
     1.3 @@ -0,0 +1,101 @@
     1.4 +;;; euphoria-mode-el -- Major mode for editing Euphoria files
     1.5 +
     1.6 +;; Author: Jeremy Cowgar <jeremy@cowgar.com>
     1.7 +;; Created: 26 Oct 2010
     1.8 +;; Keywords: Euphoria major-mode
     1.9 +
    1.10 +;; Copyright (C) 2010 Jeremy Cowgar <jeremy@cowgar.com>
    1.11 +
    1.12 +;; This program is free software; you can redistribute it and/or
    1.13 +;; modify it under the terms of the GNU General Public License as
    1.14 +;; published by the Free Software Foundation; either version 2 of
    1.15 +;; the License, or (at your option) any later version.
    1.16 +
    1.17 +;; This program is distributed in the hope that it will be
    1.18 +;; useful, but WITHOUT ANY WARRANTY; without even the implied
    1.19 +;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    1.20 +;; PURPOSE.  See the GNU General Public License for more details.
    1.21 +
    1.22 +;; You should have received a copy of the GNU General Public
    1.23 +;; License along with this program; if not, write to the Free
    1.24 +;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
    1.25 +;; MA 02111-1307 USA
    1.26 +
    1.27 +;;; Commentary:
    1.28 +;;
    1.29 +;; This mode provides syntax highlighting for Euphoria source files
    1.30 +;;
    1.31 +;; Euphoria can be learned about at http://www.openeuphoria.org
    1.32 +
    1.33 +;;; Code:
    1.34 +(defvar euphoria-mode-hook nil)
    1.35 +(defvar euphoria-mode-map
    1.36 +  (let ((euphoria-mode-map (make-keymap)))
    1.37 +    (define-key euphoria-mode-map "\C-j" 'newline-and-indent)
    1.38 +    (define-key euphoria-mode-map "\C-c" 'comment-region)
    1.39 +    (define-key euphoria-mode-map "\C-\c" 'uncomment-region)
    1.40 +    euphoria-mode-map)
    1.41 +  "Keymap for Euphoria major mode")
    1.42 +
    1.43 +(add-to-list 'auto-mode-alist '("\\.e$" . euphoria-mode))
    1.44 +(add-to-list 'auto-mode-alist '("\\.ex$" . euphoria-mode))
    1.45 +(add-to-list 'auto-mode-alist '("\\.exw$" . euphoria-mode))
    1.46 +
    1.47 +;; Keywords:
    1.48 +;;
    1.49 +;; (regexp-opt '("as" "and" "break" "by" "case" "constant" "continue"
    1.50 +;;   "do" "end" "else" "elsif" "elsedef" "elsifdef" "exit" "entry" "enum"
    1.51 +;;   "export" "for" "function" "global" "goto" "include" "if" "ifdef"
    1.52 +;;   "label" "namespace" "not" "or" "procedure" "public" "return" "retry"
    1.53 +;;   "switch" "then" "type" "to" "while" "with" "without" "xor"))
    1.54 +;;
    1.55 +;; Types:
    1.56 +;;
    1.57 +;; (regexp-opt '("object" "sequence" "integer" "atom"))
    1.58 +;;
    1.59 +
    1.60 +(defconst euphoria-font-lock-keywords-1
    1.61 +  (list
    1.62 +   '("\\<[+-]?[0-9,_\\.]+\\>" . font-lock-constant-face)
    1.63 +   '("\\<[A-Z0-9][^ \t\n\r]*\\>" . font-lock-constant-face)
    1.64 +   '("\\<\\(atom\\|integer\\|object\\|sequence\\)\\>" . font-lock-type-face)
    1.65 +   '("\\<\\(a\\(?:nd\\|s\\)\\|b\\(?:reak\\|y\\)\\|c\\(?:ase\\|on\\(?:stant\\|tinue\\)\\)\\|do\\|e\\(?:ls\\(?:e\\(?:def\\)?\\|if\\(?:def\\)?\\)\\|n\\(?:d\\|try\\|um\\)\\|x\\(?:\\(?:i\\|por\\)t\\)\\)\\|f\\(?:or\\|unction\\)\\|g\\(?:lobal\\|oto\\)\\|i\\(?:f\\(?:def\\)?\\|nclude\\)\\|label\\|n\\(?:amespace\\|ot\\)\\|or\\|p\\(?:rocedure\\|ublic\\)\\|ret\\(?:ry\\|urn\\)\\|switch\\|t\\(?:hen\\|o\\|ype\\)\\|w\\(?:hile\\|ith\\(?:out\\)?\\)\\|xor\\)\\>" . font-lock-builtin-face)
    1.66 +   )
    1.67 +  "Minimal highlighting for Euphoria mode.")
    1.68 +
    1.69 +(defvar euphoria-font-lock-keywords euphoria-font-lock-keywords-1)
    1.70 +
    1.71 +(defvar euphoria-mode-syntax-table nil)
    1.72 +
    1.73 +(if (not euphoria-mode-syntax-table)
    1.74 +    (progn
    1.75 +      (setq euphoria-mode-syntax-table (make-syntax-table))
    1.76 +      ;; _ is part of a word
    1.77 +      (modify-syntax-entry ?_ "w" euphoria-mode-syntax-table)
    1.78 +
    1.79 +      ;; define `...` strings
    1.80 +      (modify-syntax-entry ?\` "\""   euphoria-mode-syntax-table)
    1.81 +
    1.82 +      ;; define “/* ... */”comment style
    1.83 +      (modify-syntax-entry ?\/ ". 14" euphoria-mode-syntax-table)
    1.84 +      (modify-syntax-entry ?* ". 23" euphoria-mode-syntax-table)
    1.85 +
    1.86 +      ;; define -- comment style
    1.87 +      (modify-syntax-entry ?\- ". 12b" euphoria-mode-syntax-table)
    1.88 +      (modify-syntax-entry ?\n "> b" euphoria-mode-syntax-table)
    1.89 +  ))
    1.90 +
    1.91 +(defun euphoria-mode ()
    1.92 +  (interactive)
    1.93 +  (kill-all-local-variables)
    1.94 +  (use-local-map euphoria-mode-map)
    1.95 +  (set-syntax-table euphoria-mode-syntax-table)
    1.96 +  (set (make-local-variable 'font-lock-defaults)
    1.97 +       '(euphoria-font-lock-keywords))
    1.98 +  (make-local-variable 'comment-start)
    1.99 +  (setq comment-start "-- ")
   1.100 +  (setq major-mode 'euphoria-mode)
   1.101 +  (setq mode-name "Euphoria")
   1.102 +  (run-hooks 'euphoria-mode-hook))
   1.103 +
   1.104 +(provide 'euphoria-mode)

SCM Home | OpenEuphoria.org Home