annotate lisp/packages/shell-font.el @ 0:376386a54a3c r19-14

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