;;; ggo-mode.el --- Gengetopt major mode ;; Copyright (C) 2002 Matthew K. Junker ;; Author: Matthew K. Junker(remove the ;; animals around the @) ;; Keywords: extensions, convenience, local ;; $Id: ggo-mode.el,v 1.1 2002-07-13 04:45:10-05 junker Exp $ ;; This file 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 file 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: ;; A major mode for editing gengetopt files. ;; Modify `ggo-skeleton' to suit your format. The current contents ;; are based on proposals I have made. ;; initialization suggestions: ;; (add-to-list 'auto-mode-alist '("\\.ggo\\'" . ggo-mode)) ;; (autoload 'ggo-mode "ggo-mode" "gengetopt files" t) ;; (add-to-list 'auto-insert-alist '(ggo-mode . ggo-skeleton)) ;; Written for Emacs version 21. May or may not work with previous ;; versions. ;;; History: ;; ;;; Code: (defgroup ggo-mode nil "Major mode for editing and processing gengetopt files." :group 'local) (defcustom ggo-types '("" "string" "int" "short" "long" "float" "double" "longdouble" "longlong" "flag") "*Types of gengetopt options." :type '(repeat string)) (define-skeleton ggo-insert-option-skeleton "Insert a gengetopt option." "Long name: " "option \"" str "\"" (let ((short (substring str 0 1))) (skeleton-insert '("Short name: " '(setq input short) " " str | "-"))) (skeleton-insert '("Description: " " \"" str "\"")) (let ((type (completing-read "Enter the type: " (mapcar '(lambda (a) (list a a)) ggo-types) nil t))) (unless (string= type "") (insert " " type)) (cond ((string= type "flag") (insert " " (completing-read "Initial flag status: " (list (list "on" "on") (list "off" "off")) nil t "on"))) ((string= type "") (insert " no")) (t (let ((default (read-from-minibuffer "Default value: "))) (if (string= default "") nil (insert " default=\"" default "\""))) (if (y-or-n-p "Required?: ") (insert " yes") (insert " no")))))) (defvar ggo-mode-map (let ((map (make-sparse-keymap))) ;; reverse order of desired binding list (define-key map "\C-c\C-t" 'ggo-insert-text) (define-key map "\C-c\C-s" 'ggo-skeleton) (define-key map "\C-c\C-o" 'ggo-insert-option-skeleton) (define-key map "\C-c\C-h" 'ggo-insert-heading) map) "Keymap for ggo mode.") (defcustom ggo-mode-comment-start "#" "*Comment string to use in ggo mode." :type 'string :group 'ggo-mode) (defvar ggo-mode-syntax-table nil "Syntax table used while in ggo mode.") (if ggo-mode-syntax-table () (setq ggo-mode-syntax-table (make-syntax-table)) (modify-syntax-entry ?# "<" ggo-mode-syntax-table) (modify-syntax-entry ?\n ">" ggo-mode-syntax-table)) (defvar ggo-font-lock-keywords (list '("^#:.*" 0 'font-lock-variable-name-face t) '("^#text.*" 0 'font-lock-variable-name-face t) '("#:\\\\\\\".*" 0 'font-lock-comment-face t) '("package" . 'font-lock-function-name-face) '("version" . 'font-lock-function-name-face) '("purpose" . 'font-lock-function-name-face) '("option" . 'font-lock-function-name-face) '("string" . 'font-lock-type-face) '("int" . 'font-lock-type-face) '("short" . 'font-lock-type-face) '("long" . 'font-lock-type-face) '("float" . 'font-lock-type-face) '("double" . 'font-lock-type-face) '("longdouble" . 'font-lock-type-face) '("longlong" . 'font-lock-type-face) '("flag" . 'font-lock-type-face) '("yes" . 'font-lock-keyword-face) '("default" . 'font-lock-keyword-face) '("no" . 'font-lock-keyword-face) '("on" . 'font-lock-keyword-face) '("off" . 'font-lock-keyword-face)) "Font-lock highlighting control in ggo mode.") (defun ggo-mode () "Major mode for editing gengetopt files. \\[ggo-skeleton] inserts the basic .ggo data. \\[ggo-insert-option] inserts an option and parameters at the point. \\[ggo-insert-heading] inserts an option heading for help and man pages at the point. \\[ggo-insert-text] inserts text for help and man pages at the point. \\{ggo-mode-map}" (interactive) (kill-all-local-variables) (setq major-mode 'ggo-mode mode-name "ggo" comment-start ggo-mode-comment-start comment-end "" ; blank = EOL comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)#+ *" parse-sexp-ignore-comments t) (set-syntax-table ggo-mode-syntax-table) (set (make-local-variable 'font-lock-defaults) '(ggo-font-lock-keywords nil t)) (use-local-map ggo-mode-map) (run-hooks 'ggo-mode-hook)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Skeletons ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-skeleton ggo-insert-heading "Insert ggo heading." "heading: " \n "#text \"" str "\"") (define-skeleton ggo-insert-text "Insert ggo text." "text: " \n "#text \"\\t\\t\\t" str "\"") (define-skeleton ggo-skeleton "Skeleton for Gengetopt files." "Package name: " "# gengetopt input file. See the manual entry for directions." \n "package \"" str "\"" \n "version \"1.0\"" \n "purpose \"" (skeleton-read "Purpose: " nil nil) "\"\n" _ \n "#:[EXAMPLES]\n" "#:[RETURN VALUES]\n" "##:This next request is for sections 1, 6, 7 and 8 only.\n" "#:[ENVIRONMENT]\n" "#:[FILES]\n" "##: This next request is for sections 1, 6, 7, 8 and 9 only\n" "##: (command return values (to shell) and\n" "##: fprintf/stderr type diagnostics).\n" "#:[DIAGNOSTICS]\n" "#:[COMPATIBILITY]\n" "##: This next request is for sections 2, 3 and 9 error\n" "##: and signal handling only.\n" "#:[ERRORS]\n" "#:[STANDARDS]\n" "#:[HISTORY]\n" "#:[AUTHOR]\n" "#:Written by " (user-full-name) " <" user-mail-address ">\n" "#:[REPORTING BUGS]\n" "#:Report bugs to <" user-mail-address ">\n" "#:[COPYRIGHT]\n" "#:Copyright \\(co " (format-time-string "%Y " (current-time) t) (getenv "ORGANIZATION") ".\n" "#:This is free software; see the source for copying conditions.\n" "#:There is NO warranty; not even for MERCHANTABILITY\n" "#:or FITNESS FOR A PARTICULAR PURPOSE.\n" "#:[SEE ALSO]\n") (provide 'ggo-mode) ;;; ggo-mode.el ends here