annotate lisp/packages/shell-font.el @ 169:15872534500d r20-3b11

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