;;; ow-mode-el -- Major mode for viewing OneWorld ER logic ;; Author: Bill Clementson ;; Created: 2007 ;; Keywords: OW major-mode ;; Copyright (C) 2007 Bill Clementson ;; 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 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. ;; You should have received a copy of the GNU General Public ;; License along with this program; if not, write to the Free ;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, ;; MA 02111-1307 USA ;;; Commentary: ;; ;; This mode is for viewing J.D. Edwards OneWorld ER logic and for ;; launching the standard OneWorld object editors to modify OneWorld ;; objects. It has been tested with the two main OneWorld source ;; extraction utilities (OWExport and OneAssist). Alternatively, it ;; can also be used with manually extracted source (using built-in ;; OneWorld source extract functionality). ;; To use, add the following to your .emacs file: ;; (require 'ow-mode) ;; (add-to-list 'auto-mode-alist '("\\.owt\\'" . ow-mode)) ;; In addition, there are a number of customizations that can be added ;; to your .emacs file: ;; 1. You might need to change the value of ow-bsfn-source-dir ;; depending on the OW release and site standards - for example: ;; (setq ow-bsfn-source-dir "c:/e811/dv811/source/") ;; 2. If using OneAssist instead of OWExport to extract OneWorld ;; source, make certain you configure OneAssist to output all object ;; source to the same directory. In addition, you will probably add ;; something like the following to your .emacs file: ;; (add-to-list 'auto-mode-alist '("\\.e1\\'" . ow-mode)) ;; (setq ow-view-command "oneassist.bat %s %s %s %s") ;; (setq ow-temp-file-dir "c:/bin/xe") ;; (setq ow-source-suffix ".e1") ;; The oneassist.bat file should look something like the following: ;; rem =============== BEGIN BATCH FILE ================================ ;; @echo off ;; setlocal ;; set object=%2 ;; echo Exporting object %object% ;; set type=%object:~0,1% ;; if %type%==P goto appl ;; if %type%==R goto ube ;; if %type%==D goto dstr ;; if %type%==F goto tble ;; if %type%==V goto bsvw ;; goto unknown ;; ;; :appl ;; "C:\Program Files\OneAssist\OneAssist.exe" -flags APPL -export %object%& ;; goto end ;; ;; :ube ;; "C:\Program Files\OneAssist\OneAssist.exe" -flags UBE -export %object%& ;; goto end ;; ;; :dstr ;; "C:\Program Files\OneAssist\OneAssist.exe" -flags DSTR -export %object%& ;; goto end ;; ;; :tble ;; "C:\Program Files\OneAssist\OneAssist.exe" -flags TBLE -export %object%& ;; goto end ;; ;; :bsvw ;; "C:\Program Files\OneAssist\OneAssist.exe" -flags BSVW -export %object%& ;; goto end ;; ;; :Unknown ;; echo Unknown object type %type% for object %object% ;; ;; :end ;; endlocal ;; rem ================= END BATCH FILE ================================ ;; 3. If you modify OneWorld so that a copy of the source is exported ;; every time there is a checkin, you will want to set the ;; ow-temp-file-dir and ow-bsfn-source-dir variables to the common ;; source network location and set ow-always-get-local to t so that ;; ow-mode never needs to extract the source. ;; 4. In addition to the mode-specific bindings of "C-c C-v" to view ;; and "C-c C-e" to edit an object, you will probably want to add some ;; global bindings so that you can view/edit OneWorld objects when you ;; aren't currently in ow-mode: ;; (global-set-key [f5] 'ow-view-source) ;; (global-set-key [(control f5)] 'ow-edit-source) ;;; Code: (defvar ow-mode-hook nil) ;; View/Edit OneWorld ER code (defvar ow-name-history nil "The hisorical list of OW object names that have been selected.") (defvar ow-always-get-local nil "When non-nil, will attempt to retrieve local source first.") (defvar ow-view-command "OWExport -FCMI3 -T%s/%s%s %s" "The external command to use for retrieving OneWorld source code.") (defvar ow-bsfn-source-dir "c:/b7/dv7334/source/" "The location of OneWorld C Business Function source code.") (defvar ow-temp-file-dir (getenv "TEMP") "The directory where retrieved OneWorld source will be put.") (defvar ow-source-suffix ".owt" "The suffix to append to retrieved OneWorld source.") (defun ow-view-source (arg) "View OneWorld ER source code. If a prefix argument is supplied and a local copy already exists, display the local copy of the source. Alternatively, if no prefix argument is supplied but ow-always-get-local is non-nil, also attempt to display the local copy of the source." (interactive "P") (let* ((name (upcase (ow-get-object-name))) (type (substring name 0 1)) (dir (if (or (string= type "B") (string= type "X") (string= type "N")) ow-bsfn-source-dir ow-temp-file-dir))) (when name (cond ((or (string= type "B") (string= type "X") (string= type "N")) (find-file (format "%s%s.c" dir name)) ;; OW C code has tab width fixed at 3 spaces (set (make-local-variable 'tab-width) 3)) ((and (or arg ow-always-get-local) (file-exists-p (format "%s/%s%s" dir name ow-source-suffix))) (find-file (format "%s/%s%s" dir name ow-source-suffix))) (t (shell-command (format ow-view-command dir name ow-source-suffix name)) (find-file (format "%s/%s%s" dir name ow-source-suffix))))))) (defun ow-edit-source () "Edit a OneWorld object." (interactive) (let* ((name (upcase (ow-get-object-name))) (type (substring name 0 1)) (dir (if (or (string= type "B") (string= type "X") (string= type "N")) ow-bsfn-source-dir "")) (command nil)) (when name (shell-command (format "%s%s%s%s&" (cond ((string= type "P") "start fda -id") ((string= type "R") "start rda -id") ((string= type "D") "start dsform4 -id") ((string= type "T") "start poda -id") ((string= type "F") "start tda -id") ((string= type "V") "start vdt -id") ((or (string= type "B") (string= type "X") (string= type "N")) "start msdev ") (t (error "Unknown object type %s for object %s" type name))) dir name (if (or (string= type "B") (string= type "X") (string= type "N")) ".c" "")))))) (defun ow-get-object-name () "Prompt the user for the OW object to view/edit." (let ((name-string (read-string "OneWorld object: " (if (not (equal mark-active nil)) (thing-at-point 'word) (car ow-name-history)) 'ow-name-history nil))) (when (string= name-string "") (error "No OneWorld object name given")) name-string)) ;; Mode-specific key bindings (defvar ow-mode-map (let ((ow-mode-map (make-keymap))) (define-key ow-mode-map "\C-c\C-e" 'ow-edit-source) (define-key ow-mode-map "\C-c\C-v" 'ow-view-source) ow-mode-map) "Keymap for OW major mode") ;; OneWorld Keywords (defconst ow-font-lock-keywords-1 (list `(,(rx (and (or "If" "Or" "Else" "End If" "EndIf" "While" "End While" "EndWhile" "And")(any " \t\n"))) . font-lock-keyword-face)) "Minimal highlighting of keywords for OW mode.") ;; OneWorld Constants (defconst ow-font-lock-keywords-2 (append ow-font-lock-keywords-1 (list '("\\<\\(Blank\\|Zero\\|Null\\|Yes\\|No\\)\\>" . font-lock-constant-face))) "Additional constants to highlight in OW mode.") ;; OneWorld Variables (begin with specific characters) (defconst ow-font-lock-keywords-3 (append ow-font-lock-keywords-2 (list `(,(rx (or line-start " ")(and (or "evt_" "frm_" "rpt_")(1+ (or word ?_)))) . font-lock-variable-name-face))) "Variables to highlight in OW mode.") (defvar ow-font-lock-keywords ow-font-lock-keywords-3 "Default highlighting expressions for OW mode.") (defvar ow-mode-syntax-table (let ((ow-mode-syntax-table (make-syntax-table))) ;; Underscores can be used to separate words in variable names (modify-syntax-entry ?_ "w" ow-mode-syntax-table) ;; Comment lines begin with "//" (modify-syntax-entry ?/ ". 124b" ow-mode-syntax-table) (modify-syntax-entry ?\n "> b" ow-mode-syntax-table) ow-mode-syntax-table) "Syntax table for ow-mode") (defun ow-mode () (interactive) (kill-all-local-variables) (use-local-map ow-mode-map) (set-syntax-table ow-mode-syntax-table) (set (make-local-variable 'font-lock-defaults) '(ow-font-lock-keywords)) (setq major-mode 'ow-mode) (setq mode-name "OW") (run-hooks 'ow-mode-hook)) (provide 'ow-mode) ;;; ow-mode.el ends here