home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / S-mode / comint-extra.el < prev    next >
Encoding:
Text File  |  1992-05-25  |  2.8 KB  |  75 lines

  1. ;;; -*-Emacs-Lisp-*- General command interpreter in a window stuff
  2. ;;; Copyright Olin Shivers (1988).
  3. ;;; Please imagine a long, tedious, legalistic 5-page gnu-style copyright
  4. ;;; notice appearing here to the effect that you may use this code any
  5. ;;; way you like, as long as you don't charge money for it, remove this
  6. ;;; notice, or hold me liable for its results.
  7.  
  8. ;;; The changelog is at the end of this file.
  9.  
  10. ;;; Please send me bug reports, bug fixes, and extensions, so that I can
  11. ;;; merge them into the master source.
  12. ;;;     - Olin Shivers (shivers@cs.cmu.edu)
  13.  
  14. ;;; These are the less-commonly-used functions from comint.el
  15.  
  16. (require 'comint)
  17. (provide 'comint-extra)
  18.  
  19. (defun comint-psearch-input ()
  20.   "Search forwards for next occurrence of prompt and skip to end of line.
  21. \(prompt is anything matching regexp comint-prompt-regexp)"
  22.   (interactive)
  23.   (if (re-search-forward comint-prompt-regexp (point-max) t)
  24.       (end-of-line)
  25.       (error "No occurrence of prompt found")))
  26.  
  27. (defun comint-msearch-input ()
  28.   "Search backwards for previous occurrence of prompt and skip to end of line.
  29. Search starts from beginning of current line."
  30.   (interactive)
  31.   (let ((p (save-excursion
  32.          (beginning-of-line)
  33.          (cond ((re-search-backward comint-prompt-regexp (point-min) t)
  34.             (end-of-line)
  35.             (point))
  36.            (t nil)))))
  37.     (if p (goto-char p)
  38.     (error "No occurrence of prompt found"))))
  39.  
  40. (defun comint-msearch-input-matching (str)
  41.   "Search backwards for occurrence of prompt followed by STRING.
  42. STRING is prompted for, and is NOT a regular expression."
  43.   (interactive (let ((s (read-from-minibuffer 
  44.              (format "Command (default %s): "
  45.                  comint-last-input-match))))
  46.          (list (if (string= s "") comint-last-input-match s))))
  47. ; (interactive "sCommand: ")
  48.   (setq comint-last-input-match str) ; update default
  49.   (let* ((r (concat comint-prompt-regexp (regexp-quote str)))
  50.      (p (save-excursion
  51.           (beginning-of-line)
  52.           (cond ((re-search-backward r (point-min) t)
  53.              (end-of-line)
  54.              (point))
  55.             (t nil)))))
  56.     (if p (goto-char p)
  57.     (error "No match"))))
  58.  
  59. (defun comint-next-similar-input (arg)
  60.   "Reenters the next input that matches the string typed so far.  If repeated 
  61. successively newer inputs are reentered.  If arg is -1, it will go back
  62. in the history, if 1 it will go forward."
  63.   (interactive "p")
  64.   (setq this-command 'comint-previous-similar-input)
  65.   (comint-previous-similar-input (- arg)))
  66.  
  67. ;;; Change log:
  68. ;;; 31/3/92 Dave Smith dsmith@stats.adelaude.edu.au
  69. ;;;  - Created this file. It currently comprises the deprecated functions
  70. ;;;    from version 2.03 of comint.el which I happened to like. It is
  71. ;;;    currently the user's job to load this file when required, but maybe
  72. ;;;    comint.el could handle it with autoloads.
  73. ;;;  - Added comint-next-similar-input, ideal for binding to an arrow key.
  74.  
  75.