Anonymous avatar Anonymous committed 00708ad

Created

Comments (0)

Files changed (23)

+1998-01-12  SL Baur  <steve@altair.xemacs.org>
+
+	* Makefile: Update to newer package interface.
+	(ELCS): Add nroff-mode, scribe and ws-mode.
+
+1998-01-03  SL Baur  <steve@altair.xemacs.org>
+
+	* Makefile: Update to newer package interface.
+
+1997-12-24  SL Baur  <steve@altair.xemacs.org>
+
+	* whitespace-mode.el: Strip usage of adapt.el.
+
+	* xrdb-mode.el: Don't require 'reporter at bytecompile time.
+
+	* Makefile: Created.
+
+# Makefile for miscellaneous text modes lisp code
+
+# This file is part of XEmacs.
+
+# XEmacs 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, or (at your option) any
+# later version.
+
+# XEmacs 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 XEmacs; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# This XEmacs package contains independent single file lisp packages
+
+VERSION = 1.02
+PACKAGE = text-modes
+PKG_TYPE = single-file
+REQUIRES = xemacs-base
+CATEGORY = oa
+
+ELCS = autoinsert.elc crontab.elc filladapt.elc hexl.elc image-mode.elc \
+	iso-acc.elc iso-ascii.elc iso-cvt.elc iso-insert.elc iso-swed.elc \
+	nroff-mode.elc scribe.elc swedish.elc tabify.elc underline.elc \
+	whitespace-mode.elc winmgr-mode.elc ws-mode.elc xpm-mode.elc \
+	xrdb-mode.elc
+
+include ../../XEmacs.rules
+
+all:: $(ELCS) auto-autoloads.elc custom-load.elc
+
+srckit: srckit-std
+
+binkit: binkit-sourceonly
+;;; autoinsert.el --- automatic mode-dependent insertion of text into new files
+;; Copyright (C) 1985, 1986, 1987, 1994, 1995 Free Software Foundation, Inc.
+
+;; Author: Charlie Martin <crm@cs.duke.edu>
+;; Adapted-By: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389
+
+;; This file is part of XEmacs.
+
+;; XEmacs 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, or (at your option)
+;; any later version.
+
+;; XEmacs 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 XEmacs; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+;; 02111-1307, USA.
+
+;;; Synched up with: FSF 19.34.
+
+;;; Commentary:
+
+;;  The following defines an association list for text to be
+;;  automatically inserted when a new file is created, and a function
+;;  which automatically inserts these files; the idea is to insert
+;;  default text much as the mode is automatically set using
+;;  auto-mode-alist.
+;;
+;;  To use: 
+;;     (add-hook 'find-file-hooks 'auto-insert)
+;;     setq auto-insert-directory to an appropriate slash-terminated value
+;;
+;;  Author:  Charlie Martin
+;;           Department of Computer Science and
+;;           National Biomedical Simulation Resource
+;;           Box 3709
+;;           Duke University Medical Center
+;;           Durham, NC 27710
+;;	      (crm@cs.duke.edu,mcnc!duke!crm) 
+
+;;; Code:
+
+(defgroup auto-insert nil
+  "Automatic mode-dependent insertion of text into new files."
+  :group 'tools)
+
+
+(defcustom auto-insert 'not-modified
+  "*Controls automatic insertion into newly found empty files:
+	nil	do nothing
+	t	insert if possible
+	other	insert if possible, but mark as unmodified.
+Insertion is possible when something appropriate is found in
+`auto-insert-alist'.  When the insertion is marked as unmodified, you can
+save it with  \\[write-file] RET.
+This variable is used when `auto-insert' is called as a function, e.g.
+when you do (add-hook 'find-file-hooks 'auto-insert).
+With \\[auto-insert], this is always treated as if it were `t'."
+  :type '(radio (const :tag "Do nothing" nil)
+		(const :tag "Insert if possible" t)
+		(sexp :format "%t\n"
+		      :tag "Insert if possible, but mark as unmodified"
+		      other))
+  :require 'autoinsert
+  :group 'auto-insert)
+
+
+(defcustom auto-insert-query 'function
+  "*If non-`nil', ask user before auto-inserting.
+When this is `function', only ask when called non-interactively."
+  :type '(choice (const :tag "Don't ask" nil)
+		 (const :tag "Ask when non-interactive" function)
+		 (sexp :format "%t\n" :tag "Ask" other))
+  :group 'auto-insert)
+
+
+(defcustom auto-insert-prompt "Perform %s auto-insertion? "
+  "*Prompt to use when querying whether to auto-insert.
+If this contains a %s, that will be replaced by the matching rule."
+  :type 'string
+  :group 'auto-insert)
+
+
+(defvar auto-insert-alist
+  '((("\\.\\([Hh]\\|hh\\|hpp\\)\\'" . "C / C++ header")
+     (upcase (concat (file-name-nondirectory
+		      (substring buffer-file-name 0 (match-beginning 0)))
+		     "_"
+		     (substring buffer-file-name (1+ (match-beginning 0)))))
+     "#ifndef " str \n
+     "#define " str "\n\n"
+     _ "\n\n#endif")
+
+    (("\\.\\([Cc]\\|cc\\|cpp\\)\\'" . "C / C++ program")
+     nil
+     "#include \""
+     ;; nop without latest cc-mode
+     (and (fboundp 'c-companion-file)
+	  ;(file-readable-p (c-companion-file 'name))
+	  (file-name-nondirectory (c-companion-file 'name))) & ?\"
+     | -10)
+
+    ("[Mm]akefile\\'" . "makefile.inc")
+
+    (html-mode . (lambda () (sgml-tag "html")))
+
+    (plain-tex-mode . "tex-insert.tex")
+    (bibtex-mode . "tex-insert.tex")
+    (latex-mode
+     ;; should try to offer completing read for these
+     "options, RET: "
+     "\\documentstyle[" str & ?\] | -1
+     ?{ (read-string "class: ") "}\n"
+     ("package, %s: "
+      "\\usepackage[" (read-string "options, RET: ") & ?\] | -1 ?{ str "}\n")
+     _ "\n\\begin{document}\n" _
+     "\n\\end{document}")
+
+    (("/bin/.*[^/]\\'" . "Shell-Script mode magic number")
+     lambda ()
+       (if (eq major-mode default-major-mode)
+	 (sh-mode)))
+    
+    (ada-mode . ada-header)
+
+    (("\\.el\\'" . "Emacs Lisp header")
+     "Short description: "
+     ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str "
+
+;; Copyright (C) " (substring (current-time-string) -4) " by "
+ (getenv "ORGANIZATION") | "Free Software Foundation, Inc." "
+
+;; Author: " (user-full-name)
+'(if (search-backward "&" (save-excursion (beginning-of-line 1) (point)) t)
+     (replace-match (capitalize (user-login-name)) t t))
+'(end-of-line 1) " <" (user-login-name) ?@ (system-name) ">
+;; Keywords: "
+ '(require 'finder)
+ ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords)))
+ '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x))))
+		   finder-known-keywords)
+	v2 (mapconcat (lambda (x) (format "%10.0s:  %s" (car x) (cdr x)))
+	   finder-known-keywords
+	   "\n"))
+ ((let ((minibuffer-help-form v2))
+    (completing-read "Keyword, C-h: " v1 nil t))
+    str ", ") & -2 "
+
+;; This file is part of XEmacs.
+
+;; XEmacs 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, or (at your option)
+;; any later version.
+
+;; XEmacs 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 XEmacs; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+;; 02111-1307, USA.
+
+;;; Synched up with: Not in FSF
+
+;;; Commentary:
+
+;; " _ "
+
+;;; Code:
+
+
+(provide '" (file-name-sans-extension (file-name-nondirectory
+(buffer-file-name))) ")
+
+;;; " (file-name-nondirectory (buffer-file-name)) " ends here
+"))
+  "A list specifying text to insert by default into a new file.
+Elements look like (CONDITION . ACTION) or ((CONDITION . DESCRIPTION) . ACTION).
+CONDITION maybe a regexp that must match the new file's name, or it may be
+a symbol that must match the major mode for this element to apply.
+Only the first matching element is effective.
+Optional DESCRIPTION is a string for filling `auto-insert-prompt'.
+ACTION may be a skeleton to insert (see `skeleton-insert'), an absolute
+file-name or one relative to `auto-insert-directory' or a function to call.
+ACTION may also be a vector containing several successive single actions as
+described above, e.g. [\"header.insert\" date-and-author-update].")
+
+
+;; Establish a default value for auto-insert-directory
+(defvar auto-insert-directory "~/insert/"
+  "*Directory from which auto-inserted files are taken.")
+
+
+;;;###autoload
+(defun auto-insert ()
+  "Insert default contents into a new file if `auto-insert' is non-nil.
+Matches the visited file name against the elements of `auto-insert-alist'."
+  (interactive)
+  (and (not buffer-read-only)
+       (or (eq this-command 'auto-insert)
+	   (and auto-insert
+		(bobp) (eobp)))
+       (let ((alist auto-insert-alist)
+	     case-fold-search cond desc action)
+	 (goto-char 1)
+	 ;; find first matching alist entry
+	 (while alist
+	   (if (atom (setq cond (car (car alist))))
+	       (setq desc cond)
+	     (setq desc (cdr cond)
+		   cond (car cond)))
+	   (if (if (symbolp cond)
+		   (eq cond major-mode)
+		 (string-match cond buffer-file-name))
+	       (setq action (cdr (car alist))
+		     alist nil)
+	     (setq alist (cdr alist))))
+
+	 ;; Now, if we found something, do it
+	 (and action
+	      (if (stringp action)
+		  (file-readable-p (concat auto-insert-directory action))
+		t)
+	      (if auto-insert-query
+		  (or (if (eq auto-insert-query 'function)
+			  (eq this-command 'auto-insert))
+		      (y-or-n-p (format auto-insert-prompt desc)))
+		t)
+	      (mapcar
+	       (lambda (action)
+		 (if (stringp action)
+		     (if (file-readable-p
+			  (setq action (concat auto-insert-directory action)))
+			 (insert-file-contents action))
+		   (save-window-excursion
+		     ;; make buffer visible before skeleton or function
+		     ;; which might ask the user for something
+		     (switch-to-buffer (current-buffer))
+		     (if (and (consp action)
+			      (not (eq (car action) 'lambda)))
+			 (skeleton-insert action)
+		       (funcall action)))))
+	       (if (vectorp action)
+		   action
+		 (vector action))))
+	 (and (buffer-modified-p)
+	      (not (eq this-command 'auto-insert))
+	      (set-buffer-modified-p (eq auto-insert t))))))
+
+
+;;;###autoload
+(defun define-auto-insert (key action &optional after)
+  "Associate CONDITION with (additional) ACTION in `auto-insert-alist'.
+Optional AFTER means to insert action after all existing actions for CONDITION,
+or if CONDITION had no actions, after all other CONDITIONs."
+  (let ((elt (assoc key auto-insert-alist)))
+    (if elt
+	(setcdr elt
+		(if (vectorp (cdr elt))
+		    (vconcat (if after (cdr elt))
+			     (if (vectorp action) action (vector action))
+			     (if after () (cdr elt)))
+		  (if after
+		      (vector (cdr elt) action)
+		    (vector action (cdr elt)))))
+      (if after
+	  (nconc auto-insert-alist (list (cons key action)))
+	(setq auto-insert-alist (cons (cons key action)
+				      auto-insert-alist))))))
+
+(provide 'autoinsert)
+
+;;; autoinsert.el ends here
+;; #(@) crontab.el - An Emacs function to assist in editing crontab entries
+;; Last edited: Fri Aug 18 12:19:22 1989 by chris (Christopher D. Orr) on lxn
+;;
+;; Version: 1.00 - Initial Creation of mode
+;;          1.01 - Added crontab-use-local-file variable
+;;          1.02 - Reworked most of the library to be cleaner.
+;;          1.03 - Now deletes blank lines in crontab entry
+
+;; Copyright (C) 1989 Christopher D. Orr (chris@lxn.eds.com)
+
+;; This file is part of XEmacs.
+
+;; XEmacs 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, or (at your option)
+;; any later version.
+
+;; XEmacs 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 XEmacs; see the file COPYING.  If not, write to the 
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Synched up with: Not in FSF.
+
+;;
+;; TODO:
+;;
+
+;; Place the following line in your ~/.emacs file:
+;;    (autoload 'crontab-edit "crontab"
+;;              "Function to allow the easy editing of crontab files." t)
+;;
+
+(provide 'crontab-edit)
+
+;;; Local Variables.  Define these to your liking.
+
+(defgroup crontab nil
+  "Assist in editing crontab files."
+  :group 'languages)
+
+
+(defcustom crontab-filename "~/.crontab"
+  "*The name of the file to store the User's Crontab."
+  :type 'file
+  :group 'crontab)
+
+(defcustom crontab-directory "/usr/spool/cron/crontabs"
+  "*The name of the directory in which crontab stores it's entries."
+  :type 'file
+  :group 'crontab)
+
+(defcustom crontab-use-local-file nil
+  "*Non-nil means use file stored in User's Home directory, if it exists.
+Otherwise, always ask crontab for the current entry (maybe)."
+  :type 'boolean
+  :group 'crontab)
+
+
+;;; Interactive Function called to edit a Crontab Entry.  It is called
+;;; instead of crontab-edit to allow for future automatic entries.
+
+(defun crontab-edit ()
+  "Function to allow the easy editing of crontab files."
+
+  (interactive)
+  (crontab-get))
+
+
+;;; Function to retrieve the crontab entry.  The Function will
+;;; retrieve the file (crontab-filename) first.  If the file does not
+;;; exists, a crontab -l command will be executed. 
+
+(defun crontab-get ()
+   "Retrieve a crontab file either using crontab -l or from the variable
+crontab-filename"
+   (message "Retrieving Crontab ... ")
+   (switch-to-buffer (create-file-buffer crontab-filename))
+   (erase-buffer)
+
+   (if (file-exists-p crontab-filename)
+       (if (file-newer-than-file-p (concat crontab-directory "/" (user-login-name)) (expand-file-name crontab-filename))
+	   (if (yes-or-no-p "Cron has a more recent copy of your crontab.  Use it ? ")
+	       (call-process "crontab" nil t t "-l")
+	     (insert-file crontab-filename))
+	 (if crontab-use-local-file
+	     (insert-file crontab-filename)
+	   (call-process "crontab" nil t t "-l")))
+     (if crontab-use-local-file
+	 (insert-file crontab-filename)
+       (call-process "crontab" nil t t "-l")))
+
+;; What if crontab returns a fatal ??????  Can't we check the errorlevel ????
+   (goto-char (point-min))
+   (if (search-forward-regexp "crontab:\\|no crontab for" nil t nil)
+       (erase-buffer))
+   (if (eobp)
+       (crontab-initialize))
+   (goto-line 6)
+   (setq buffer-file-name crontab-filename)
+   (set-buffer-modified-p nil)
+   (make-variable-buffer-local 'write-file-hooks)
+   (or (memq 'crontab-save write-file-hooks)
+       (setq write-file-hooks 
+	     (reverse (cons 'crontab-save (reverse write-file-hooks)))))
+   (message "Save file normally when finished to update cron."))
+
+
+;;; This function is called whenever a save-file operation is
+;;; performed in the crontab buffer.  It saves the crontab to the file
+;;; name (crontab-filename) and then removes the crontab buffer.
+
+(defun crontab-save ()
+  "Submit the edited crontab to the cron deamon for processing"
+
+  (goto-char (point-min))
+  (while (not (eobp))
+    (delete-blank-lines)
+    (forward-line 1))
+  (redraw-display)
+
+  (setq write-file-hooks nil)
+  (let ((crontab-buffer (buffer-name)))
+    (basic-save-buffer)
+
+;; What if the call-process to crontab fails ???  Can we check for a fatal ???
+;;  (call-process "crontab" nil nil nil (expand-file-name crontab-filename))
+    (shell-command (concat "crontab " (expand-file-name crontab-filename)))
+
+    (switch-to-buffer (other-buffer))
+    (kill-buffer crontab-buffer))
+  (message (concat "Crontab saved as " crontab-filename " and submitted to cron."))
+;; fixed by Lynn D. Newton - 03/17/95
+  "")
+;; OLD
+;; nil)
+
+(defun crontab-initialize ()
+  "Create a default Crontab file if one does not exist or is empty.
+If the function (time-stamp) is available, the last modification time will
+be stamped to the file."
+
+   (insert "# Cron Table Entry for ")
+   (insert (user-login-name))
+   (insert " (")
+   (insert (user-full-name))
+   (insert ")\n# Last Edited: \n")
+   (insert "#\n")
+   (insert "# min    hr     day   mon    wday(0=sun)  cmd\n")
+   (insert "#\n"))
+
+;;; Watch out for the signature  :-)
+;;; Adaptive fill
+;;; Copyright (C) 1989, 1995, 1996, 1997 Kyle E. Jones
+;;;
+;;; 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, 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.
+;;;
+;;; A copy of the GNU General Public License can be obtained from this
+;;; program's author (send electronic mail to kyle@uunet.uu.net) or from
+;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
+;;; 02139, USA.
+;;;
+;;; Send bug reports to kyle_jones@wonderworks.com
+
+;; LCD Archive Entry: 
+;; filladapt|Kyle Jones|kyle_jones@wonderworks.com| 
+;; Minor mode to adaptively set fill-prefix and overload filling functions|
+;; 10-June-1996|2.10|~/packages/filladapt.el| 
+
+;; These functions enhance the default behavior of Emacs' Auto Fill
+;; mode and the commands fill-paragraph, lisp-fill-paragraph,
+;; fill-region-as-paragraph and fill-region.
+;;
+;; The chief improvement is that the beginning of a line to be
+;; filled is examined and, based on information gathered, an
+;; appropriate value for fill-prefix is constructed.  Also the
+;; boundaries of the current paragraph are located.  This occurs
+;; only if the fill prefix is not already non-nil.
+;;
+;; The net result of this is that blurbs of text that are offset
+;; from left margin by asterisks, dashes, and/or spaces, numbered
+;; examples, included text from USENET news articles, etc. are
+;; generally filled correctly with no fuss.
+;;
+;; Since this package replaces existing Emacs functions, it cannot
+;; be autoloaded.  Save this in a file named filladapt.el in a
+;; Lisp directory that Emacs knows about, byte-compile it and put
+;;    (require 'filladapt)
+;; in your .emacs file.
+;;
+;; Note that in this release Filladapt mode is a minor mode and it is
+;; _off_ by default.  If you want it to be on by default, use
+;;   (setq-default filladapt-mode t)
+;;
+;; M-x filladapt-mode toggles Filladapt mode on/off in the current
+;; buffer.
+;;
+;; Use
+;;     (add-hook 'text-mode-hook 'turn-on-filladapt-mode)
+;; to have Filladapt always enabled in Text mode.
+;;
+;; Use
+;;     (add-hook 'c-mode-hook 'turn-off-filladapt-mode)
+;; to have Filladapt always disabled in C mode.
+;;
+;; In many cases, you can extend Filladapt by adding appropriate
+;; entries to the following three `defvar's.  See `postscript-comment'
+;; or `texinfo-comment' as a sample of what needs to be done.
+;;
+;;     filladapt-token-table
+;;     filladapt-token-match-table
+;;     filladapt-token-conversion-table
+
+(and (featurep 'filladapt)
+     (error "filladapt cannot be loaded twice in the same Emacs session."))
+
+(provide 'filladapt)
+
+;; BLOB to make custom stuff work even without customize
+(eval-and-compile
+  (condition-case ()
+      (require 'custom)
+    (error nil))
+  (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
+      nil ;; We've got what we needed
+    ;; We have the old custom-library, hack around it!
+    (defmacro defgroup (&rest args)
+      nil)
+    (defmacro defcustom (var value doc &rest args) 
+      (` (defvar (, var) (, value) (, doc))))))
+
+(defgroup filladapt nil
+  "Enhanced filling"
+  :group 'fill)
+
+(defvar filladapt-version "2.10"
+  "Version string for filladapt.")
+
+(defcustom filladapt-mode nil
+  "*Non-nil means that Filladapt minor mode is enabled.
+Use the filladapt-mode command to toggle the mode on/off."
+  :type 'boolean
+  :require 'filladapt
+  :group 'filladapt)
+(make-variable-buffer-local 'filladapt-mode)
+
+(defcustom filladapt-mode-line-string " Filladapt"
+  "*String to display in the modeline when Filladapt mode is active.
+Set this to nil if you don't want a modeline indicator for Filladapt."
+  :type 'string
+  :group 'filladapt)
+
+(defcustom filladapt-fill-column-tolerance nil
+  "*Tolerate filled paragraph lines ending this far from the fill column.
+If any lines other than the last paragraph line end at a column
+less than fill-column - filladapt-fill-column-tolerance, fill-column will
+be adjusted using the filladapt-fill-column-*-fuzz variables and
+the paragraph will be re-filled until the tolerance is achieved
+or filladapt runs out of fuzz values to try.
+
+A nil value means behave normally, that is, don't try refilling
+paragraphs to make filled line lengths fit within any particular
+range."
+  :type '(choice (const nil)
+		 integer)
+  :group 'filladapt)
+
+(defcustom filladapt-fill-column-forward-fuzz 5
+  "*Try values from fill-column to fill-column plus this variable
+when trying to make filled paragraph lines fall with the tolerance
+range specified by filladapt-fill-column-tolerance."
+  :type 'integer
+  :group 'filladapt)
+
+(defcustom filladapt-fill-column-backward-fuzz 5
+  "*Try values from fill-column to fill-column minus this variable
+when trying to make filled paragraph lines fall with the tolerance
+range specified by filladapt-fill-column-tolerance."
+  :type 'integer
+  :group 'filladapt)
+
+;; install on minor-mode-alist
+(or (assq 'filladapt-mode minor-mode-alist)
+    (setq minor-mode-alist (cons (list 'filladapt-mode
+				       'filladapt-mode-line-string)
+				 minor-mode-alist)))
+
+(defcustom filladapt-token-table
+  '(
+    ;; this must be first
+    ("^" beginning-of-line)
+    ;; Included text in news or mail replies
+    (">+" citation->)
+    ;; Included text generated by SUPERCITE.  We can't hope to match all
+    ;; the possible variations, your mileage may vary.
+    ("[A-Za-z0-9][^'`\"< \t\n]*>[ \t]*" supercite-citation)
+    ;; Lisp comments
+    (";+" lisp-comment)
+    ;; UNIX shell comments
+    ("#+" sh-comment)
+    ;; Postscript comments
+    ("%+" postscript-comment)
+    ;; C++ comments
+    ("///*" c++-comment)
+    ;; Texinfo comments
+    ("@c[ \t]" texinfo-comment)
+    ("@comment[ \t]" texinfo-comment)
+    ;; Bullet types.
+    ;;
+    ;; LaTex \item
+    ;;
+    ("\\\\item[ \t]" bullet)
+    ;;
+    ;; 1. xxxxx
+    ;;    xxxxx
+    ;;
+    ("[0-9]+\\.[ \t]" bullet)
+    ;;
+    ;; 2.1.3  xxxxx xx x xx x
+    ;;        xxx
+    ;;
+    ("[0-9]+\\(\\.[0-9]+\\)+[ \t]" bullet)
+    ;;
+    ;; a. xxxxxx xx
+    ;;    xxx xxx
+    ;;
+    ("[A-Za-z]\\.[ \t]" bullet)
+    ;;
+    ;; 1) xxxx x xx x xx   or   (1) xx xx x x xx xx
+    ;;    xx xx xxxx                xxx xx x x xx x
+    ;;
+    ("(?[0-9]+)[ \t]" bullet)
+    ;;
+    ;; a) xxxx x xx x xx   or   (a) xx xx x x xx xx
+    ;;    xx xx xxxx                xxx xx x x xx x
+    ;;
+    ("(?[A-Za-z])[ \t]" bullet)
+    ;;
+    ;; 2a. xx x xxx x x xxx
+    ;;     xxx xx x xx x
+    ;;
+    ("[0-9]+[A-Za-z]\\.[ \t]" bullet)
+    ;;
+    ;; 1a) xxxx x xx x xx   or   (1a) xx xx x x xx xx
+    ;;     xx xx xxxx                 xxx xx x x xx x
+    ;;
+    ("(?[0-9]+[A-Za-z])[ \t]" bullet)
+    ;;
+    ;; -  xx xxx xxxx   or   *  xx xx x xxx xxx
+    ;;    xxx xx xx             x xxx x xx x x x
+    ;;
+    ("[-~*+]+[ \t]" bullet)
+    ;;
+    ;; o  xx xxx xxxx xx x xx xxx x xxx xx x xxx
+    ;;    xxx xx xx 
+    ;;
+    ("o[ \t]" bullet)
+    ;; don't touch
+    ("[ \t]+" space)
+    ("$" end-of-line)
+   )
+  "Table of tokens filladapt knows about.
+Format is
+
+   ((REGEXP SYM) ...)
+
+filladapt uses this table to build a tokenized representation of
+the beginning of the current line.  Each REGEXP is matched
+against the beginning of the line until a match is found.
+Matching is done case-sensitively.  The corresponding SYM is
+added to the list, point is moved to (match-end 0) and the
+process is repeated.  The process ends when there is no REGEXP in
+the table that matches what is at point."
+  :type '(repeat (list regexp symbol))
+  :group 'filladapt)
+
+(defcustom filladapt-not-token-table
+  '(
+    "[Ee].g."
+    "[Ii].e."
+    ;; end-of-line isn't a token if whole line is empty
+    "^$"
+   )
+  "List of regexps that can never be a token.
+Before trying the regular expressions in filladapt-token-table,
+the regexps in this list are tried.  If any regexp in this list
+matches what is at point then the token generator gives up and
+doesn't try any of the regexps in filladapt-token-table.
+
+Regexp matching is done case-sensitively."
+  :type '(repeat regexp)
+  :group 'filladapt)
+
+(defcustom filladapt-token-match-table
+  '(
+    (citation-> citation->)
+    (supercite-citation supercite-citation)
+    (lisp-comment lisp-comment)
+    (sh-comment sh-comment)
+    (postscript-comment postscript-comment)
+    (c++-comment c++-comment)
+    (texinfo-comment texinfo-comment)
+    (bullet)
+    (space bullet space)
+    (beginning-of-line beginning-of-line)
+   )
+  "Table describing what tokens a certain token will match.
+
+To decide whether a line belongs in the current paragraph,
+filladapt creates a token list for the fill prefix of both lines.
+Tokens and the columns where tokens end are compared.  This table
+specifies what a certain token will match.
+
+Table format is
+
+   (SYM [SYM1 [SYM2 ...]])
+
+The first symbol SYM is the token, subsequent symbols are the
+tokens that SYM will match."
+  :type '(repeat (repeat symbol))
+  :group 'filladapt)
+
+(defcustom filladapt-token-match-many-table
+  '(
+    space
+   )
+  "List of tokens that can match multiple tokens.
+If one of these tokens appears in a token list, it will eat all
+matching tokens in a token list being matched against it until it
+encounters a token that doesn't match or a token that ends on
+a greater column number."
+  :type '(repeat symbol)
+  :group 'filladapt)
+
+(defcustom filladapt-token-paragraph-start-table
+  '(
+    bullet
+   )
+  "List of tokens that indicate the start of a paragraph.
+If parsing a line generates a token list containing one of
+these tokens, then the line is considered to be the start of a
+paragraph."
+  :type '(repeat symbol)
+  :group 'filladapt)
+
+(defcustom filladapt-token-conversion-table
+  '(
+    (citation-> . exact)
+    (supercite-citation . exact)
+    (lisp-comment . exact)
+    (sh-comment . exact)
+    (postscript-comment . exact)
+    (c++-comment . exact)
+    (texinfo-comment . exact)
+    (bullet . spaces)
+    (space . exact)
+    (end-of-line . exact)
+   )
+  "Table that specifies how to convert a token into a fill prefix.
+Table format is
+
+   ((SYM . HOWTO) ...)
+
+SYM is the symbol naming the token to be converted.
+HOWTO specifies how to do the conversion.
+  `exact' means copy the token's string directly into the fill prefix.
+  `spaces' means convert all characters in the token string that are
+      not a TAB or a space into spaces and copy the resulting string into 
+      the fill prefix."
+  :type '(repeat (cons symbol (choice (const exact)
+				      (const spaces))))
+  :group 'filladapt)
+
+(defvar filladapt-function-table
+  (let ((assoc-list
+	 (list (cons 'fill-paragraph (symbol-function 'fill-paragraph))
+	       (cons 'fill-region (symbol-function 'fill-region))
+	       (cons 'fill-region-as-paragraph
+		     (symbol-function 'fill-region-as-paragraph))
+	       (cons 'do-auto-fill (symbol-function 'do-auto-fill)))))
+    ;; v18 Emacs doesn't have lisp-fill-paragraph
+    (if (fboundp 'lisp-fill-paragraph)
+	(nconc assoc-list
+	       (list (cons 'lisp-fill-paragraph
+			   (symbol-function 'lisp-fill-paragraph)))))
+    assoc-list )
+  "Table containing the old function definitions that filladapt usurps.")
+
+(defcustom filladapt-fill-paragraph-post-hook nil
+  "Hooks run after filladapt runs fill-paragraph."
+  :type 'hook
+  :group 'filladapt)
+
+(defvar filladapt-inside-filladapt nil
+  "Non-nil if the filladapt version of a fill function executing.
+Currently this is only checked by the filladapt version of
+fill-region-as-paragraph to avoid this infinite recursion:
+
+  fill-region-as-paragraph -> fill-paragraph -> fill-region-as-paragraph ...")
+
+(defcustom filladapt-debug nil
+  "Non-nil means filladapt debugging is enabled.
+Use the filladapt-debug command to turn on debugging.
+
+With debugging enabled, filladapt will
+
+    a. display the proposed indentation with the tokens highlighted
+       using filladapt-debug-indentation-face-1 and
+       filladapt-debug-indentation-face-2.
+    b. display the current paragraph using the face specified by
+       filladapt-debug-paragraph-face."
+  :type 'boolean
+  :group 'filladapt)
+
+(if filladapt-debug
+    (add-hook 'post-command-hook 'filladapt-display-debug-info-maybe))
+
+(defvar filladapt-debug-indentation-face-1 'highlight
+  "Face used to display the indentation when debugging is enabled.")
+
+(defvar filladapt-debug-indentation-face-2 'secondary-selection
+  "Another face used to display the indentation when debugging is enabled.")
+
+(defvar filladapt-debug-paragraph-face 'bold
+  "Face used to display the current paragraph when debugging is enabled.")
+
+(defvar filladapt-debug-indentation-extents nil)
+(make-variable-buffer-local 'filladapt-debug-indentation-extents)
+(defvar filladapt-debug-paragraph-extent nil)
+(make-variable-buffer-local 'filladapt-debug-paragraph-extent)
+
+;; kludge city, see references in code.
+(defvar filladapt-old-line-prefix)
+
+(defun do-auto-fill ()
+  (catch 'done
+    (if (and filladapt-mode (null fill-prefix))
+	(save-restriction
+	  (let ((paragraph-ignore-fill-prefix nil)
+		;; if the user wanted this stuff, they probably
+		;; wouldn't be using filladapt-mode.
+		(adaptive-fill-mode nil)
+		(adaptive-fill-regexp nil)
+		;; need this or Emacs 19 ignores fill-prefix when
+		;; inside a comment.
+		(comment-multi-line t)
+		(filladapt-inside-filladapt t)
+		fill-prefix retval)
+	    (if (filladapt-adapt nil nil)
+		(progn
+		  (setq retval (filladapt-funcall 'do-auto-fill))
+		  (throw 'done retval))))))
+    (filladapt-funcall 'do-auto-fill)))
+
+(defun filladapt-fill-paragraph (function arg)
+  (catch 'done
+    (if (and filladapt-mode (null fill-prefix))
+	(save-restriction
+	  (let ((paragraph-ignore-fill-prefix nil)
+		;; if the user wanted this stuff, they probably
+		;; wouldn't be using filladapt-mode.
+		(adaptive-fill-mode nil)
+		(adaptive-fill-regexp nil)
+		;; need this or Emacs 19 ignores fill-prefix when
+		;; inside a comment.
+		(comment-multi-line t)
+		fill-prefix retval)
+	    (if (filladapt-adapt t nil)
+		(progn
+		  (if filladapt-fill-column-tolerance
+		      (let* ((low (- fill-column
+				     filladapt-fill-column-backward-fuzz))
+			     (high (+ fill-column
+				      filladapt-fill-column-forward-fuzz))
+			     (old-fill-column fill-column)
+			     (fill-column fill-column)
+			     (lim (- high low))
+			     (done nil)
+			     (sign 1)
+			     (delta 0))
+			(while (not done)
+			  (setq retval (filladapt-funcall function arg))
+			  (if (filladapt-paragraph-within-fill-tolerance)
+			      (setq done 'success)
+			    (setq delta (1+ delta)
+				  sign (* sign -1)
+				  fill-column (+ fill-column (* delta sign)))
+			    (while (and (<= delta lim)
+					(or (< fill-column low)
+					    (> fill-column high)))
+			      (setq delta (1+ delta)
+				    sign (* sign -1)
+				    fill-column (+ fill-column
+						   (* delta sign))))
+			    (setq done (> delta lim))))
+			;; if the paragraph lines never fell
+			;; within the tolerances, refill using
+			;; the old fill-column.
+			(if (not (eq done 'success))
+			    (let ((fill-column old-fill-column))
+			      (setq retval (filladapt-funcall function arg)))))
+		    (setq retval (filladapt-funcall function arg)))
+		  (run-hooks 'filladapt-fill-paragraph-post-hook)
+		  (throw 'done retval))))))
+    ;; filladapt-adapt failed, so do fill-paragraph normally.
+    (filladapt-funcall function arg)))
+
+(defun fill-paragraph (arg)
+  "Fill paragraph at or after point.  Prefix arg means justify as well.
+
+(This function has been overloaded with the `filladapt' version.)
+
+If `sentence-end-double-space' is non-nil, then period followed by one
+space does not end a sentence, so don't break a line there.
+
+If `fill-paragraph-function' is non-nil, we call it (passing our
+argument to it), and if it returns non-nil, we simply return its value."
+  (interactive "*P")
+  (let ((filladapt-inside-filladapt t))
+    (filladapt-fill-paragraph 'fill-paragraph arg)))
+
+(defun lisp-fill-paragraph (&optional arg)
+  "Like \\[fill-paragraph], but handle Emacs Lisp comments.
+
+(This function has been overloaded with the `filladapt' version.)
+
+If any of the current line is a comment, fill the comment or the
+paragraph of it that point is in, preserving the comment's indentation
+and initial semicolons."
+  (interactive "*P")
+  (let ((filladapt-inside-filladapt t))
+    (filladapt-fill-paragraph 'lisp-fill-paragraph arg)))
+
+(defun fill-region-as-paragraph (beg end &optional justify
+				 nosqueeze squeeze-after)
+  "Fill the region as one paragraph.
+
+(This function has been overloaded with the `filladapt' version.)
+
+It removes any paragraph breaks in the region and extra newlines at the end,
+indents and fills lines between the margins given by the
+`current-left-margin' and `current-fill-column' functions.
+It leaves point at the beginning of the line following the paragraph.
+
+Normally performs justification according to the `current-justification'
+function, but with a prefix arg, does full justification instead.
+
+From a program, optional third arg JUSTIFY can specify any type of
+justification.  Fourth arg NOSQUEEZE non-nil means not to make spaces
+between words canonical before filling.  Fifth arg SQUEEZE-AFTER, if non-nil,
+means don't canonicalize spaces before that position.
+
+If `sentence-end-double-space' is non-nil, then period followed by one
+space does not end a sentence, so don't break a line there."
+  (interactive "*r\nP")
+  (if (and filladapt-mode (not filladapt-inside-filladapt))
+      (save-restriction
+	(narrow-to-region beg end)
+	(let ((filladapt-inside-filladapt t)
+	      line-start last-token)
+	  (goto-char beg)
+	  (while (equal (char-after (point)) ?\n)
+	    (delete-char 1))
+	  (end-of-line)
+	  (while (zerop (forward-line))
+	    (if (setq last-token
+		      (car (filladapt-tail (filladapt-parse-prefixes))))
+		(progn
+		  (setq line-start (point))
+		  (move-to-column (nth 1 last-token))
+		  (delete-region line-start (point))))
+	    ;; Dance...
+	    ;;
+	    ;; Do this instead of (delete-char -1) to keep
+	    ;; markers on the correct side of the whitespace.
+	    (goto-char (1- (point)))
+	    (insert " ")
+	    (delete-char 1)
+
+	    (end-of-line))
+	  (goto-char beg)
+	  (fill-paragraph justify))
+	;; In XEmacs 19.12 and Emacs 18.59 fill-region relies on
+	;; fill-region-as-paragraph to do this.  If we don't do
+	;; it, fill-region will spin in an endless loop.
+	(goto-char (point-max)))
+    (condition-case nil
+	;; five args for Emacs 19.31
+	(filladapt-funcall 'fill-region-as-paragraph beg end
+			   justify nosqueeze squeeze-after)
+      (wrong-number-of-arguments
+       (condition-case nil
+	   ;; four args for Emacs 19.29
+	   (filladapt-funcall 'fill-region-as-paragraph beg end
+			      justify nosqueeze)
+	 ;; three args for the rest of the world.
+	 (wrong-number-of-arguments
+	  (filladapt-funcall 'fill-region-as-paragraph beg end justify)))))))
+
+(defun fill-region (beg end &optional justify nosqueeze to-eop)
+  "Fill each of the paragraphs in the region.
+
+(This function has been overloaded with the `filladapt' version.)
+
+Prefix arg (non-nil third arg, if called from program) means justify as well.
+
+Noninteractively, fourth arg NOSQUEEZE non-nil means to leave
+whitespace other than line breaks untouched, and fifth arg TO-EOP
+non-nil means to keep filling to the end of the paragraph (or next
+hard newline, if `use-hard-newlines' is on).
+
+If `sentence-end-double-space' is non-nil, then period followed by one
+space does not end a sentence, so don't break a line there."
+  (interactive "*r\nP")
+  (if (and filladapt-mode (not filladapt-inside-filladapt))
+      (save-restriction
+	(narrow-to-region beg end)
+	(let ((filladapt-inside-filladapt t)
+	      start)
+	  (goto-char beg)
+	  (while (not (eobp))
+	    (setq start (point))
+	    (while (and (not (eobp)) (not (filladapt-parse-prefixes)))
+	      (forward-line 1))
+	    (if (not (equal start (point)))
+		(progn
+		  (save-restriction
+		    (narrow-to-region start (point))
+		    (fill-region start (point) justify nosqueeze to-eop)
+		    (goto-char (point-max)))
+		  (if (and (not (bolp)) (not (eobp)))
+		      (forward-line 1))))
+	    (if (filladapt-parse-prefixes)
+		(progn
+		  (save-restriction
+		    ;; for the clipping region
+		    (filladapt-adapt t t)
+		    (fill-paragraph justify)
+		    (goto-char (point-max)))
+		  (if (and (not (bolp)) (not (eobp)))
+		      (forward-line 1)))))))
+    (condition-case nil
+	(filladapt-funcall 'fill-region beg end justify nosqueeze to-eop)
+      (wrong-number-of-arguments
+       (condition-case nil
+	   (filladapt-funcall 'fill-region beg end justify nosqueeze)
+	 (wrong-number-of-arguments
+	  (filladapt-funcall 'fill-region beg end justify)))))))
+
+(defvar zmacs-region-stays) ; for XEmacs
+
+(defun filladapt-mode (&optional arg)
+  "Toggle Filladapt minor mode.
+With arg, turn Filladapt mode on iff arg is positive.  When
+Filladapt mode is enabled, auto-fill-mode and the fill-paragraph
+command are both smarter about guessing a proper fill-prefix and
+finding paragraph boundaries when bulleted and indented lines and
+paragraphs are used."
+  (interactive "P")
+  ;; don't deactivate the region.
+  (setq zmacs-region-stays t)
+  (setq filladapt-mode (or (and arg (> (prefix-numeric-value arg) 0))
+			   (and (null arg) (null filladapt-mode))))
+  (if (fboundp 'force-mode-line-update)
+      (force-mode-line-update)
+    (set-buffer-modified-p (buffer-modified-p))))
+
+(defun turn-on-filladapt-mode ()
+  "Unconditionally turn on Filladapt mode in the current buffer."
+  (filladapt-mode 1))
+
+(defun turn-off-filladapt-mode ()
+  "Unconditionally turn off Filladapt mode in the current buffer."
+  (filladapt-mode -1))
+
+(defun filladapt-funcall (function &rest args)
+  "Call the old definition of a function that filladapt has usurped."
+  (apply (cdr (assoc function filladapt-function-table)) args))
+
+(defun filladapt-paragraph-start (list)
+  "Returns non-nil if LIST contains a paragraph starting token.
+LIST should be a token list as returned by filladapt-parse-prefixes."
+  (catch 'done
+    (while list
+      (if (memq (car (car list)) filladapt-token-paragraph-start-table)
+	  (throw 'done t))
+      (setq list (cdr list)))))
+
+(defun filladapt-parse-prefixes ()
+  "Parse all the tokens after point and return a list of them.
+The tokens regular expressions are specified in
+filladapt-token-table.  The list returned is of this form
+
+  ((SYM COL STRING) ...)
+
+SYM is a token symbol as found in filladapt-token-table.
+COL is the column at which the token ended.
+STRING is the token's text."
+  (save-excursion
+    (let ((token-list nil)
+	  (done nil)
+	  (old-point (point))
+	  (case-fold-search nil)
+	  token-table not-token-table moved)
+      (catch 'done
+	(while (not done)
+	  (setq not-token-table filladapt-not-token-table)
+	  (while not-token-table
+	    (if (looking-at (car not-token-table))
+		(throw 'done t))
+	    (setq not-token-table (cdr not-token-table)))
+	  (setq token-table filladapt-token-table
+		done t)
+	  (while token-table
+	    (if (null (looking-at (car (car token-table))))
+		(setq token-table (cdr token-table))
+	      (goto-char (match-end 0))
+	      (setq token-list (cons (list (nth 1 (car token-table))
+					   (current-column)
+					   (buffer-substring
+					    (match-beginning 0)
+					    (match-end 0)))
+				     token-list)
+		    moved (not (eq (point) old-point))
+		    token-table (if moved nil (cdr token-table))
+		    done (not moved)
+		    old-point (point))))))
+      (nreverse token-list))))
+
+(defun filladapt-tokens-match-p (list1 list2)
+  "Compare two token lists and return non-nil if they match, nil otherwise.
+The lists are walked through in lockstep, comparing tokens.
+
+When two tokens A and B are compared, they are considered to
+match if
+
+    1. A appears in B's list of matching tokens or
+       B appears in A's list of matching tokens
+and
+    2. A and B both end at the same column
+         or
+       A can match multiple tokens and ends at a column > than B
+         or
+       B can match multiple tokens and ends at a column > than A
+
+In the case where the end columns differ the list pointer for the
+token with the greater end column is not moved forward, which
+allows its current token to be matched against the next token in
+the other list in the next iteration of the matching loop.
+
+All tokens must be matched in order for the lists to be considered
+matching."
+  (let ((matched t)
+	(done nil))
+    (while (and (not done) list1 list2)
+      (let* ((token1 (car (car list1)))
+	     (token1-matches-many-p
+	         (memq token1 filladapt-token-match-many-table))
+	     (token1-matches (cdr (assq token1 filladapt-token-match-table)))
+	     (token1-endcol (nth 1 (car list1)))
+	     (token2 (car (car list2)))
+	     (token2-matches-many-p
+	         (memq token2 filladapt-token-match-many-table))
+	     (token2-matches (cdr (assq token2 filladapt-token-match-table)))
+	     (token2-endcol (nth 1 (car list2)))
+	     (tokens-match (or (memq token1 token2-matches)
+			       (memq token2 token1-matches))))
+	(cond ((not tokens-match)
+	       (setq matched nil
+		     done t))
+	      ((and token1-matches-many-p token2-matches-many-p)
+	       (cond ((= token1-endcol token2-endcol)
+		      (setq list1 (cdr list1)
+			    list2 (cdr list2)))
+		     ((< token1-endcol token2-endcol)
+		      (setq list1 (cdr list1)))
+		     (t
+		      (setq list2 (cdr list2)))))
+	      (token1-matches-many-p
+	       (cond ((= token1-endcol token2-endcol)
+		      (setq list1 (cdr list1)
+			    list2 (cdr list2)))
+		     ((< token1-endcol token2-endcol)
+		      (setq matched nil
+			    done t))
+		     (t
+		      (setq list2 (cdr list2)))))
+	      (token2-matches-many-p
+	       (cond ((= token1-endcol token2-endcol)
+		      (setq list1 (cdr list1)
+			    list2 (cdr list2)))
+		     ((< token2-endcol token1-endcol)
+		      (setq matched nil
+			    done t))
+		     (t
+		      (setq list1 (cdr list1)))))
+	      ((= token1-endcol token2-endcol)
+	       (setq list1 (cdr list1)
+		     list2 (cdr list2)))
+	      (t
+	       (setq matched nil
+		     done t)))))
+    (and matched (null list1) (null list2)) ))
+
+(defun filladapt-make-fill-prefix (list)
+  "Build a fill-prefix for a token LIST.
+filladapt-token-conversion-table specifies how this is done."
+  (let ((prefix-list nil)
+	(conversion-spec nil))
+    (while list
+      (setq conversion-spec (cdr (assq (car (car list))
+				       filladapt-token-conversion-table)))
+      (cond ((eq conversion-spec 'spaces)
+	     (setq prefix-list
+		   (cons
+		    (filladapt-convert-to-spaces (nth 2 (car list)))
+		    prefix-list)))
+	    ((eq conversion-spec 'exact)
+	     (setq prefix-list
+		   (cons
+		    (nth 2 (car list))
+		    prefix-list))))
+      (setq list (cdr list)))
+    (apply (function concat) (nreverse prefix-list)) ))
+
+(defun filladapt-paragraph-within-fill-tolerance ()
+  (catch 'done
+    (save-excursion
+      (let ((low (- fill-column filladapt-fill-column-tolerance))
+	    (shortline nil))
+	(goto-char (point-min))
+	(while (not (eobp))
+	  (if shortline
+	      (throw 'done nil)
+	    (end-of-line)
+	    (setq shortline (< (current-column) low))
+	    (forward-line 1)))
+	t ))))
+
+(defun filladapt-convert-to-spaces (string)
+  "Return a copy of STRING, with all non-tabs and non-space changed to spaces."
+  (let ((i 0)
+	(space-list '(?\  ?\t))
+	(space ?\ )
+	(lim (length string)))
+    (setq string (copy-sequence string))
+    (while (< i lim)
+      (if (not (memq (aref string i) space-list))
+	  (aset string i space))
+      (setq i (1+ i)))
+    string ))
+
+(defun filladapt-adapt (paragraph debugging)
+  "Set fill-prefix based on the contents of the current line.
+
+If the first arg PARAGRAPH is non-nil, also set a clipping region
+around the current paragraph.
+
+If the second arg DEBUGGING is non-nil, don't do the kludge that's
+necessary to make certain paragraph fills work properly."
+  (save-excursion
+    (beginning-of-line)
+    (let ((token-list (filladapt-parse-prefixes))
+	  curr-list done)
+      (if (null token-list)
+	  nil
+	(setq fill-prefix (filladapt-make-fill-prefix token-list))
+	(if paragraph
+	    (let (beg end)
+	      (if (filladapt-paragraph-start token-list)
+		  (setq beg (point))
+		(save-excursion
+		  (setq done nil)
+		  (while (not done)
+		    (cond ((not (= 0 (forward-line -1)))
+			   (setq done t
+				 beg (point)))
+			  ((not (filladapt-tokens-match-p
+				 token-list
+				 (setq curr-list (filladapt-parse-prefixes))))
+			   (forward-line 1)
+			   (setq done t
+				 beg (point)))
+			  ((filladapt-paragraph-start curr-list)
+			   (setq done t
+				 beg (point)))))))
+	      (save-excursion
+		(setq done nil)
+		(while (not done)
+		  (cond ((not (= 0 (progn (end-of-line) (forward-line 1))))
+			 (setq done t
+			       end (point)))
+			((not (filladapt-tokens-match-p
+			       token-list
+			       (setq curr-list (filladapt-parse-prefixes))))
+			 (setq done t
+			       end (point)))
+			((filladapt-paragraph-start curr-list)
+			 (setq done t
+			       end (point))))))
+	      (narrow-to-region beg end)
+	      ;; Multiple spaces after the bullet at the start of
+	      ;; a hanging list paragraph get squashed by
+	      ;; fill-paragraph.  We kludge around this by
+	      ;; replacing the line prefix with the fill-prefix
+	      ;; used by the rest of the lines in the paragraph.
+	      ;; fill-paragraph will not alter the fill prefix so
+	      ;; we win.  The post hook restores the old line prefix
+	      ;; after fill-paragraph has been called.
+	      (if (and paragraph (not debugging))
+		  (let (col)
+		    (setq col (nth 1 (car (filladapt-tail token-list))))
+		    (goto-char (point-min))
+		    (move-to-column col)
+		    (setq filladapt-old-line-prefix
+			  (buffer-substring (point-min) (point)))
+		    (delete-region (point-min) (point))
+		    (insert fill-prefix)
+		    (add-hook 'filladapt-fill-paragraph-post-hook
+			      'filladapt-cleanup-kludge-at-point-min)))))
+	t ))))
+
+(defun filladapt-cleanup-kludge-at-point-min ()
+  "Cleanup the paragraph fill kludge.
+See filladapt-adapt."
+  (save-excursion
+    (goto-char (point-min))
+    (insert filladapt-old-line-prefix)
+    (delete-char (length fill-prefix))
+    (remove-hook 'filladapt-fill-paragraph-post-hook
+		 'filladapt-cleanup-kludge-at-point-min)))
+
+(defun filladapt-tail (list)
+  "Returns the last cons in LIST."
+  (if (null list)
+      nil
+    (while (consp (cdr list))
+      (setq list (cdr list)))
+    list ))
+
+(defun filladapt-delete-extent (e)
+  (if (fboundp 'delete-extent)
+      (delete-extent e)
+    (delete-overlay e)))
+
+(defun filladapt-make-extent (beg end)
+  (if (fboundp 'make-extent)
+      (make-extent beg end)
+    (make-overlay beg end)))
+
+(defun filladapt-set-extent-endpoints (e beg end)
+  (if (fboundp 'set-extent-endpoints)
+      (set-extent-endpoints e beg end)
+    (move-overlay e beg end)))
+
+(defun filladapt-set-extent-property (e prop val)
+  (if (fboundp 'set-extent-property)
+      (set-extent-property e prop val)
+    (overlay-put e prop val)))
+
+(defun filladapt-debug ()
+  "Toggle filladapt debugging on/off in the current buffer."
+;;  (interactive)
+  (make-local-variable 'filladapt-debug)
+  (setq filladapt-debug (not filladapt-debug))
+  (if (null filladapt-debug)
+      (progn
+	(mapcar (function (lambda (e) (filladapt-set-extent-endpoints e 1 1)))
+		filladapt-debug-indentation-extents)
+	(if filladapt-debug-paragraph-extent
+	    (progn
+	      (filladapt-delete-extent filladapt-debug-paragraph-extent)
+	      (setq filladapt-debug-paragraph-extent nil)))))
+  (add-hook 'post-command-hook 'filladapt-display-debug-info-maybe))
+
+(defun filladapt-display-debug-info-maybe ()
+  (cond ((null filladapt-debug) nil)
+	(fill-prefix nil)
+	(t
+	 (if (null filladapt-debug-paragraph-extent)
+	     (let ((e (filladapt-make-extent 1 1)))
+	       (filladapt-set-extent-property e 'detachable nil)
+	       (filladapt-set-extent-property e 'evaporate nil)
+	       (filladapt-set-extent-property e 'face
+					      filladapt-debug-paragraph-face)
+	       (setq filladapt-debug-paragraph-extent e)))
+	 (save-excursion
+	   (save-restriction
+	     (let ((ei-list filladapt-debug-indentation-extents)
+		   (ep filladapt-debug-paragraph-extent)
+		   (face filladapt-debug-indentation-face-1)
+		   fill-prefix token-list)
+	       (if (null (filladapt-adapt t t))
+		   (progn
+		     (filladapt-set-extent-endpoints ep 1 1)
+		     (while ei-list
+		       (filladapt-set-extent-endpoints (car ei-list) 1 1)
+		       (setq ei-list (cdr ei-list))))
+		 (filladapt-set-extent-endpoints ep (point-min) (point-max))
+		 (beginning-of-line)
+		 (setq token-list (filladapt-parse-prefixes))
+		 (message "(%s)" (mapconcat (function
+					   (lambda (q) (symbol-name (car q))))
+					  token-list
+					  " "))
+		 (while token-list
+		   (if ei-list
+		       (setq e (car ei-list)
+			     ei-list (cdr ei-list))
+		     (setq e (filladapt-make-extent 1 1))
+		     (filladapt-set-extent-property e 'detachable nil)
+		     (filladapt-set-extent-property e 'evaporate nil)
+		     (setq filladapt-debug-indentation-extents
+			   (cons e filladapt-debug-indentation-extents)))
+		   (filladapt-set-extent-property e 'face face)
+		   (filladapt-set-extent-endpoints e (point)
+						   (progn
+						     (move-to-column
+						      (nth 1
+							   (car token-list)))
+						     (point)))
+		   (if (eq face filladapt-debug-indentation-face-1)
+		       (setq face filladapt-debug-indentation-face-2)
+		     (setq face filladapt-debug-indentation-face-1))
+		   (setq token-list (cdr token-list)))
+		 (while ei-list
+		   (filladapt-set-extent-endpoints (car ei-list) 1 1)
+		   (setq ei-list (cdr ei-list))))))))))
+;;; hexl.el --- edit a file in a hex dump format using the hexl filter.
+
+;; Copyright (C) 1989, 1994 Free Software Foundation, Inc.
+
+;; Author: Keith Gabryelski <ag@wheaties.ai.mit.edu>
+;; Maintainer: FSF
+;; Keywords: data
+
+;; This file is part of XEmacs.
+
+;; XEmacs 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, or (at your option)
+;; any later version.
+
+;; XEmacs 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 XEmacs; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+;; 02111-1307, USA.
+
+;;; Synched up with: FSF 19.34.
+
+;;; Commentary:
+
+;; This package implements a major mode for editing binary files.  It uses
+;; a program called hexl, supplied with the GNU Emacs distribution, that
+;; can filter a binary into an editable format or from the format back into
+;; binary.  For full instructions, invoke `hexl-mode' on an empty buffer and
+;; do `M-x describe-mode'.
+;;
+;; This may be useful in your .emacs:
+;;
+;;	(autoload 'hexl-find-file "hexl"
+;;	  "Edit file FILENAME in hexl-mode." t)
+;;	
+;;	(define-key global-map "\C-c\C-h" 'hexl-find-file)
+;;
+;; NOTE: Remember to change HEXL-PROGRAM or HEXL-OPTIONS if needed.
+;;
+;; Currently hexl only supports big endian hex output with 16 bit
+;; grouping.
+;;
+;; -iso in `hexl-options' will allow iso characters to display in the
+;; ASCII region of the screen (if your emacs supports this) instead of
+;; changing them to dots.
+
+;;; Code:
+
+;;
+;; vars here
+;;
+
+(defvar hexl-program "hexl"
+  "The program that will hexlify and dehexlify its stdin.
+`hexl-program' will always be concatenated with `hexl-options'
+and \"-de\" when dehexlifying a buffer.")
+
+(defvar hexl-iso ""
+  "If your emacs can handle ISO characters, this should be set to
+\"-iso\" otherwise it should be \"\".")
+
+(defvar hexl-options (format "-hex %s" hexl-iso)
+  "Options to hexl-program that suit your needs.")
+
+(defvar hexlify-command
+  (format "%s%s %s" exec-directory hexl-program hexl-options)
+  "The command to use to hexlify a buffer.")
+
+(defvar dehexlify-command
+  (format "%s%s -de %s" exec-directory hexl-program hexl-options)
+  "The command to use to unhexlify a buffer.")
+
+(defvar hexl-max-address 0
+  "Maximum offset into hexl buffer.")
+
+(defvar hexl-mode-map nil)
+
+(defvar hexl-mode-old-local-map)
+(defvar hexl-mode-old-mode-name)
+(defvar hexl-mode-old-major-mode)
+(defvar hexl-mode-old-write-contents-hooks)
+(defvar hexl-mode-old-require-final-newline)
+(defvar hexl-mode-old-syntax-table)
+
+;; routines
+
+;;;###autoload
+(defun hexl-mode (&optional arg)
+  "\\<hexl-mode-map>
+A major mode for editing binary files in hex dump format.
+
+This function automatically converts a buffer into the hexl format
+using the function `hexlify-buffer'.
+
+Each line in the buffer has an \"address\" (displayed in hexadecimal)
+representing the offset into the file that the characters on this line
+are at and 16 characters from the file (displayed as hexadecimal
+values grouped every 16 bits) and as their ASCII values.
+
+If any of the characters (displayed as ASCII characters) are
+unprintable (control or meta characters) they will be replaced as
+periods.
+
+If `hexl-mode' is invoked with an argument the buffer is assumed to be
+in hexl format.
+
+A sample format:
+
+  HEX ADDR: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f     ASCII-TEXT
+  --------  ---- ---- ---- ---- ---- ---- ---- ----  ----------------
+  00000000: 5468 6973 2069 7320 6865 786c 2d6d 6f64  This is hexl-mod
+  00000010: 652e 2020 4561 6368 206c 696e 6520 7265  e.  Each line re
+  00000020: 7072 6573 656e 7473 2031 3620 6279 7465  presents 16 byte
+  00000030: 7320 6173 2068 6578 6164 6563 696d 616c  s as hexadecimal
+  00000040: 2041 5343 4949 0a61 6e64 2070 7269 6e74   ASCII.and print
+  00000050: 6162 6c65 2041 5343 4949 2063 6861 7261  able ASCII chara
+  00000060: 6374 6572 732e 2020 416e 7920 636f 6e74  cters.  Any cont
+  00000070: 726f 6c20 6f72 206e 6f6e 2d41 5343 4949  rol or non-ASCII
+  00000080: 2063 6861 7261 6374 6572 730a 6172 6520   characters.are 
+  00000090: 6469 7370 6c61 7965 6420 6173 2070 6572  displayed as per
+  000000a0: 696f 6473 2069 6e20 7468 6520 7072 696e  iods in the prin
+  000000b0: 7461 626c 6520 6368 6172 6163 7465 7220  table character 
+  000000c0: 7265 6769 6f6e 2e0a                      region..
+
+Movement is as simple as movement in a normal emacs text buffer.  Most
+cursor movement bindings are the same (ie. Use \\[hexl-backward-char], \\[hexl-forward-char], \\[hexl-next-line], and \\[hexl-previous-line]
+to move the cursor left, right, down, and up).
+
+Advanced cursor movement commands (ala \\[hexl-beginning-of-line], \\[hexl-end-of-line], \\[hexl-beginning-of-buffer], and \\[hexl-end-of-buffer]) are
+also supported.
+
+There are several ways to change text in hexl mode:
+
+ASCII characters (character between space (0x20) and tilde (0x7E)) are
+bound to self-insert so you can simply type the character and it will
+insert itself (actually overstrike) into the buffer.
+
+\\[hexl-quoted-insert] followed by another keystroke allows you to insert the key even if
+it isn't bound to self-insert.  An octal number can be supplied in place
+of another key to insert the octal number's ASCII representation.
+
+\\[hexl-insert-hex-char] will insert a given hexadecimal value (if it is between 0 and 0xFF)
+into the buffer at the current point.
+
+\\[hexl-insert-octal-char] will insert a given octal value (if it is between 0 and 0377)
+into the buffer at the current point.
+
+\\[hexl-insert-decimal-char] will insert a given decimal value (if it is between 0 and 255)
+into the buffer at the current point.
+
+\\[hexl-mode-exit] will exit hexl-mode.
+
+Note: saving the file with any of the usual Emacs commands
+will actually convert it back to binary format while saving.
+
+You can use \\[hexl-find-file] to visit a file in hexl-mode.
+
+\\[describe-bindings] for advanced commands."
+  (interactive "p")
+  (if (eq major-mode 'hexl-mode)
+      (error "You are already in hexl mode")
+
+    (let ((modified (buffer-modified-p))
+	  (inhibit-read-only t)
+	  (original-point (1- (point)))
+	  max-address)
+      (and (eobp) (not (bobp))
+	   (setq original-point (1- original-point)))
+      (if (not (or (eq arg 1) (not arg)))
+	  ;; if no argument then we guess at hexl-max-address
+	  (setq max-address (+ (* (/ (1- (buffer-size)) 68) 16) 15))
+	(setq max-address (1- (buffer-size)))
+	(hexlify-buffer)
+	(set-buffer-modified-p modified))
+      (make-local-variable 'hexl-max-address)
+      (setq hexl-max-address max-address)
+      (hexl-goto-address original-point))
+
+    ;; We do not turn off the old major mode; instead we just
+    ;; override most of it.  That way, we can restore it perfectly.
+    (make-local-variable 'hexl-mode-old-local-map)
+    (setq hexl-mode-old-local-map (current-local-map))
+    (use-local-map hexl-mode-map)
+
+    (make-local-variable 'hexl-mode-old-mode-name)
+    (setq hexl-mode-old-mode-name mode-name)
+    (setq mode-name "Hexl")
+
+    (make-local-variable 'hexl-mode-old-major-mode)
+    (setq hexl-mode-old-major-mode major-mode)
+    (setq major-mode 'hexl-mode)
+
+    (make-local-variable 'hexl-mode-old-syntax-table)
+    (setq hexl-mode-old-syntax-table (syntax-table))
+    (set-syntax-table (standard-syntax-table))
+
+    (make-local-variable 'hexl-mode-old-write-contents-hooks)
+    (setq hexl-mode-old-write-contents-hooks write-contents-hooks)
+    (make-local-variable 'write-contents-hooks)
+    (add-hook 'write-contents-hooks 'hexl-save-buffer)
+
+    (make-local-variable 'hexl-mode-old-require-final-newline)
+    (setq hexl-mode-old-require-final-newline require-final-newline)
+    (make-local-variable 'require-final-newline)
+    (setq require-final-newline nil)
+
+    ;; Add hooks to rehexlify or dehexlify on various events.
+    (make-local-hook 'after-revert-hook)
+    (add-hook 'after-revert-hook 'hexl-after-revert-hook nil t)
+
+    (make-local-hook 'change-major-mode-hook)
+    (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t))
+  (run-hooks 'hexl-mode-hook))
+
+(defun hexl-after-revert-hook ()
+  (hexlify-buffer)
+  (set-buffer-modified-p nil))
+
+(defvar hexl-in-save-buffer nil)
+
+(defun hexl-save-buffer ()
+  "Save a hexl format buffer as binary in visited file if modified."
+  (interactive)
+  (if hexl-in-save-buffer nil
+    (set-buffer-modified-p (if (buffer-modified-p)
+			       (save-excursion
+				 (let ((buf (generate-new-buffer " hexl"))
+				       (name (buffer-name))
+				       (file-name (buffer-file-name))
+				       (start (point-min))
+				       (end (point-max))
+				       modified)
+				   (set-buffer buf)
+				   (insert-buffer-substring name start end)
+				   (set-buffer name)
+				   (dehexlify-buffer)
+				   ;; Prevent infinite recursion.
+				   (let ((hexl-in-save-buffer t)
+					 (buffer-file-type t)) ; for ms-dos
+				     (save-buffer))
+				   (setq modified (buffer-modified-p))
+				   (delete-region (point-min) (point-max))
+				   (insert-buffer-substring buf start end)
+				   (kill-buffer buf)
+				   modified))
+			     (message "(No changes need to be saved)")
+			     nil))
+    ;; Return t to indicate we have saved t
+    t))
+
+;;;###autoload
+(defun hexl-find-file (filename)
+  "Edit file FILENAME in hexl-mode.
+Switch to a buffer visiting file FILENAME, creating one in none exists."
+  (interactive "fFilename: ")
+  (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
+      (find-file-binary filename)
+    (find-file filename))
+  (if (not (eq major-mode 'hexl-mode))
+      (hexl-mode)))
+
+(defun hexl-mode-exit (&optional arg)
+  "Exit Hexl mode, returning to previous mode.
+With arg, don't unhexlify buffer."
+  (interactive "p")
+  (if (or (eq arg 1) (not arg))
+      (let ((modified (buffer-modified-p))
+	    (inhibit-read-only t)
+	    (original-point (1+ (hexl-current-address))))
+	(dehexlify-buffer)
+	(remove-hook 'write-contents-hooks 'hexl-save-buffer)
+	(set-buffer-modified-p modified)
+	(goto-char original-point)))
+
+  (remove-hook 'after-revert-hook 'hexl-after-revert-hook t)
+  (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t)
+
+  (setq write-contents-hooks hexl-mode-old-write-contents-hooks)
+  (setq require-final-newline hexl-mode-old-require-final-newline)
+  (setq mode-name hexl-mode-old-mode-name)
+  (use-local-map hexl-mode-old-local-map)
+  (set-syntax-table hexl-mode-old-syntax-table)
+  (setq major-mode hexl-mode-old-major-mode)
+  (force-mode-line-update)
+  (run-hooks 'hexl-mode-exit-hook))
+
+(defun hexl-maybe-dehexlify-buffer ()
+  "Convert a hexl format buffer to binary.
+Ask the user for confirmation."
+  (if (y-or-n-p "Convert contents back to binary format? ")
+      (let ((modified (buffer-modified-p))
+	    (inhibit-read-only t)
+	    (original-point (1+ (hexl-current-address))))
+	(dehexlify-buffer)
+	(remove-hook 'write-contents-hooks 'hexl-save-buffer)
+	(set-buffer-modified-p modified)
+	(goto-char original-point))))
+
+(defun hexl-current-address (&optional validate)
+  "Return current hexl-address."
+  (interactive)
+  (let ((current-column (- (% (point) 68) 11)) 
+	(hexl-address 0))
+    (if (< current-column 0)
+	(if validate
+	    (error "Point is not on a character in the file")
+	  (setq current-column 0)))
+    (setq hexl-address
+	  (+ (* (/ (point) 68) 16)
+	     (if (>= current-column 41)
+		 (- current-column 41)
+	       (/ (- current-column  (/ current-column 5)) 2))))
+    hexl-address))
+
+(defun hexl-address-to-marker (address)
+  "Return marker for ADDRESS."
+  (interactive "nAddress: ")
+  (+ (* (/ address 16) 68) 11 (/ (* (% address 16) 5) 2)))
+
+(defun hexl-goto-address (address)
+  "Go to hexl-mode (decimal) address ADDRESS.
+Signal error if ADDRESS out of range."
+  (interactive "nAddress: ")
+  (if (or (< address 0) (> address hexl-max-address))
+	  (error "Out of hexl region."))
+  (goto-char (hexl-address-to-marker address)))
+
+(defun hexl-goto-hex-address (hex-address)
+  "Go to hexl-mode address (hex string) HEX-ADDRESS.
+Signal error if HEX-ADDRESS is out of range."
+  (interactive "sHex Address: ")
+  (hexl-goto-address (hexl-hex-string-to-integer hex-address)))
+
+(defun hexl-hex-string-to-integer (hex-string)
+  "Return decimal integer for HEX-STRING."
+  (interactive "sHex number: ")
+  (let ((hex-num 0))
+    (while (not (equal hex-string ""))
+      (setq hex-num (+ (* hex-num 16)
+		       (hexl-hex-char-to-integer (string-to-char hex-string))))
+      (setq hex-string (substring hex-string 1)))
+    hex-num))
+
+(defun hexl-octal-string-to-integer (octal-string)
+  "Return decimal integer for OCTAL-STRING."
+  (interactive "sOctal number: ")
+  (let ((oct-num 0))
+    (while (not (equal octal-string ""))
+      (setq oct-num (+ (* oct-num 8)
+		       (hexl-oct-char-to-integer
+			(string-to-char octal-string))))
+      (setq octal-string (substring octal-string 1)))
+    oct-num))
+
+;; move point functions
+
+(defun hexl-backward-char (arg)
+  "Move to left ARG bytes (right if ARG negative) in hexl-mode."
+  (interactive "p")
+  (hexl-goto-address (- (hexl-current-address) arg)))
+
+(defun hexl-forward-char (arg)
+  "Move right ARG bytes (left if ARG negative) in hexl-mode."
+  (interactive "p")
+  (hexl-goto-address (+ (hexl-current-address) arg)))
+
+(defun hexl-backward-short (arg)
+  "Move to left ARG shorts (right if ARG negative) in hexl-mode."
+  (interactive "p")
+  (hexl-goto-address (let ((address (hexl-current-address)))
+		       (if (< arg 0)
+			   (progn
+			     (setq arg (- arg))
+			     (while (> arg 0)
+			       (if (not (equal address (logior address 3)))
+				   (if (> address hexl-max-address)
+				       (progn
+					 (message "End of buffer.")
+					 (setq address hexl-max-address))
+				     (setq address (logior address 3)))
+				 (if (> address hexl-max-address)
+				     (progn
+				       (message "End of buffer.")
+				       (setq address hexl-max-address))
+				   (setq address (+ address 4))))
+			       (setq arg (1- arg)))
+			     (if (> address hexl-max-address)
+				 (progn
+				   (message "End of buffer.")
+				   (setq address hexl-max-address))
+			       (setq address (logior address 3))))
+			 (while (> arg 0)
+			   (if (not (equal address (logand address -4)))
+			       (setq address (logand address -4))
+			     (if (not (equal address 0))
+				 (setq address (- address 4))
+			       (message "Beginning of buffer.")))
+			   (setq arg (1- arg))))
+		       address)))
+
+(defun hexl-forward-short (arg)
+  "Move right ARG shorts (left if ARG negative) in hexl-mode."
+  (interactive "p")
+  (hexl-backward-short (- arg)))
+
+(defun hexl-backward-word (arg)
+  "Move to left ARG words (right if ARG negative) in hexl-mode."
+  (interactive "p")
+  (hexl-goto-address (let ((address (hexl-current-address)))
+		       (if (< arg 0)
+			   (progn
+			     (setq arg (- arg))
+			     (while (> arg 0)
+			       (if (not (equal address (logior address 7)))
+				   (if (> address hexl-max-address)
+				       (progn
+					 (message "End of buffer.")
+					 (setq address hexl-max-address))
+				     (setq address (logior address 7)))
+				 (if (> address hexl-max-address)
+				     (progn
+				       (message "End of buffer.")
+				       (setq address hexl-max-address))
+				   (setq address (+ address 8))))
+			       (setq arg (1- arg)))
+			     (if (> address hexl-max-address)
+				 (progn
+				   (message "End of buffer.")
+				   (setq address hexl-max-address))
+			       (setq address (logior address 7))))
+			 (while (> arg 0)
+			   (if (not (equal address (logand address -8)))
+			       (setq address (logand address -8))
+			     (if (not (equal address 0))
+				 (setq address (- address 8))
+			       (message "Beginning of buffer.")))
+			   (setq arg (1- arg))))
+		       address)))
+
+(defun hexl-forward-word (arg)
+  "Move right ARG words (left if ARG negative) in hexl-mode."
+  (interactive "p")
+  (hexl-backward-word (- arg)))
+
+(defun hexl-previous-line (arg)
+  "Move vertically up ARG lines [16 bytes] (down if ARG negative) in hexl-mode.
+If there is byte at the target address move to the last byte in that line."
+  (interactive "p")
+  (hexl-next-line (- arg)))
+
+(defun hexl-next-line (arg)
+  "Move vertically down ARG lines [16 bytes] (up if ARG negative) in hexl-mode.
+If there is no byte at the target address move to the last byte in that line."
+  (interactive "p")
+  (hexl-goto-address (let ((address (+ (hexl-current-address) (* arg 16))))
+		       (if (and (< arg 0) (< address 0))
+				(progn (message "Out of hexl region.")
+				       (setq address
+					     (% (hexl-current-address) 16)))
+			 (if (and (> address hexl-max-address)
+				  (< (% hexl-max-address 16) (% address 16)))
+			     (setq address hexl-max-address)
+			   (if (> address hexl-max-address)
+			       (progn (message "Out of hexl region.")
+				      (setq
+				       address
+				       (+ (logand hexl-max-address -16)
+					  (% (hexl-current-address) 16)))))))
+		       address)))
+
+(defun hexl-beginning-of-buffer (arg)
+  "Move to the beginning of the hexl buffer.
+Leaves `hexl-mark' at previous position.
+With prefix arg N, puts point N bytes of the way from the true beginning."
+  (interactive "p")
+  (push-mark (point))
+  (hexl-goto-address (+ 0 (1- arg))))
+
+(defun hexl-end-of-buffer (arg)
+  "Go to `hexl-max-address' minus ARG."
+  (interactive "p")
+  (push-mark (point))
+  (hexl-goto-address (- hexl-max-address (1- arg))))
+
+(defun hexl-beginning-of-line ()
+  "Goto beginning of line in hexl mode."
+  (interactive)
+  (goto-char (+ (* (/ (point) 68) 68) 11)))
+
+(defun hexl-end-of-line ()
+  "Goto end of line in hexl mode."
+  (interactive)
+  (hexl-goto-address (let ((address (logior (hexl-current-address) 15)))
+		       (if (> address hexl-max-address)
+			   (setq address hexl-max-address))
+		       address)))
+
+(defun hexl-scroll-down (arg)
+  "Scroll hexl buffer window upward ARG lines; or near full window if no ARG."
+  (interactive "P")
+  (if (null arg)
+      (setq arg (1- (window-height)))
+    (setq arg (prefix-numeric-value arg)))
+  (hexl-scroll-up (- arg)))
+
+(defun hexl-scroll-up (arg)
+  "Scroll hexl buffer window upward ARG lines; or near full window if no ARG."
+  (interactive "P")
+  (if (null arg)
+      (setq arg (1- (window-height)))
+    (setq arg (prefix-numeric-value arg)))
+  (let ((movement (* arg 16))
+	(address (hexl-current-address)))
+    (if (or (> (+ address movement) hexl-max-address)
+	    (< (+ address movement) 0))
+	(message "Out of hexl region.")
+      (hexl-goto-address (+ address movement))
+      (recenter 0))))
+
+(defun hexl-beginning-of-1k-page ()
+  "Go to beginning of 1k boundary."
+  (interactive)
+  (hexl-goto-address (logand (hexl-current-address) -1024)))
+
+(defun hexl-end-of-1k-page ()
+  "Go to end of 1k boundary."
+  (interactive)
+  (hexl-goto-address (let ((address (logior (hexl-current-address) 1023)))
+		       (if (> address hexl-max-address)
+			   (setq address hexl-max-address))
+		       address)))
+
+(defun hexl-beginning-of-512b-page ()
+  "Go to beginning of 512 byte boundary."
+  (interactive)
+  (hexl-goto-address (logand (hexl-current-address) -512)))
+
+(defun hexl-end-of-512b-page ()
+  "Go to end of 512 byte boundary."
+  (interactive)
+  (hexl-goto-address (let ((address (logior (hexl-current-address) 511)))
+		       (if (> address hexl-max-address)
+			   (setq address hexl-max-address))
+		       address)))
+
+(defun hexl-quoted-insert (arg)
+  "Read next input character and insert it.
+Useful for inserting control characters.
+You may also type up to 3 octal digits, to insert a character with that code"
+  (interactive "p")
+  (hexl-insert-char (read-quoted-char) arg))
+
+;00000000: 0011 2233 4455 6677 8899 aabb ccdd eeff  0123456789ABCDEF
+
+;;;###autoload
+(defun hexlify-buffer ()
+  "Convert a binary buffer to hexl format.
+This discards the buffer's undo information."
+  (interactive)
+  (and buffer-undo-list
+       (or (y-or-n-p "Converting to hexl format discards undo info; ok? ")
+	   (error "Aborted")))
+  (setq buffer-undo-list nil)
+  (let ((binary-process-output nil) ; for Ms-Dos
+	(binary-process-input t)
+	(buffer-undo-list t))
+    (shell-command-on-region (point-min) (point-max) hexlify-command t)))
+
+(defun dehexlify-buffer ()
+  "Convert a hexl format buffer to binary.
+This discards the buffer's undo information."
+  (interactive)
+  (and buffer-undo-list
+       (or (y-or-n-p "Converting from hexl format discards undo info; ok? ")
+	   (error "Aborted")))
+  (setq buffer-undo-list nil)
+  (let ((binary-process-output t) ; for Ms-Dos
+	(binary-process-input nil)
+	(buffer-undo-list t))
+    (shell-command-on-region (point-min) (point-max) dehexlify-command t)))
+
+(defun hexl-char-after-point ()
+  "Return char for ASCII hex digits at point."
+  (hexl-htoi (char-after (point))
+	     (char-after (1+ (point)))))
+
+(defun hexl-htoi (lh rh)
+  "Hex (char) LH (char) RH to integer."
+    (+ (* (hexl-hex-char-to-integer lh) 16)
+       (hexl-hex-char-to-integer rh)))
+
+(defun hexl-hex-char-to-integer (character)
+  "Take a char and return its value as if it was a hex digit."
+  (if (and (>= character ?0) (<= character ?9))
+      (- character ?0)
+    (let ((ch (logior character 32)))
+      (if (and (>= ch ?a) (<= ch ?f))
+	  (- ch (- ?a 10))
+	(error "Invalid hex digit `%c'." ch)))))
+
+(defun hexl-oct-char-to-integer (character)
+  "Take a char and return its value as if it was a octal digit."
+  (if (and (>= character ?0) (<= character ?7))
+      (- character ?0)
+    (error "Invalid octal digit `%c'." character)))
+
+(defun hexl-printable-character (ch)
+  "Return a displayable string for character CH."
+  (format "%c" (if hexl-iso
+		   (if (or (< ch 32) (and (>= ch 127) (< ch 160)))
+		       46
+		     ch)
+		 (if (or (< ch 32) (>= ch 127))
+		     46
+		   ch))))
+
+(defun hexl-self-insert-command (arg)
+  "Insert this character."
+  (interactive "p")
+  (hexl-insert-char last-command-char arg))
+
+(defun hexl-insert-char (ch num)
+  "Insert a character in a hexl buffer."
+  (let ((address (hexl-current-address t)))
+    (while (> num 0)
+      (let ((hex-position
+	     (+ (* (/ address 16) 68)
+		11
+		(* 2 (% address 16))
+		(/ (% address 16) 2)))
+	    (ascii-position
+	     (+ (* (/ address 16) 68) 52 (% address 16)))
+	    at-ascii-position)
+	(if (= (point) ascii-position)
+	    (setq at-ascii-position t))
+	(goto-char hex-position)
+	(delete-char 2)
+	(insert (format "%02x" ch))
+	(goto-char ascii-position)
+	(delete-char 1)
+	(insert (hexl-printable-character ch))
+	(or (eq address hexl-max-address)
+	    (setq address (1+ address)))
+	(hexl-goto-address address)
+	(if at-ascii-position
+	    (progn
+	      (beginning-of-line)
+	      (forward-char 51)
+	      (forward-char (% address 16)))))
+      (setq num (1- num)))))
+
+;; hex conversion
+
+(defun hexl-insert-hex-char (arg)
+  "Insert a ASCII char ARG times at point for a given hexadecimal number."
+  (interactive "p")
+  (let ((num (hexl-hex-string-to-integer (read-string "Hex number: "))))
+    (if (or (> num 255) (< num 0))
+	(error "Hex number out of range.")
+      (hexl-insert-char num arg))))
+
+(defun hexl-insert-decimal-char (arg)
+  "Insert a ASCII char ARG times at point for a given decimal number."
+  (interactive "p")
+  (let ((num (string-to-int (read-string "Decimal Number: "))))
+    (if (or (> num 255) (< num 0))
+	(error "Decimal number out of range.")
+      (hexl-insert-char num arg))))
+
+(defun hexl-insert-octal-char (arg)
+  "Insert a ASCII char ARG times at point for a given octal number."
+  (interactive "p")
+  (let ((num (hexl-octal-string-to-integer (read-string "Octal Number: "))))
+    (if (or (> num 255) (< num 0))
+	(error "Decimal number out of range.")
+      (hexl-insert-char num arg))))
+
+;; startup stuff.
+
+(if hexl-mode-map
+    nil
+  (setq hexl-mode-map (make-sparse-keymap))
+
+  (define-key hexl-mode-map [left] 'hexl-backward-char)
+  (define-key hexl-mode-map [right] 'hexl-forward-char)
+  (define-key hexl-mode-map [up] 'hexl-previous-line)
+  (define-key hexl-mode-map [down] 'hexl-next-line)
+  (define-key hexl-mode-map [(meta left)] 'hexl-backward-short)
+  (define-key hexl-mode-map [(meta right)] 'hexl-forward-short)
+  (define-key hexl-mode-map [next] 'hexl-scroll-up)
+  (define-key hexl-mode-map [prior] 'hexl-scroll-down)
+  (define-key hexl-mode-map [home] 'hexl-beginning-of-buffer)
+  (define-key hexl-mode-map [deletechar] 'undefined)
+  (define-key hexl-mode-map [deleteline] 'undefined)
+  (define-key hexl-mode-map [insertline] 'undefined)
+  (define-key hexl-mode-map [(shift backspace)] 'undefined)
+  (define-key hexl-mode-map [(shift delete)] 'undefined)
+  (define-key hexl-mode-map 'backspace 'undefined)
+  (define-key hexl-mode-map 'delete 'undefined)
+
+  (define-key hexl-mode-map "\C-a" 'hexl-beginning-of-line)
+  (define-key hexl-mode-map "\C-b" 'hexl-backward-char)
+  (define-key hexl-mode-map "\C-d" 'undefined)
+  (define-key hexl-mode-map "\C-e" 'hexl-end-of-line)
+  (define-key hexl-mode-map "\C-f" 'hexl-forward-char)
+
+  (if (not (eq (key-binding (vector help-char)) 'help-command))
+      (define-key hexl-mode-map (vector help-char) 'undefined))
+
+  (define-key hexl-mode-map "\C-i" 'hexl-self-insert-command)
+  (define-key hexl-mode-map "\C-j" 'hexl-self-insert-command)
+  (define-key hexl-mode-map "\C-k" 'undefined)
+  (define-key hexl-mode-map "\C-m" 'hexl-self-insert-command)
+  (define-key hexl-mode-map "\C-n" 'hexl-next-line)
+  (define-key hexl-mode-map "\C-o" 'undefined)
+  (define-key hexl-mode-map "\C-p" 'hexl-previous-line)
+  (define-key hexl-mode-map "\C-q" 'hexl-quoted-insert)
+  (define-key hexl-mode-map "\C-t" 'undefined)
+  (define-key hexl-mode-map "\C-v" 'hexl-scroll-up)
+  (define-key hexl-mode-map "\C-w" 'undefined)
+  (define-key hexl-mode-map "\C-y" 'undefined)
+
+  (let ((ch 32))
+    (while (< ch 127)
+      (define-key hexl-mode-map (format "%c" ch) 'hexl-self-insert-command)
+      (setq ch (1+ ch))))
+
+  (define-key hexl-mode-map "\e\C-a" 'hexl-beginning-of-512b-page)
+  (define-key hexl-mode-map "\e\C-b" 'hexl-backward-short)
+  (define-key hexl-mode-map "\e\C-c" 'undefined)
+  (define-key hexl-mode-map "\e\C-d" 'hexl-insert-decimal-char)
+  (define-key hexl-mode-map "\e\C-e" 'hexl-end-of-512b-page)
+  (define-key hexl-mode-map "\e\C-f" 'hexl-forward-short)
+  (define-key hexl-mode-map "\e\C-g" 'undefined)
+  (define-key hexl-mode-map "\e\C-h" 'undefined)
+  (define-key hexl-mode-map "\e\C-i" 'undefined)
+  (define-key hexl-mode-map "\e\C-j" 'undefined)
+  (define-key hexl-mode-map "\e\C-k" 'undefined)
+  (define-key hexl-mode-map "\e\C-l" 'undefined)
+  (define-key hexl-mode-map "\e\C-m" 'undefined)
+  (define-key hexl-mode-map "\e\C-n" 'undefined)
+  (define-key hexl-mode-map "\e\C-o" 'hexl-insert-octal-char)
+  (define-key hexl-mode-map "\e\C-p" 'undefined)
+  (define-key hexl-mode-map "\e\C-q" 'undefined)
+  (define-key hexl-mode-map "\e\C-r" 'undefined)
+  (define-key hexl-mode-map "\e\C-s" 'undefined)
+  (define-key hexl-mode-map "\e\C-t" 'undefined)
+  (define-key hexl-mode-map "\e\C-u" 'undefined)
+
+  (define-key hexl-mode-map "\e\C-w" 'undefined)
+  (define-key hexl-mode-map "\e\C-x" 'hexl-insert-hex-char)
+  (define-key hexl-mode-map "\e\C-y" 'undefined)
+
+  (define-key hexl-mode-map "\ea" 'undefined)
+  (define-key hexl-mode-map "\eb" 'hexl-backward-word)
+  (define-key hexl-mode-map "\ec" 'undefined)
+  (define-key hexl-mode-map "\ed" 'undefined)
+  (define-key hexl-mode-map "\ee" 'undefined)
+  (define-key hexl-mode-map "\ef" 'hexl-forward-word)
+  (define-key hexl-mode-map "\eg" 'hexl-goto-hex-address)
+  (define-key hexl-mode-map "\eh" 'undefined)
+  (define-key hexl-mode-map "\ei" 'undefined)
+  (define-key hexl-mode-map "\ej" 'hexl-goto-address)
+  (define-key hexl-mode-map "\ek" 'undefined)
+  (define-key hexl-mode-map "\el" 'undefined)
+  (define-key hexl-mode-map "\em" 'undefined)
+  (define-key hexl-mode-map "\en" 'undefined)
+  (define-key hexl-mode-map "\eo" 'undefined)
+  (define-key hexl-mode-map "\ep" 'undefined)
+  (define-key hexl-mode-map "\eq" 'undefined)
+  (define-key hexl-mode-map "\er" 'undefined)
+  (define-key hexl-mode-map "\es" 'undefined)
+  (define-key hexl-mode-map "\et" 'undefined)
+  (define-key hexl-mode-map "\eu" 'undefined)
+  (define-key hexl-mode-map "\ev" 'hexl-scroll-down)
+  (define-key hexl-mode-map "\ey" 'undefined)
+  (define-key hexl-mode-map "\ez" 'undefined)
+  (define-key hexl-mode-map "\e<" 'hexl-beginning-of-buffer)
+  (define-key hexl-mode-map "\e>" 'hexl-end-of-buffer)
+
+  (define-key hexl-mode-map "\C-c\C-c" 'hexl-mode-exit)
+
+  (define-key hexl-mode-map "\C-x[" 'hexl-beginning-of-1k-page)
+  (define-key hexl-mode-map "\C-x]" 'hexl-end-of-1k-page)
+  (define-key hexl-mode-map "\C-x\C-p" 'undefined)
+  (define-key hexl-mode-map "\C-x\C-s" 'hexl-save-buffer)
+  (define-key hexl-mode-map "\C-x\C-t" 'undefined))
+
+;;; hexl.el ends here
+;;; image-mode.el --- Major mode for navigate images
+
+;; Copyright (C) 1997 MORIOKA Tomohiko
+
+;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;; Created: 1997/6/27
+;; Version: image-mode.el,v 20.3.1.2 1997/07/01 17:29:44 morioka Exp
+;; Keywords: image, graphics
+
+;; This file is part of XEmacs.
+
+;; XEmacs 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, or (at your option)
+;; any later version.
+
+;; XEmacs 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 XEmacs; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+;; 02111-1307, USA.
+
+;;; Code:
+
+(defvar buffer-image-format nil)
+(make-variable-buffer-local 'buffer-image-format)
+
+(defsubst image-decode (start end type)
+  "Decode the image between START and END which is encoded in TYPE."
+  (save-excursion
+    (let ((image (make-image-instance
+		  (vector type :data (buffer-string)) nil nil 'no-error)))
+      (delete-region start end)
+      (if image
+	  (let ((glyph (make-glyph image)))
+	    (set-extent-begin-glyph (make-extent start start) glyph)
+	    (setq buffer-read-only t)
+	    )
+	(insert (format "%s is not supported!\n" type))
+	(let ((overriding-local-map image-mode-map))
+	  (insert
+	   (substitute-command-keys
+	    "
+Please type `\\[image-toggle-decoding]' if you would like to display
+raw data.
+Please type `\\[image-enter-hexl-mode]' if you would like to edit hex
+data.
+Please type `\\[image-enter-xpm-mode]' if you would like to edit xpm
+data.
+Please type `\\[image-start-external-viewer]' if you would like to
+display contents of this buffer by external viewer.\n")))
+	(call-interactively 'fill-paragraph)
+	)
+      start)))
+
+(defvar image-mode-map (make-keymap))
+(suppress-keymap image-mode-map)
+(define-key image-mode-map "v" 'image-start-external-viewer)
+(define-key image-mode-map "t" 'image-toggle-decoding)
+(define-key image-mode-map "h" 'image-enter-hexl-mode)
+(define-key image-mode-map "e" 'image-enter-xpm-mode)
+(define-key image-mode-map "q" 'image-mode-quit)
+
+(defvar image-external-viewer
+  (cond ((exec-installed-p "display")	 "display")	; ImageMagic
+	((exec-installed-p "xv")	 "xv")		; xv
+	)
+  "*External viewer for image-mode.")
+
+(defun image-start-external-viewer ()
+  "Start external image viewer for current-buffer.
+It uses `image-external-viewer' as external image viewer."
+  (interactive)
+  (start-process "external image viewer" nil
+		 image-external-viewer buffer-file-name)
+  )
+
+(defun image-toggle-decoding ()
+  "Toggle image display mode in current buffer."
+  (interactive)
+  (if buffer-file-format
+      (progn