home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / tpu-edt-3.0 / tpu-edt-history.el < prev    next >
Encoding:
Text File  |  1993-06-24  |  7.3 KB  |  202 lines

  1. ;;; tpu-edt-history.el --- gmhistification of TPU-edt
  2.  
  3. ;; Copyright (C) 1993 Rob Riepel.
  4.  
  5. ;; Author: Rob Riepel <riepel@networking.stanford.edu>
  6. ;; Maintainer: Rob Riepel <riepel@networking.stanford.edu>
  7. ;; Keywords: tpu-edt gmhist
  8.  
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  11. ;; accepts responsibility to anyone for the consequences of using it
  12. ;; or for whether it serves any particular purpose or works at all,
  13. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  14. ;; License for full details.
  15.  
  16. ;; Everyone is granted permission to copy, modify and redistribute
  17. ;; GNU Emacs, but only under the conditions described in the
  18. ;; GNU Emacs General Public License.   A copy of this license is
  19. ;; supposed to have been given to you along with GNU Emacs so you
  20. ;; can know your rights and responsibilities.  It should be in a
  21. ;; file named COPYING.  Among other things, the copyright notice
  22. ;; and this notice must be preserved on all copies.
  23. ;;
  24.  
  25. ;;; Revision: $Id: tpu-edt-history.el,v 2.2 1993/06/20 19:25:40 riepel Exp $
  26.  
  27. ;;; Commentary:
  28.  
  29. ;; TPU-edt History only applies to GNU emacs version 18!
  30.  
  31. ;;  This file implements minibuffer history recall on strings, file names,
  32. ;;  and commands for TPU-edt.  The affected functions are:
  33.  
  34. ;;       SEARCH and REPLACE   share a common string history
  35. ;;       GET and INCLUDE      share a common file name history
  36. ;;       ADD-AT-BOL           uses an independent string history
  37. ;;       ADD-AT-EOL           uses an independent string history
  38.  
  39. ;;  Also, the DO key and Gold-KP7 combination are mapped to the gmhist
  40. ;;  function gmhist-execute-extended-command, which provides command
  41. ;;  recall from the M-x prompt.
  42.  
  43. ;;; Usage:
  44.  
  45. ;;  The gmhist package is required for activation of the history recall
  46. ;;  mechanism.  Gmhist is a generic minibuffer history package written by
  47. ;;  Sebastian Kremer.  The package is available for anonymous ftp in the
  48. ;;  USA from:
  49.  
  50. ;;       ftp.cs.buffalo.edu:pub/Emacs/gmhist.tar.Z
  51.  
  52. ;;  Or from Sebastion's own site in Germany:
  53.  
  54. ;;       ftp.thp.uni-koeln.de:pub/gnu/emacs/gmhist.tar.Z
  55.  
  56. ;;  If you experience timeouts with that host, try
  57.  
  58. ;;       ftp.uni-koeln.de:pub/gnu/emacs/gmhist.tar.Z
  59.  
  60. ;;  The necessary parts of gmhist also come with Sebastian's tree dired
  61. ;;  package, found in the file diredall.tar.Z on the same ftp servers.
  62. ;;  If you already have tree dired, you don't need to fetch gmhist.
  63.  
  64. ;;  Make sure you have an up to date version.  TPU-edt history recall
  65. ;;  was developed using the following versions of the gmhist files.
  66.  
  67. ;;       gmhist.el      Revision 4.27  1992/04/20 17:17:47  sk RelBeta
  68. ;;       gmhist-app.el  Revision 4.16  1992/02/26 14:32:27  sk RelBeta
  69.  
  70. ;;  Once you have the gmhist package, make sure that this file and the
  71. ;;  gmhist*.el(c) files are in your load path.  Then modify your .emacs
  72. ;;  file to load this file after TPU-edt has been loaded.  For example:
  73.  
  74. ;;       (load "tpu-edt")                   ; Load the base TPU-edt,
  75. ;;       (load "tpu-edt-history")           ;   and add history recall.
  76.  
  77. ;;  If you're already using gmhist, just load this file after your own
  78. ;;  gmhist setup or in your gmhist-load-hook (note that this file loads
  79. ;;  gmhist-app).  It will make the modifications to TPU-edt without
  80. ;;  molesting your customizations.
  81.  
  82. ;;  Finally, note that it is safe to load this file even if gmhist is not
  83. ;;  available.  Of course, no minibuffer history functions will be enabled.
  84.  
  85. ;;; Known Problems:
  86.  
  87. ;;  Some TPU-edt commands contain spaces -- "what line" and "set scroll
  88. ;;  margins" for example.  The gmhist routine that reads line mode commands
  89. ;;  does not work with such commands.  The work-around is to use the emacs
  90. ;;  version of the command.  Each TPU-edt command that contains spaces has
  91. ;;  an alias of the form tpu-<command with spaces replaced by dashes>.  For
  92. ;;  example, "what line" can be invoked with the command tpu-what-line.
  93.  
  94. ;;; Code:
  95.  
  96.  
  97. ;;; TPU-edt History only applies to GNU emacs version 18!
  98.  
  99. (cond
  100.  ((not tpu-emacs19-p)
  101.  
  102.   ;;  Revision Information
  103.  
  104.   (defconst tpu-history-revision "$Revision: 2.2 $"
  105.     "Revision number of TPU-edt histification.")
  106.  
  107.  
  108.   ;; Global variables
  109.  
  110.   (defvar tpu-gmhistified nil
  111.     "If non-nil, TPU-edt has been gmhistified.")
  112.  
  113.  
  114.   ;; Replace the regular expression and string prompt function.
  115.  
  116.   (defun tpu-regexp-prompt (prompt)
  117.     "Read a string, adding 'RE' to the prompt if tpu-regexp-p is set."
  118.     (if (featurep 'gmhist)
  119.     (read-with-history-in 'tpu-regexp-prompt-hist
  120.                   (concat (if tpu-regexp-p "RE ") prompt))
  121.       (read-string (concat (if tpu-regexp-p "RE ") prompt))))
  122.  
  123.   (defun tpu-string-prompt (prompt history-symbol)
  124.     "Read a string with PROMPT and history HISTORY-SYMBOL."
  125.     (if (featurep 'gmhist)
  126.     (read-with-history-in history-symbol prompt)
  127.       (read-string prompt)))
  128.  
  129.  
  130.   ;; Commands to run if gmhist is available, and after it is loaded.
  131.  
  132.   (defun tpu-gmhist-hook nil
  133.     "Set up gmhist history symbols and key mappings."
  134.  
  135.     ;; Indicate that we've tried to gmhistify.
  136.     (setq tpu-gmhistified t)
  137.  
  138.     ;; prompt for string searches and replacements
  139.     (put 'tpu-regexp-prompt-hist 'no-default t)
  140.     (put 'tpu-regexp-prompt-hist 'cursor-end t)
  141.  
  142.     ;; prompt for adding strings at bol
  143.     (put 'tpu-add-at-bol-hist 'no-default t)
  144.     (put 'tpu-add-at-bol-hist 'cursor-end t)
  145.  
  146.     ;; prompt for adding strings at eol
  147.     (put 'tpu-add-at-eol-hist 'no-default t)
  148.     (put 'tpu-add-at-eol-hist 'cursor-end t)
  149.  
  150.     ;; prompt for file names to include or get
  151.     (gmhist-make-magic 'tpu-include 'tpu-file-name-hist)
  152.     (gmhist-make-magic 'tpu-get 'tpu-file-name-hist)
  153.     (put 'tpu-file-name-hist 'no-default t)
  154.     (put 'tpu-file-name-hist 'cursor-end t)
  155.  
  156.     ;; file name hack for VMS versions of GNU emacs.
  157.     (and (string= (symbol-value 'system-type) "vax-vms")
  158.      (fset 'gmhist-quote-dollars (symbol-function 'identity)))
  159.  
  160.     ;; Make up and down arrows recall commands and strings
  161.  
  162.     (let ((loc (where-is-internal 'tpu-previous-line)) (cur nil))
  163.       (while (setq cur (car loc))
  164.     (define-key gmhist-map cur 'gmhist-previous)
  165.     (define-key gmhist-completion-map cur 'gmhist-previous)
  166.     (define-key gmhist-must-match-map cur 'gmhist-previous)
  167.     (setq loc (cdr loc)))
  168.  
  169.       (setq loc (where-is-internal 'tpu-next-line))
  170.       (while (setq cur (car loc))
  171.     (define-key gmhist-map cur 'gmhist-next)
  172.     (define-key gmhist-completion-map cur 'gmhist-next)
  173.     (define-key gmhist-must-match-map cur 'gmhist-next)
  174.     (setq loc (cdr loc))))
  175.  
  176.     ;; If gmhist-app is available, make up and down arrows recall
  177.     ;; commands.    While we're at it, try to leave M-x alone.
  178.  
  179.     (cond ((load "gmhist-app" t t)
  180.        (let ((loc (where-is-internal 'execute-extended-command)) (cur nil))
  181.          (while (setq cur (car loc))
  182.            (if (not (equal cur "\ex"))
  183.            (global-set-key cur 'gmhist-execute-extended-command))
  184.            (setq loc (cdr loc)))))))
  185.  
  186.  
  187.   ;; If gmhist is already loaded, run the TPU-edt gmhist setup function,
  188.   ;; otherwise, attempt to load it, and if that suceeds, run the TPU-edt
  189.   ;; gmhist setup function.  Either way, don't complain if gmhist isn't
  190.   ;; available.
  191.  
  192.   (defun tpu-gmhistify nil
  193.     "gmhistify TPU-edt functions."
  194.     (interactive)
  195.     (if (featurep 'gmhist) (tpu-gmhist-hook)
  196.       (if (load "gmhist" t t) (tpu-gmhist-hook))))
  197.  
  198.   ;; gmhistify if we're not already
  199.   (if (not tpu-gmhistified) (tpu-gmhistify))))
  200.  
  201. ;;; tpu-edt-history.el ends here
  202.