;;; pdx-mode.el --- mode for editing pdx code ;; Author: Harry G. George ;; Maintainer: Harry G. George ;; Keywords: tools, languages ;; This file is to be used with GNU Emacs. ;;;Commentary: ;; This mode was written by following the pattern in several of ;; the other modes, esp: asm, prolog, scheme, and tcl. ;; Somewhere in the .emacs process, assure this is handled: ;; ;; (load "/path-to-modes/pdx-mode") ;; (setq auto-mode-alist ;; (append ;; '(("\\.pdx\\'" . pdx-mode)) ;; auto-mode-alist)) ;;; Code: ;---group--- (defgroup pdx nil "Mode for editing pdx code." :group 'languages) ;---syntax--- (defvar pdx-mode-syntax-table nil "Syntax table used while in Pdx mode.") (if pdx-mode-syntax-table nil ;Do not change the table if it is already set up. (setq pdx-mode-syntax-table (make-syntax-table)) (modify-syntax-entry ?\\ "\\" pdx-mode-syntax-table) ) ;---abbrev--- (defvar pdx-mode-abbrev-table nil "Abbrev table used while in Pdx mode.") (define-abbrev-table 'pdx-mode-abbrev-table ()) ;---mode map--- (defvar pdx-mode-map nil "Keymap for Pdx mode.") (if pdx-mode-map nil (setq pdx-mode-map (make-sparse-keymap)) (define-key pdx-mode-map "\177" 'backward-delete-char-untabify) (define-key pdx-mode-map "\C-X\C-S" 'pdx-maybe-run-on-save) ) ;---font-lock--- (defconst pdx-font-lock-keywords (list ;; comments (list "^\\s-*\\(#.*\\)" '(1 font-lock-comment-face)) ;;"=" markers (list (concat "^\\s-*\\(=" (regexp-opt '("begin" "center" "cfg" "def" "end" "for" "head" "include" "include_verbatim" "include_for" "quote" "table" "row" "pathpush" "pathpop" "list" "item" "preamble_begin_for" "preamble_append_for" "preamble_end_for" "postamble_for" "verbatim") t) "\\)") '(1 font-lock-keyword-face)) ;; in-line markers (list (concat "\\<\\(" (regexp-opt '("B" "C" "E" "I" "L" "N" "T" "X") t) "<[^>]*>\\)") '(1 font-lock-variable-name-face)) )) ;---hooks--- (defun redefine-save-menu () (define-key menu-bar-files-menu [save-buffer] '("Save Buffer" . pdx-maybe-run-on-save))) ;---edit functions--- (defun pdx-newline () "Insert LFD + fill-prefix, to bring us back to code-indent level." (interactive) (if (eolp) (delete-horizontal-space)) (insert "\n") (tab-to-tab-stop) ) ;;;========================================================== ;;;Compiling the buffer... (defcustom pdx-run-on-save nil "run pdx program after a file is saved" :type 'boolean :group 'pdx) (defcustom pdx-program-name "pdx2html.py" "Program name for invoking an inferior process with `run-pdx'." :type 'string :group 'pdx) (defcustom pdx-program-options "" "Command line options for `run-pdx'. E.g., --notoc" :type 'string :group 'pdx) (defcustom pdx-eof-string nil "*String that represents end of file for pdx. nil means send actual operating system end of file." :type 'string :group 'pdx) (defun pdx-run () "*function used to run pdx on the current buffer." (interactive) (if (buffer-modified-p) (progn (save-buffer) (shell-command (concat pdx-program-name " " pdx-program-options " " buffer-file-name )) ))) (defun pdx-maybe-run-on-save () "runs pdx on current buffer if \\ pdx-run-on-save is set to true" (interactive) (if pdx-run-on-save (pdx-run) (save-buffer))) ;;;============================================= ;;;###autoload (defun pdx-mode () "Major mode for editing typical pdx code. " (interactive) (kill-all-local-variables) (setq mode-name "Pdx") (setq major-mode 'pdx-mode) (setq local-abbrev-table pdx-mode-abbrev-table) (make-local-variable 'font-lock-defaults) (setq font-lock-defaults '(pdx-font-lock-keywords 't ; keywords only nil ; not ignore case nil ; syntax table nil ; syntax beginning )) (set-syntax-table pdx-mode-syntax-table) (use-local-map pdx-mode-map) (make-local-variable 'menu-bar-files-menu) (redefine-save-menu) (add-hook 'pdx-mode-hook 'turn-on-font-lock) (run-hooks 'pdx-mode-hook) ) (provide 'pdx-mode) ;;; pdx-mode.el ends here