;;; umdeck.el --- UMARC input file editing mode for Emacs ;; Copyright (C) Jinwei Shen ;; Author: Jinwei Shen ;; Maintainer: shenjw@wam.umd.edu ;; Keywords: UMARC ;; Created: 1998-11-01 ;; This file is not part of GNU Emacs. ;; This program 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, 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. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; This code borrowed heavily from the awk-mode.el in emacs. ;; This code fontifies (highlights) the keywords and comments of UMARC ;; input file, but the keywords listed here is by no means ;; complete. You can also use M-C-a, M-C-e to move around data blocks. ;;; Installation: ;; Install umdeck.el somewhere in your lisp load path. Maybe add ;; lines in your ~/.emacs along the lines of: ; ;; (setq my-path (concat (getenv "HOME") "/local/share/emacs/site-lisp" ;; (setq load-path (cons my-path load-path)) ;; (autoload 'umdeck-mode "umdeck" "Enter umdeck mode." t) ; ;; when editing umarc input file, use M-x umdeck-mode to invoke this ;; mode. ;;; Code: (defvar umdeck-mode-syntax-table nil "Syntax table in use in umdeck-mode buffers.") (if umdeck-mode-syntax-table () (setq umdeck-mode-syntax-table (make-syntax-table)) (modify-syntax-entry ?\\ "\\" umdeck-mode-syntax-table) (modify-syntax-entry ?\n "> " umdeck-mode-syntax-table) (modify-syntax-entry ?\f "> " umdeck-mode-syntax-table) (modify-syntax-entry ?\* "< " umdeck-mode-syntax-table) (modify-syntax-entry ?/ "." umdeck-mode-syntax-table) ; (modify-syntax-entry ?* "." umdeck-mode-syntax-table) (modify-syntax-entry ?+ "." umdeck-mode-syntax-table) (modify-syntax-entry ?- "." umdeck-mode-syntax-table) (modify-syntax-entry ?= "." umdeck-mode-syntax-table) (modify-syntax-entry ?% "." umdeck-mode-syntax-table) (modify-syntax-entry ?< "." umdeck-mode-syntax-table) (modify-syntax-entry ?> "." umdeck-mode-syntax-table) (modify-syntax-entry ?& "." umdeck-mode-syntax-table) (modify-syntax-entry ?| "." umdeck-mode-syntax-table) (modify-syntax-entry ?_ "_" umdeck-mode-syntax-table) (modify-syntax-entry ?\' "\"" umdeck-mode-syntax-table)) ;; Regexps written with help from Peter Galbraith . (defconst umdeck-font-lock-keywords (eval-when-compile (list ;; ;; Variables names. (cons (concat "\\<\\(" "ref_mass\\|" "ref_rotor_speed\\|" "rotor_radius\\|" "rotor_type\\|" "rotor_name\\|" "no_blades\\|" "solidity\\|" "lock_no\\|" "ct/sigma\\|" "cg_below_hub\\|" "cg_hub_offset_x\\|" "cg_hub_offset_y\\|" "material_type\\|" "twist\\|" "precone\\|" "root_cut\\|" "no_space_elements\\|" "sweep_flag\\|" "sweep_angle\\|" "droop_angle\\|" "twist_angle\\|" "element_length\\|" "chord\\|" "eiy\\|" "eiz\\|" "gj\\|" "ea\\|" "eb1\\|" "eb2\\|" "ec1\\|" "ec2\\|" "offset_cg&ea\\|" "offset_ta&ea\\|" "offset_ac&ea\\|" "element_mass\\|" "sq_km1\\|" "sq_km2\\|" "no_hub_dof\\|" "body_seq\\|" "effective_x_mass\\|" "effective_y_mass\\|" "effective_z_mass\\|" "fuselage_pitch_inertia\\|" "fuselage_roll_inertia\\|" "fuselage_x_damper\\|" "fuselage_y_damper\\|" "fuselage_z_damper\\|" "fuselage_pitch_damper\\|" "fuselage_roll_damper\\|" "fuselage_x_spring\\|" "fuselage_y_spring\\|" "fuselage_z_spring\\|" "fuselage_pitch_spring\\|" "fuselage_roll_spring\\|" "body_roll_moment_coeff\\|" "body_pitch_moment_coeff\\|" "body_side_force_coeff\\|" "parasite_drag_area\\|" "solidity_tail_rot\\|" "gear_ratio_tail_rot\\|" "rad_ratio_tail_rot\\|" "twist(deg)_tail_rot\\|" "cg_tail_rot_offset_x\\|" "tail_rot_above_cg\\|" "c1_tail_rot\\|" "cg_tail_hor_offset_x\\|" "hor_tail_area\\|" "c1_tail_hor\\|" "c0_tail_hor\\|" "table_look_up\\|" "no_airfoils\\|" "airfoil_starting_locations\\|" "cl_table_names test\\|" "cd_table_names notab\\|" "cm_table_names notab\\|" "ref_lift_curve_slope\\|" "czero\\|" "c1\\|" "dzero\\|" "d1\\|" "d2\\|" "cmac\\|" "f1\\|" "le_recov_fact\\|" "advance_ratio\\|" "density_ratio\\|" "rotor_speed_ratio\\|" "tip_mach\\|" "flight_angle\\|" "drees_linear_inflow\\|" "b&w_linear_inflow\\|" "uniform_inflow\\|" "reverse_flow\\|" "wt_conv_crit\\|" "coupled_wt\\|" "nl_struct_aero\\|" "no_time_elements\\|" "nodes_per_time_elem\\|" "no_flap_modes\\|" "flap_mode_seq\\|" "flap_mode_damping\\|" "no_lag_modes\\|" "lag_mode_seq\\|" "lag_mode_damping\\|" "no_torsion_modes\\|" "torsion_mode_seq\\|" "torsion_mode_damping\\|" "no_axial_modes\\|" "axial_mode_seq\\|" "axial_mode_damping\\|" "conv_crit\\|" "first_flap_freq_per_rev\\|" "delta_controls\\|" "trim_conv_crit\\|" "resp_conv_crit\\|" "coupled_trim_scheme\\|" "no_max_iter\\|" "qs_aero_damp\\|" "alpha_s_wt\\|" "theta_0_wt\\|" "fix_qs_floq\\|" "no_psi_locations\\|" "dynamic_inflow\\|" "print_control\\|" "te_flap_chord\\|" "te_flap_m\\|" "te_flap_cg\\|" "te_flap_skm2\\|" "flap_harmonics\\|" "flap_effectiveness\\|" "coupled_rb\\|" "hub_load_control" "\\)\\>") 'font-lock-variable-name-face) ;; ;; Keywords. (concat "\\<\\(" "title\\|input_data\\|rotor_properties\\|" "blade_properties\\|fuselage_properties\\|tail_properties\\|" "airfoil_properties\\|flight_condition\\|aerodynamics\\|" "trim_analysis\\|stability_analysis\\|output_options" "\\)\\>") ;; ;; Operators. Is this too much? (cons (mapconcat 'identity '(" = " " : ") "\\|") 'font-lock-constant-face) )) "Default expressions to highlight in umdeck mode.") (defvar umdeck-mode-map () "Keymap used in umdeck mode.") (if umdeck-mode-map () (setq umdeck-mode-map (make-sparse-keymap)) (define-key umdeck-mode-map "\C-c;" 'comment-region) (define-key umdeck-mode-map "\M-\C-a" 'beginning-of-umdeck-datablock) (define-key umdeck-mode-map "\M-\C-e" 'end-of-umdeck-datablock) ) (defvar umdeck-end-datablock-re "^[ \t]*\\(\\(title\\|input_data\\|rotor_properties\\|blade_properties\\|fuselage_properties\\|tail_properties\\|airfoil_properties\\|flight_condition\\|aerodynamics\\|trim_analysis\\|stability_analysis\\|output_options\\)[ \t]*\\)") (defun beginning-of-umdeck-datablock () "Moves point to the beginning of the current data block." (interactive) (let ((case-fold-search t)) (beginning-of-line -1) (if (re-search-backward umdeck-end-datablock-re nil 'move) (forward-line)))) (defun end-of-umdeck-datablock () "Moves point to the end of the current data block." (interactive) (let ((case-fold-search t)) (if (save-excursion ; on END (beginning-of-line) (looking-at umdeck-end-datablock-re)) (forward-line) (beginning-of-line 2) (re-search-forward umdeck-end-datablock-re nil 'move) (goto-char (match-beginning 0)) (forward-line)))) ;;;###autoload (defun umdeck-mode () "Major mode for editing umdeck code. This is much like C mode except for the syntax of comments. It uses the same keymap as C mode and has the same variables for customizing indentation. It has its own abbrev table and its own syntax table. Turning on umdeck mode calls the value of the variable `umdeck-mode-hook' with no args, if that value is non-nil." (interactive) (kill-all-local-variables) ; (require 'cc-mode) ; (c-initialize-cc-mode) (use-local-map umdeck-mode-map) (setq major-mode 'umdeck-mode) (setq mode-name "umdeck") ; (setq local-abbrev-table umdeck-mode-abbrev-table) (set-syntax-table umdeck-mode-syntax-table) (make-local-variable 'paragraph-start) (setq paragraph-start (concat "$\\|" page-delimiter)) (make-local-variable 'paragraph-separate) (setq paragraph-separate paragraph-start) ; (make-local-variable 'paragraph-ignore-fill-prefix) ; (setq paragraph-ignore-fill-prefix t) ; (make-local-variable 'indent-line-function) ; (setq indent-line-function 'c-indent-line) ; (make-local-variable 'require-final-newline) ; (setq require-final-newline t) (make-local-variable 'comment-start) (setq comment-start "* ") (make-local-variable 'comment-end) (setq comment-end "") (make-local-variable 'comment-column) (setq comment-column 32) (make-local-variable 'comment-start-skip) (setq comment-start-skip "\*+ *") ; (make-local-variable 'comment-indent-function) ; (setq comment-indent-function 'c-comment-indent) ; (make-local-variable 'parse-sexp-ignore-comments) ; (setq parse-sexp-ignore-comments t) (make-local-variable 'font-lock-defaults) (setq font-lock-defaults '(umdeck-font-lock-keywords nil nil ((?_ . "w")))) (run-hooks 'umdeck-mode-hook)) (provide 'umdeck-mode) ;;; umdeck-mode.el ends here