;;; owl-menu.el --- a part of the simple OWL mode for Xemacs ;;; (C) 2001 BBN Technologies ;;; by Mark Burstein, with assistance from Ken Anderson and Richard Shapiro ;;; updated for OWL by David Rager ;;; This package is designed to be used with XEmacs and Gnu Emacs ;;;; Definition of the menu and keystroke commands (unless (boundp 'in-xemacs-p) (setq in-xemacs-p (string-match "XEmacs" (emacs-version)))) ;;; COMPAT for DAML/OWL mode: ;;; functions used by OWL mode not found in GNU emacs (unless (string-match "XEmacs\\|Lucid" (emacs-version)) (defun mapvector (fn list) (coerce (mapcar '(lambda (elt) (funcall fn elt)) list) 'vector)) (defmacro char= (a b) `(and (numberp ,a)(numberp ,b)(= ,a ,b))) (defmacro characterp (c) `(and (numberp ,c)(< ,c 256))) ) ;; end unless for COMPAT ;;; hide conditionalization of keystroke definitions between XEmacs and GNU Emacs ;;; for GNU: ;;; take lists like (control ?f) (meta ?y) (control meta ?z) ;;; and convert them to strings like "^f" "^[y" "^[^z" for GNU ;;; or to vector of these elts for Xemacs (unless (symbol-function 'some) ;; some emaxen don't have this??? (defun some (fn list) (let ((res nil) elt) (while (and list (not res)) (setq elt (car list)) (setq list (cdr list)) (setq res (funcall fn elt))) res)) ) (defun keystroke (list) "Convert an Xemacs keystroke representation to GNU form, if in XEmacs, then much same as quote, just make a vector if a sequence." (if in-xemacs-p (if (and (consp list) (some 'consp list)) ;; a complex key seq (mapvector 'keystroke list) list) ;; else GNU (cond ((integerp list) (char-to-string list)) ((symbolp list) (symbol-name list)) ;; should be a single character name ((consp list) (if (some 'consp list) (apply 'concat (mapcar 'keystroke list)) (let* ((ctrl (member 'control list)) (meta (member 'meta list)) (key (car (last list))) (str ;; note that may be multi-char if not control or meta (cond ((symbolp key) (symbol-name key)) ((integerp key) ;; a char (char-to-string key)) ((stringp key) key)))) (when ctrl ;; then key should be 1 char (setq key (elt str 0)) (setq key (1+ (- key ?a))) ;; convert to control char (setq str (char-to-string key))) ; redo string (if meta (setq str (concat "\e" str))) str))) (t list)))) ;;; printable representation appropriate for menus (defun keystroke-string (list) "Convert an keystroke representation to printable form" (cond ((if in-xemacs-p (characterp list) (integerp list)) (char-to-string list)) ((consp list) (if (consp (car list)) (apply 'concat (mapcar 'keystroke-string list)) (let* ((ctrl (member 'control list)) (meta (member 'meta list)) (key (car (last list))) (str-elts (append (if ctrl '("C-")) (if meta '("M-")) (list (char-to-string key)) (list " ")))) (apply 'concat str-elts)))) (t list))) ; (define-key owl-mode-map "\C-z\C-z" 'suspend-or-iconify-emacs) ;;; items are each (menu-text action keystroke active?) (defun owl-make-menu (menuvar name mode-map doc items) (let ((menuitems nil)) (dolist (item items) (cond ((stringp item) (setq menuitems (nconc menuitems (list item)))) (t ;else a form (let ((menuitem nil) (label (first item)) (action (second item)) (keys (third item)) (active (if (cdddr item) (fourth item) t)) ) (setq menuitem (mapvector 'identity (list label action :keys (keystroke-string keys) :active active))) (setq menuitems (nconc menuitems (list menuitem))) ;; also define the key ;;; (scratch-msg "before define key %S %s\n" (keystroke keys) action) (define-key mode-map (keystroke keys) action) )) ;; this defines the keystroke based on the items )) ;; (scratch-msg "Menu is %S" menuitems) (easy-menu-do-define menuvar mode-map doc (cons name menuitems)) )) (defvar owl-menu nil) ;;; also creates keystroke commands ;;; elts are (label fn key active?) active? defaults to t (defvar owl-menu-items '(;; in owl-w3 ("View URL" owl-view-url (meta ?.)) ("Find Def In Buffer" owl-find-def-in-buffer (meta ?,)) ("Previous Position" owl-goto-previous-position ((control ?x) ?p)) ("Remember Position" owl-remember-position ((control ?x) ?.)) "--" ;; in owl-motion ("Forward Tag" owl-forward-tag (control meta ?f)) ("Backward Tag" owl-backward-tag (control meta ?b)) ("Up Tag" owl-up-tag (control meta ?a)) ("Up Tag End" owl-up-tag-end (control meta ?e)) ("Inside Tag" owl-inside-tag (control meta ?i)) ("Prev Tag Def" owl-prev-tag-def (control meta ?u)) ("Next Tag Def" owl-next-tag-def (control meta ?d)) ("Indent Tag Expression" owl-indent-expression (control meta ?q)) ("Indent Line" owl-indent-line (control ?i)) ;; == tab "--" ("List Definitions" owl-summarize ((control ?c) ?l ?d)) )) (defvar owl-insert-menu nil) (defvar owl-insert-menu-items '( ;; in owl-insert ("" owl-insert-ontology ((control ?c) ?o ?t)) ("" owl-insert-versionInfo ((control ?c) ?v ?i)) ("" owl-insert-imports ((control ?c) ?i ?m)) ("" owl-insert-priorVersion ((control ?c) ?p ?v)) ("" owl-insert-backwardCompatibleWith ((control ?c) ?b ?c)) ("" owl-insert-incompatibleWith ((control ?c) ?i ?c)) "--" ("" owl-insert-description-id ((control ?c) ?d ?i)) ("" owl-insert-description-about ((control ?c) ?d ?a)) ("" owl-insert-comment ((control ?c) ?c ?m)) ("