home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / packages / shell-font.el < prev    next >
Encoding:
Text File  |  1993-02-17  |  3.0 KB  |  71 lines

  1. ;; Makes the shell buffer's prompt be bold (or whatever).
  2. ;; Copyright (C) 1992-1993 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 2, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. ;; Do this: (add-hook 'shell-mode-hook 'install-shell-font-prompt) 
  21. ;; and the prompt in your shell-buffers will appear in boldface.
  22. ;;
  23. ;; If you want it to be italic instead, do (copy-face 'italic 'shell-prompt).
  24.  
  25.  
  26. (make-face 'shell-prompt)
  27. (or (face-differs-from-default-p 'shell-prompt)
  28.     (copy-face 'bold 'shell-prompt))
  29.  
  30. (defun shell-hack-prompt-font (limit)
  31.   "Search backward from point-max for text matching the comint-prompt-regexp,
  32. and put it in the `shell-prompt' face.  LIMIT is the left bound of the search."
  33.   (save-excursion
  34.     (goto-char (point-max))
  35.     (save-match-data
  36.      (cond ((re-search-backward comint-prompt-regexp limit t)
  37.         (goto-char (match-end 0))
  38.         (skip-chars-backward " \t")
  39.         (set-extent-face (make-extent (match-beginning 0) (point))
  40.                  'shell-prompt))))))
  41.  
  42. (defun shell-face-process-filter (proc string)
  43.   "A process-filter that simply inserts the string into the process's buffer,
  44. to give the illusion of a process with no filter, but then searches backward
  45. for text matching the comint-prompt-regexp of this buffer, and puts it in
  46. the `shell-prompt' face."
  47.   (save-excursion 
  48.     (set-buffer (process-buffer proc))
  49.     (goto-char (process-mark proc))
  50.     (let* ((p (point))
  51.        (ie (and comint-last-input-end
  52.             (marker-position comint-last-input-end)))
  53.        (w (get-buffer-window (current-buffer)))
  54.        (ws (and w (window-start w))))
  55.       (insert-before-markers string)
  56.       ;; the insert-before-markers may have screwed window-start
  57.       ;; and likely moved comint-last-input-end.  This is why the
  58.       ;; insertion-reaction should be a property of markers, not
  59.       ;; of the function which does the inserting.
  60.       (if ws (set-window-start w ws t))
  61.       (if ie (set-marker comint-last-input-end ie))
  62.       (set-marker (process-mark proc) (point))
  63.       (shell-hack-prompt-font p))))
  64.  
  65. (defun install-shell-font-prompt ()
  66.   "Add this to your shell-mode-hook to make the prompt be printed in boldface.
  67. The prompt uses the face called `shell-prompt'; you can alter the graphical
  68. attributes of that with the normal face-manipulation functions."
  69.   (set-process-filter (get-buffer-process (current-buffer))
  70.               'shell-face-process-filter))
  71.