[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: clearing buffer

From: Noah Friedman
Subject: Re: clearing buffer
Date: Mon, 09 Jul 2001 13:05:15 -0700 (PDT)

Here's what I use.  It deletes everything up to (but not including) the
most recent prompt.  In particular, commands which have been typed but not
yet executed, are not deleted.

This is part of my proc-filters.el package;

An alias like
    (defalias 'clear 'proc-filter-shell-erase-buffer)

should make it easier to type this command.

(defvar proc-filter-shell-prompt-pattern-modes
  '(shell-mode rlogin-mode ssh-mode telnet-mode ftelnet-mode)
  "*List of major modes which are shell-mode or comint-mode based.
Used by `proc-filter-shell-erase-buffer' to determine which variables
contain valid interpreter prompt regexps.")

(defun proc-filter-shell-erase-buffer ()
  "Delete all buffer contents leading up to the process mark.
Leave a prompt visible."
    (let ((orig-point (point-marker))
          (proc (get-buffer-process (current-buffer)))
       ((and (boundp 'shell-prompt-pattern)
             (memq major-mode proc-filter-shell-prompt-pattern-modes))
        (setq pattern shell-prompt-pattern))
       ((boundp 'comint-prompt-regexp)
        (setq pattern comint-prompt-regexp))
        (signal 'void-variable (list 'comint-prompt-regexp
       ((and proc (> (process-mark proc) orig-point))
        (goto-char (process-mark proc))
        (and (re-search-backward pattern nil t)
               (delete-region (point-min) (point))
               (goto-char (process-mark proc)))))
        (and (re-search-backward pattern nil t)
             (delete-region (point-min) (point)))
        (goto-char orig-point))))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]