;;; yorick-mode.el --- major mode for editing Yorick code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Copyright (C) 1999 Eric THIEBAUT. ;; ;; Warranty: ;; This package is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2 of the ;; License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; To get a copy of the GNU General Public License, write to the Free ;; Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Authors: 1999 Eric THIEBAUT. ;; Maintainer: thiebaut@obs.univ-lyon1.fr ;; Created: adapted from C variants (Java, C++) implemented over cc-mode ;; Keywords: yorick languages cc-mode ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; History: ;; $Log: yorick-mode.el,v $ ;; Revision 1.1 1999/12/09 11:26:01 eric ;; Initial revision ;; ;; $Id: yorick-mode.el,v 1.1 1999/12/09 11:26:01 eric Exp $ ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; This package provides GNU Emacs major mode for editing Yorick code. ;; C mode (cc-mode) in Emacs is designed to implement support for other ;; C-like languages (this is how Java, C++, Objective-C modes are ;; implemented). It was therefore very easy to create a Yorick mode ;; that account for the differences between Yorick's syntax and that of ;; C/C++. ;; ;; This mode will help you to write code for Yorick: auto-indent, ;; construction checking, and syntax highlighting (if you use ;; font-lock). ;; ;; ;; INSTALLATION ;; ============ ;; ;; 1. Copy file "yorick-mode.el" in one of the standard directories ;; where Emacs looks for elisp files (see Emacs's variable ;; "load-path" for a list of these paths, e.g., ;; "/usr/local/share/emacs/site-lisp"). ;; ;; 2. Optionally byte-compile "yorick-mode.el" (see Emacs's doc). ;; ;; 3. Insert the following lines in your "~/.emacs" or public ;; "default.el": ;; ;; (setq auto-mode-alist (append '(("\\.i$" . yorick-mode)) ;; auto-mode-alist)) ;; (autoload 'yorick-mode ;; "yorick-mode" "*Editing mode for Yorick *.i files." t) ;; ;; 4. You can also add a hook for Yorick mode (the hook variable ;; `yorick-mode-hook' is run with no args, if that variable is bound ;; and has a non-nil value. Also the hook `c-mode-common-hook' is ;; run first.) ;; ;; (add-hook 'yorick-mode-hook (function (lambda () ...))) ;; ;; ;; YORICK CONSTRUCTS THAT GET HIGHLIGHTED ;; ====================================== ;; * keywords: `break', `continue', `do', `else', `for', `func', ;; `goto', `if', `return', `while' (font-lock-keyword-face). ;; * symbol scope: `extern', `local' (font-lock-type-face). ;; * types: `char', `short', `int', `long', `float', `double', `complex', ;; `string', `pointer' (font-lock-type-face). ;; * definition: `struct' (font-lock--keyword-face and font-lock-type-face). ;; * range functions: `avg', `cum', `dif', `max', `min', `mnx', `mxx', ;; `pcen', `psum', `ptp', `rms', `sum', `uncp', `zcen' ;; (font-lock-builtin-face). ;; * reserved: `more_args', `next_arg' (font-lock-builtin-face). ;; * built-in (special): `require', `include', `error', `catch', ;; `am_subroutine' (font-lock-builtin-face). ;; * directives: #include, #if, #endif (font-lock-builtin-face and ;; font-lock-string-face). ;; * function definition: ;; func SYMBOL function with no args ;; func SYMBOL(ARG1 [, ...]) function with args ;; * special: "DOCUMENT" "FIXME:" "SEE ALSO" (font-lock-warning-face). ;; (require 'cc-mode) (require 'cc-defs) ;; NOTE: ;; In `cc-langs.el' the constant `c-symbol-key' is defined as REGEX that ;; matches any `symbol' in all C-like languages. The definition is: ;; ;; (defconst c-symbol-key "[_a-zA-Z]\\(\\w\\|\\s_\\)*") ;; ;; and (I guess that) the following `*-key' definitions are matched against ;; a symbol which already matches `c-symbol-key'. ;; keywords introducing class definitions. language specific (defconst c-Yorick-class-key "\\(struct\\)") (defconst c-Yorick-extra-toplevel-key "\\(extern\\|local\\)[^_]") ;; regexp describing access protection clauses. language specific (defconst c-Yorick-access-key nil) ;; keywords introducing conditional blocks (defconst c-Yorick-conditional-key "\\b\\(for\\|if\\|do\\|else\\|while\\)\\b[^_]") ;; comment starter definitions for various languages. language specific (defconst c-Yorick-comment-start-regexp "/[/*]") ;; menu support for both XEmacs and Emacs. If you don't have easymenu ;; with your version of Emacs, you are incompatible! (require 'easymenu) (defvar c-yorick-menu nil) ;; Support for Yorick. (defvar yorick-mode-abbrev-table nil "Abbreviation table used in yorick-mode buffers.") (define-abbrev-table 'yorick-mode-abbrev-table ()) (defvar yorick-mode-map () "Keymap used in yorick-mode buffers.") (if yorick-mode-map nil (setq yorick-mode-map (c-make-inherited-keymap)) ;; add bindings which are only useful for Yorick ) (defvar yorick-mode-syntax-table nil "Syntax table used in yorick-mode buffers.") (if yorick-mode-syntax-table () (setq yorick-mode-syntax-table (make-syntax-table)) (c-populate-syntax-table yorick-mode-syntax-table)) (easy-menu-define c-yorick-menu yorick-mode-map "Yorick Mode Commands" (c-mode-menu "Yorick")) (defvar cc-imenu-yorick-generic-expression cc-imenu-c-generic-expression "Imenu generic expression for Yorick mode. See `imenu-generic-expression'.") ;; Yorick definitions for font-lock: (defvar yorick-font-lock-keywords '( ;; ;; Fontify function name definitions. ("\\<\\(func\\)[ \t]+\\([_A-Za-z][_A-Za-z0-9]*\\)?" (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)) ;; ;; Fontify function structure definitions. ("\\<\\(struct\\)[ \t]+\\(\\([_A-Za-z][_A-Za-z0-9]*\\)[ \t]*{\\)?" (1 font-lock-keyword-face) (3 font-lock-type-face nil t)) ;; ;; Fontify warning directives. ("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend) ("\\<\\(DOCUMENT\\|SEE[ \t]+ALSO\\|KEYWORDS\\)\\>" 1 font-lock-warning-face prepend) ;; ;; Fontify #KEYWORD directives (Note: unlike C preprocessor, Yorick does ;; not care of spaces before/after the `#'): ;; 1. fontify filenames in #include <...> directives as strings. ("^[ \t]*\\(#[ \t]*include\\)[ \t]*\\(<[^>\"\n]*>\\)" (1 font-lock-builtin-face nil t) (2 font-lock-string-face nil t)) ;; 2. fontify directives. ("^[ \t]*\\(#[ \t]*\\(if\\|include\\|endif\\)\\)\\>" 1 font-lock-builtin-face) ;; ;; Fontify some common Yorick's functions (only `more_args' and `next_arg' ;; are reserved words in Yorick): ("\\<\\(am_subroutine\\|catch\\|error\\|include\\|more_args\\|next_arg\\|require\\)\\>" 1 font-lock-builtin-face) ;; ;; Fontify goto keywords and targets, and case default/goto tags. ("\\<\\(goto\\)\\>[ \t]*\\(-?\\sw+\\)?" (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) ;; Anders Lindgren points out that it is quicker to use ;; MATCH-ANCHORED to effectively anchor the regexp on the left. ;; This must come after the one for keywords and targets. (":" ("^[ \t]*\\(\\sw+\\)[ \t]*:" (beginning-of-line) (end-of-line) (1 font-lock-constant-face))) ;; ;; Fontify Yorick's types/scope specifiers. ("\\<\\(c\\(har\\|omplex\\)\\|double\\|extern\\|float\\|int\\|lo\\(cal\\|ng\\)\\|pointer\\|s\\(hort\\|tring\\)\\)\\>" 1 font-lock-type-face) ;; ;; Fontify Yorick's keywords (`goto' and `func' are handled elsewhere): ("\\<\\(break\\|continue\\|do\\|else\\|for\\|if\\|return\\|while\\)\\>" 1 font-lock-keyword-face) ;; Fontify Yorick's Yorick's range functions: ("\\<\\(avg\\|cum\\|dif\\|m\\(ax\\|in\\|nx\\|xx\\)\\|p\\(cen\\|sum\\|tp\\)\\|rms\\|sum\\|uncp\\|zcen\\)\\>" 1 font-lock-builtin-face) ) "Default expressions to highlight in Yorick mode.") ;; (KEYWORDS KEYWORDS-ONLY CASE-FOLD SYNTAX-ALIST SYNTAX-BEGIN ...) (defvar yorick-font-lock-defaults '((yorick-font-lock-keywords) nil nil ((?_ . "w")) beginning-of-defun ;; Obsoleted by Emacs 20 parse-partial-sexp's COMMENTSTOP. ;;(font-lock-comment-start-regexp . "/[*/]") (font-lock-mark-block-function . mark-defun))) (defun yorick-mode () "Major mode for editing Yorick code (by thiebaut@obs.univ-lyon1.fr). The hook variable `yorick-mode-hook' is run with no args, if that variable is bound and has a non-nil value. Also the hook `c-mode-common-hook' is run first. Key bindings: \\{yorick-mode-map}" (interactive) (c-initialize-cc-mode) (kill-all-local-variables) (set-syntax-table yorick-mode-syntax-table) (setq major-mode 'yorick-mode mode-name "Yorick" local-abbrev-table yorick-mode-abbrev-table) (use-local-map yorick-mode-map) (c-common-init) (make-local-variable 'font-lock-defaults) (setq comment-start "// " comment-end "" c-comment-start-regexp c-Yorick-comment-start-regexp c-conditional-key c-Yorick-conditional-key c-class-key c-Yorick-class-key c-access-key c-Yorick-access-key c-recognize-knr-p nil imenu-generic-expression cc-imenu-yorick-generic-expression imenu-case-fold-search nil font-lock-defaults yorick-font-lock-defaults) (run-hooks 'c-mode-common-hook) (run-hooks 'yorick-mode-hook) (c-update-modeline)) (provide 'yorick-mode) ;;; yorick-mode.el ends here