;; lisp file for xyzzy ver0.2.2.233
;; mode-menu.l ver.0.0.0.4
;;[2006-06-14]13:27:20(+0900)

(provide "mode-menu")

(in-package "editor")

(export '(
	  add-mode-menu
	  ))

;;(defvar *auto-mode-menu-list* '(
;;				))
(defvar *auto-mode-menu-list* '(
				basic-mode
				c++-mode
				c-mode
				csharp-mode
				css-mode
				detect-c-or-c++-mode
				fundamental-mode
				html-mode
				idl-mode
				java-mode
				LaTeX-mode
				lisp-mode
				lisp-interaction-mode
				pascal-mode
				perl-mode
				sql-mode
				text-mode
				essay-mode
				view-mode
				))

(defvar *minor-mode-menu-list* '(
				 abbrev-mode
				 box-drawings-mode
				 auto-fill-mode
				 overwrite-mode
				 edict-mode
				 ;indent-tab-mode
				 ))

(defvar *else-mode-menu-list* '(
				))

(defun add-mode-menu ()
  ;;  (dolist (mode *auto-mode-alist*)
  ;;    (pushnew (cdr mode) *auto-mode-menu-list* :test 'equal))
  ;;  (pushnew 'fundamental-mode *auto-mode-menu-list* :test 'equal)
  ;;  (pushnew 'lisp-interaction-mode *auto-mode-menu-list* :test 'equal)
  ;;  (pushnew 'view-mode *auto-mode-menu-list* :test 'equal)
  ;;  (setq *auto-mode-menu-list* (sort *auto-mode-menu-list* #'string-lessp))

  (dolist (mode (ed::apropos-find-matches "-mode$" #'commandp))
    (unless (or (member mode *auto-mode-menu-list*)
		(member mode *minor-mode-menu-list*))
      (pushnew mode *else-mode-menu-list*)))

  (when (menup *app-menu*)
    ;(while (delete-menu *mode-popup-menu* 0 t))
    ;(while (delete-menu *mode-popup-else-menu* 0 t))

    (add-mode-popup-menu *mode-popup-menu* *auto-mode-menu-list*)
    (add-menu-separator *mode-popup-menu*)

    (add-mode-popup-menu *mode-popup-else-menu* *minor-mode-menu-list*)
    (add-menu-separator *mode-popup-else-menu*)
    (add-mode-popup-menu *mode-popup-else-menu* *else-mode-menu-list*)
    (add-popup-menu *mode-popup-menu* *mode-popup-else-menu* "minor else(&E)")

    (add-menu-separator *mode-popup-menu*)
    (add-menu-item *mode-popup-menu* nil "read-only" 'toggle-read-only
		   #'(lambda () (if buffer-read-only :check))))
  )

(defun add-mode-popup-menu (menu1 list1)
  (dolist (item list1)
    (let ((mode item))
      (add-menu-item menu1 nil
		     (format nil "~S" mode)
		     #'(lambda () (interactive)
			 (funcall mode))
		     #'(lambda ()
			 (when (eq buffer-mode mode)
			   :check)))))
  )

