;;; 50lookup-el.el --- Debian lookup-el startup file  -*-mode: emacs-lisp;-*-

;;; Code:

(let* ((flavor-name (if (boundp 'debian-emacs-flavor)
			(symbol-name debian-emacs-flavor)
		      "emacs"))
       (lispdir (concat "/usr/share/" flavor-name "/site-lisp/lookup-el")))
  (when (and (featurep 'mule) (file-readable-p (concat lispdir "/lookup.elc")))
    (if (fboundp 'debian-pkg-add-load-path-item)
	(debian-pkg-add-load-path-item lispdir)
      (setq load-path (cons lispdir load-path)))
    (autoload 'lookup "lookup" nil t)
    (autoload 'lookup-region "lookup" nil t)
    (autoload 'lookup-pattern "lookup" nil t)
    (add-hook 'lookup-load-hook 'lookup-set-debian-default)
    ;;
(defconst lookup-select-mode-help-en
  "Lookup Select mode:

`n'(ext)      - Next dictionary
`p'(revios)   - Previous dictionary

`m'(ark)      - Mark dictionary
`u'(nmark)    - Unmark dictionary
`a'(ll)       - Mark all dictionary
`RET'         - Mark this dictionary
`d'(isable)   - Disable dictionary (`D' mark)
(e)`x'(ecute) - Execute `D' mark

`f'(ind)    - Input text and search
`/'           - Text search this dictionary
`M'(enu)    - Display dictionary menu
`C'(opyright) - Display dictionary copyright
`o'(pen)    - Maximize window

`q'    - Quit buffer
`g'    - Initialize module
`Q'    - Quit Lookup
`R'    - Restart Lookup")

(defconst lookup-entry-mode-help-en
  "Lookup Entry mode:

`n'(ext)     - Next entry
`M-n' - Next history
`p'(revious) - Previous entry
`M-p' - Previous history

`v'(iew)   - Overview mode
`o'(pen)  - Maximize window
`s'(earch) - isearch-forward  	
`i'(nfo)  - Display entry info
`t'(oggle) - Toggle text processing
`w'(rite) - Write content to kill ring
`f'(ind)   - Input text to search

`M'(enu)   - Display dictionary menu
`C'(opyright) - Display dictionary copyright
`L'(inks)  - Display links
`S'(elect) - Select mode

`r'   - Go to buffer
`h'   - Go to Content buffer
`q'   - Quit buffer
`g'   - Search again
`Q'   - Quit Lookup
`R'   - Restart Lookup")

(defconst lookup-content-mode-help-en
  "Lookup Content mode:

`SPC' - Next page               `<'   - First buffer
`DEL' - Previous page           `>'   - Last buffer

`TAB' - Next link               `RET' - Follow link

`t'   - Toggle text processing  `w'   - Write region to kill ring
`h'   - Go to Entry buffer      `g'   - Update buffer
`q'   - Quit buffer             `?'   - Help")

(defun lookup-search-agents-debian-default ()
  (let (agents)
    (if (and (file-exists-p "/etc/inetd.conf")
	     (eq (call-process "egrep" "/etc/inetd.conf" nil nil "^ndtp[ \t]")
		 0)
	     (file-exists-p "/etc/services")
	     (eq (call-process "egrep" "/etc/services" nil nil "^ndtp[ \t]")
		 0)
	     (file-exists-p "/usr/sbin/ndtpd"))
	;; ndtp
	(add-to-list 'agents '(ndtp "localhost") 'append)
      ;; ndeb
      (when (file-executable-p "/usr/bin/eblook")
	(let ((dirs 
	       (append
		(and (file-directory-p "/usr/local/share/dict/epwing")
		     (directory-files "/usr/local/share/dict/epwing"
				      'full "[^.]"))
		(and (file-directory-p "/usr/share/dict/epwing")
		     (directory-files "/usr/share/dict/epwing"
				      'full "[^.]"))))
	      d d-a)
	  (while dirs
	    (setq d (car dirs))
	    (when (or (file-readable-p (concat d "/catalogs"))
		      (file-readable-p (concat d "/catalog")))
	      (if (and (string-match "/epwing/" d)
		       (setq d-a (replace-match "/epwing-appendix/" nil t d))
		       (or (file-readable-p (concat d-a "/catalogs"))
			   (file-readable-p (concat d-a "/catalog"))))
		  (add-to-list 'agents `(ndeb ,d :appendix ,d-a) 'append)
		(add-to-list 'agents `(ndeb ,d) 'append)))
	    (setq dirs (cdr dirs))))))
    (if (and (not (featurep 'xemacs))
	     (or (and (file-exists-p "/var/run/dictd.pid")
		      (file-exists-p "/usr/sbin/dictd"))
		 (and (file-exists-p "/var/run/dicod/dicod.pid")
		      (file-exists-p "/usr/bin/dicod"))))
	;; ndict
	(if (or (and (fboundp 'find-coding-system)
		     (find-coding-system 'utf-8-dos))
		(and (fboundp 'coding-system-p)
		     (coding-system-p 'utf-8-dos)))
	    (add-to-list 'agents
			 '(ndict "localhost" :coding utf-8-dos) 'append)
	  (add-to-list 'agents '(ndict "localhost") 'append))
      ;; ndic
      (if (file-directory-p "/usr/local/share/dictd")
	  (add-to-list 'agents '(ndic "/usr/local/share/dictd") 'append))
      (if (file-directory-p "/usr/share/dictd")
	  (add-to-list 'agents '(ndic "/usr/share/dictd") 'append)))
    ;; ndspell
    (cond
     ((file-executable-p "/usr/bin/ispell")
      (setq ndspell-ispell-program "ispell")
      (add-to-list 'agents '(ndspell) 'append))
     ((file-executable-p "/usr/bin/hunspell")
      (setq ndspell-ispell-program "hunspell")
      (add-to-list 'agents '(ndspell) 'append)))
    ;; ndkks
    (if (file-executable-p "/usr/bin/kakasi")
	(add-to-list 'agents '(ndkks) 'append))
    agents))

(defun lookup-set-debian-default ()
  (if (null lookup-search-agents)
      (setq lookup-search-agents (lookup-search-agents-debian-default)))
  (if (string= current-language-environment "Japanese")
      ()
    (eval-after-load "lookup-select"
      '(defconst lookup-select-mode-help lookup-select-mode-help-en))
    (eval-after-load "lookup-entry"
      '(defconst lookup-entry-mode-help lookup-entry-mode-help-en))
    (eval-after-load "lookup-content"
      '(defconst lookup-content-mode-help lookup-content-mode-help-en))))
    ;;
    ))

;;; 50lookup-el.el ends here
