home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / packages / shell-font.el < prev    next >
Encoding:
Text File  |  1995-04-17  |  5.3 KB  |  140 lines

  1. ;; Decorate a shell buffer with fonts.
  2. ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of XEmacs.
  5.  
  6. ;; XEmacs is free software; you can redistribute it and/or modify it
  7. ;; 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. ;; XEmacs is distributed in the hope that it will be useful, but
  12. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. ;; General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  18. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. ;; Do this: (add-hook 'shell-mode-hook 'install-shell-fonts) 
  21. ;; and the prompt in your shell-buffers will appear bold-italic, process
  22. ;; output will appear in normal face, and typein will appear in bold.
  23. ;;
  24. ;; The faces shell-prompt, shell-input and shell-output can be modified
  25. ;; as desired, for example, (copy-face 'italic 'shell-prompt).
  26.  
  27. ;; Written by Jamie Zawinski, overhauled by Eric Benson.
  28.  
  29. ;; TODO:
  30. ;; =====
  31. ;; Parse ANSI/VT100 escape sequences to turn on underlining/boldface/etc.
  32. ;; Automatically run nuke-nroff-bs?
  33.  
  34.  
  35. (require 'text-props)    ; for put-nonduplicable-text-property
  36.  
  37. (make-face 'shell-prompt)
  38. (if (not (face-differs-from-default-p 'shell-prompt))
  39.     (copy-face 'bold-italic 'shell-prompt))
  40.  
  41. (make-face 'shell-input)
  42. (if (not (face-differs-from-default-p 'shell-input))
  43.     (copy-face 'bold 'shell-input))
  44.  
  45. (make-face 'shell-output)
  46. (if (not (face-differs-from-default-p 'shell-output))
  47.     (progn (make-face-unbold 'shell-output)
  48.        (make-face-unitalic 'shell-output)
  49.        (set-face-underline-p 'shell-output nil)))
  50.  
  51. (defvar shell-font-read-only-prompt nil
  52.   "*Set all shell prompts to be read-only")
  53.  
  54. (defvar shell-font-current-face 'shell-input)
  55.  
  56. (defun shell-font-fontify-region (start end delete-count)
  57.   ;; for use as an element of after-change-functions; fontifies the inserted text.
  58.   (if (= start end)
  59.       nil
  60. ;    ;; This creates lots of extents (one per user-typed character)
  61. ;    ;; which is wasteful of memory.
  62. ;    (let ((e (make-extent start end)))
  63. ;      (set-extent-face e shell-font-current-face)
  64. ;      (set-extent-property e 'shell-font t))
  65.  
  66.     ;; This efficiently merges extents
  67.     (put-nonduplicable-text-property start end 'face shell-font-current-face)
  68.     (and shell-font-read-only-prompt
  69.      (eq shell-font-current-face 'shell-prompt)
  70.      (put-nonduplicable-text-property start end 'read-only t))
  71.     ))
  72.  
  73. (defun shell-font-hack-prompt (limit)
  74.   "Search backward from point-max for text matching the comint-prompt-regexp,
  75. and put it in the `shell-prompt' face.  LIMIT is the left bound of the search."
  76.   (save-excursion
  77.     (goto-char (point-max))
  78.     (save-match-data
  79.      (cond ((re-search-backward comint-prompt-regexp limit t)
  80.         (goto-char (match-end 0))
  81.         (cond ((= (point) (point-max))
  82.            (skip-chars-backward " \t")
  83.            (let ((shell-font-current-face 'shell-prompt))
  84.              (shell-font-fontify-region
  85.               (match-beginning 0) (point) 0)))))))))
  86.  
  87.  
  88. (defvar shell-font-process-filter nil
  89.   "In an interaction buffer with shell-font, this is the original proc filter.
  90. shell-font encapsulates this.")
  91.  
  92. (defun shell-font-process-filter (proc string)
  93.   "Invoke the original process filter, then set fonts on the output.
  94. The original filter is in the buffer-local variable shell-font-process-filter."
  95.   (let ((cb (current-buffer))
  96.     (pb (process-buffer proc)))
  97.     (if (null pb)
  98.     ;; If the proc has no buffer, leave it alone.
  99.     (funcall shell-font-process-filter proc string)
  100.       ;; Don't do save excursion because some proc filters want to change
  101.       ;; the buffer's point.
  102.       (set-buffer pb)
  103.       (let ((p (marker-position (process-mark proc))))
  104.     (prog1
  105.         ;; this let must not be around the `set-buffer' call.
  106.         (let ((shell-font-current-face 'shell-output))
  107.           (funcall shell-font-process-filter proc string))
  108.       (shell-font-hack-prompt p)
  109.       (set-buffer cb))))))
  110.  
  111. ;;;###autoload
  112. (defun install-shell-fonts ()
  113.   "Decorate the current interaction buffer with fonts.
  114. This uses the faces called `shell-prompt', `shell-input' and `shell-output';
  115. you can alter the graphical attributes of those with the normal
  116. face-manipulation functions."
  117.   (let* ((proc (or (get-buffer-process (current-buffer))
  118.            (error "no process in %S" (current-buffer))))
  119.      (old (or (process-filter proc)
  120.           (error "no process filter on %S" proc))))
  121.     (make-local-variable 'after-change-functions)
  122.     (add-hook 'after-change-functions 'shell-font-fontify-region)
  123.     (make-local-variable 'shell-font-current-face)
  124.     (setq shell-font-current-face 'shell-input)
  125.     (make-local-variable 'shell-font-process-filter)
  126.     (or (eq old 'shell-font-process-filter) ; already set
  127.     (setq shell-font-process-filter old))
  128.     (set-process-filter proc 'shell-font-process-filter))
  129.   nil)
  130.  
  131. (add-hook 'shell-mode-hook    'install-shell-fonts)
  132. (add-hook 'telnet-mode-hook    'install-shell-fonts)
  133. (add-hook 'gdb-mode-hook    'install-shell-fonts)
  134.  
  135. ;; for compatibility with the 19.8 version
  136. ;(fset 'install-shell-font-prompt 'install-shell-fonts)
  137. (make-obsolete 'install-shell-font-prompt 'install-shell-fonts)
  138.  
  139. (provide 'shell-font)
  140.