aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2009-09-24 02:04:25 +0000
committerStefan Monnier2009-09-24 02:04:25 +0000
commit4a814992b8972f549477673c4470d7307d0adefe (patch)
tree959862986fce722d44e31caa586f5c3d292a7267
parent89cc15915a6181c67a14e73ea8cd06693eef1311 (diff)
downloademacs-4a814992b8972f549477673c4470d7307d0adefe.tar.gz
emacs-4a814992b8972f549477673c4470d7307d0adefe.zip
Require CL.
(term-ansi-reset): New function. (term-mode, term-emulate-terminal, term-handle-colors-array): Use it. (term-handle-colors-array): Simplify.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/term.el150
2 files changed, 76 insertions, 81 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index bcc4eca6b6f..02a8589512e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12009-09-24 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * term.el: Require CL.
4 (term-ansi-reset): New function.
5 (term-mode, term-emulate-terminal, term-handle-colors-array): Use it.
6 (term-handle-colors-array): Simplify.
7
12009-09-24 Juanma Barranquero <lekktu@gmail.com> 82009-09-24 Juanma Barranquero <lekktu@gmail.com>
2 9
3 * allout.el (allout-overlay-interior-modification-handler) 10 * allout.el (allout-overlay-interior-modification-handler)
diff --git a/lisp/term.el b/lisp/term.el
index 5a9caa34acd..b7eb9fd1845 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -399,7 +399,8 @@
399(defconst term-protocol-version "0.96") 399(defconst term-protocol-version "0.96")
400 400
401(eval-when-compile 401(eval-when-compile
402 (require 'ange-ftp)) 402 (require 'ange-ftp)
403 (require 'cl))
403(require 'ring) 404(require 'ring)
404(require 'ehelp) 405(require 'ehelp)
405 406
@@ -739,12 +740,18 @@ Buffer local variable.")
739 740
740;;; faces -mm 741;;; faces -mm
741 742
742(defcustom term-default-fg-color (face-foreground term-current-face) 743(defcustom term-default-fg-color
744 ;; FIXME: This depends on the current frame, so depending on when
745 ;; it's loaded, the result may be different.
746 (face-foreground term-current-face)
743 "Default color for foreground in `term'." 747 "Default color for foreground in `term'."
744 :group 'term 748 :group 'term
745 :type 'string) 749 :type 'string)
746 750
747(defcustom term-default-bg-color (face-background term-current-face) 751(defcustom term-default-bg-color
752 ;; FIXME: This depends on the current frame, so depending on when
753 ;; it's loaded, the result may be different.
754 (face-background term-current-face)
748 "Default color for background in `term'." 755 "Default color for background in `term'."
749 :group 'term 756 :group 'term
750 :type 'string) 757 :type 'string)
@@ -959,6 +966,20 @@ is buffer-local.")
959 (setq i (1+ i))) 966 (setq i (1+ i)))
960 dt)) 967 dt))
961 968
969(defun term-ansi-reset ()
970 (setq term-current-face (nconc
971 (if term-default-bg-color
972 (list :background term-default-bg-color))
973 (if term-default-fg-color
974 (list :foreground term-default-fg-color))))
975 (setq term-ansi-current-underline nil)
976 (setq term-ansi-current-bold nil)
977 (setq term-ansi-current-reverse nil)
978 (setq term-ansi-current-color 0)
979 (setq term-ansi-current-invisible nil)
980 (setq term-ansi-face-already-done t)
981 (setq term-ansi-current-bg-color 0))
982
962(defun term-mode () 983(defun term-mode ()
963 "Major mode for interacting with an inferior interpreter. 984 "Major mode for interacting with an inferior interpreter.
964The interpreter name is same as buffer name, sans the asterisks. 985The interpreter name is same as buffer name, sans the asterisks.
@@ -1111,8 +1132,7 @@ Entry to this mode runs the hooks on `term-mode-hook'."
1111 (make-local-variable 'term-pending-delete-marker) 1132 (make-local-variable 'term-pending-delete-marker)
1112 (setq term-pending-delete-marker (make-marker)) 1133 (setq term-pending-delete-marker (make-marker))
1113 (make-local-variable 'term-current-face) 1134 (make-local-variable 'term-current-face)
1114 (setq term-current-face (list :background term-default-bg-color 1135 (term-ansi-reset)
1115 :foreground term-default-fg-color))
1116 (make-local-variable 'term-pending-frame) 1136 (make-local-variable 'term-pending-frame)
1117 (setq term-pending-frame nil) 1137 (setq term-pending-frame nil)
1118 ;; Cua-mode's keybindings interfere with the term keybindings, disable it. 1138 ;; Cua-mode's keybindings interfere with the term keybindings, disable it.
@@ -3117,25 +3137,19 @@ See `term-prompt-regexp'."
3117(defun term-reset-terminal () 3137(defun term-reset-terminal ()
3118 "Reset the terminal, delete all the content and set the face to the default one." 3138 "Reset the terminal, delete all the content and set the face to the default one."
3119 (erase-buffer) 3139 (erase-buffer)
3140 (term-ansi-reset)
3120 (setq term-current-row 0) 3141 (setq term-current-row 0)
3121 (setq term-current-column 1) 3142 (setq term-current-column 1)
3122 (setq term-scroll-start 0) 3143 (setq term-scroll-start 0)
3123 (setq term-scroll-end term-height) 3144 (setq term-scroll-end term-height)
3124 (setq term-insert-mode nil) 3145 (setq term-insert-mode nil)
3125 (setq term-current-face (list :background term-default-bg-color 3146 ;; FIXME: No idea why this is here, it looks wrong. --Stef
3126 :foreground term-default-fg-color)) 3147 (setq term-ansi-face-already-done nil))
3127 (setq term-ansi-current-underline nil)
3128 (setq term-ansi-current-bold nil)
3129 (setq term-ansi-current-reverse nil)
3130 (setq term-ansi-current-color 0)
3131 (setq term-ansi-current-invisible nil)
3132 (setq term-ansi-face-already-done nil)
3133 (setq term-ansi-current-bg-color 0))
3134 3148
3135;; New function to deal with ansi colorized output, as you can see you can 3149;; New function to deal with ansi colorized output, as you can see you can
3136;; have any bold/underline/fg/bg/reverse combination. -mm 3150;; have any bold/underline/fg/bg/reverse combination. -mm
3137 3151
3138(defvar term-bold-attribute '(:weight bold)) 3152(defvar term-bold-attribute '(:weight bold)
3139 "Attribute to use for the bold terminal attribute. 3153 "Attribute to use for the bold terminal attribute.
3140Set it to nil to disable bold.") 3154Set it to nil to disable bold.")
3141 3155
@@ -3189,15 +3203,7 @@ Set it to nil to disable bold.")
3189 3203
3190 ;; 0 (Reset) or unknown (reset anyway) 3204 ;; 0 (Reset) or unknown (reset anyway)
3191 (t 3205 (t
3192 (setq term-current-face (list :background term-default-bg-color 3206 (term-ansi-reset)))
3193 :foreground term-default-fg-color))
3194 (setq term-ansi-current-underline nil)
3195 (setq term-ansi-current-bold nil)
3196 (setq term-ansi-current-reverse nil)
3197 (setq term-ansi-current-color 0)
3198 (setq term-ansi-current-invisible nil)
3199 (setq term-ansi-face-already-done t)
3200 (setq term-ansi-current-bg-color 0)))
3201 3207
3202 ;; (message "Debug: U-%d R-%d B-%d I-%d D-%d F-%d B-%d" 3208 ;; (message "Debug: U-%d R-%d B-%d I-%d D-%d F-%d B-%d"
3203 ;; term-ansi-current-underline 3209 ;; term-ansi-current-underline
@@ -3210,65 +3216,47 @@ Set it to nil to disable bold.")
3210 3216
3211 3217
3212 (unless term-ansi-face-already-done 3218 (unless term-ansi-face-already-done
3213 (if term-ansi-current-reverse 3219 (if term-ansi-current-invisible
3214 (if term-ansi-current-invisible 3220 (let ((color
3215 (setq term-current-face 3221 (if term-ansi-current-reverse
3216 (if (= term-ansi-current-color 0) 3222 (if (= term-ansi-current-color 0)
3217 (list :background 3223 term-default-fg-color
3218 term-default-fg-color 3224 (elt ansi-term-color-vector term-ansi-current-color))
3219 :foreground 3225 (if (= term-ansi-current-bg-color 0)
3220 term-default-fg-color) 3226 term-default-bg-color
3221 (list :background 3227 (elt ansi-term-color-vector term-ansi-current-bg-color)))))
3222 (elt ansi-term-color-vector term-ansi-current-color) 3228 (setq term-current-face
3223 :foreground 3229 (list :background color
3224 (elt ansi-term-color-vector term-ansi-current-color))) 3230 :foreground color))
3225 ;; No need to bother with anything else if it's invisible 3231 ) ;; No need to bother with anything else if it's invisible.
3226 ) 3232
3227 (setq term-current-face 3233 (setq term-current-face
3228 (list :background 3234 (if term-ansi-current-reverse
3229 (if (= term-ansi-current-color 0) 3235 (if (= term-ansi-current-color 0)
3230 term-default-fg-color 3236 (list :background term-default-fg-color
3231 (elt ansi-term-color-vector term-ansi-current-color)) 3237 :foreground term-default-bg-color)
3232 :foreground 3238 (list :background
3233 (if (= term-ansi-current-bg-color 0) 3239 (elt ansi-term-color-vector term-ansi-current-color)
3234 term-default-bg-color 3240 :foreground
3235 (elt ansi-term-color-vector term-ansi-current-bg-color)))) 3241 (elt ansi-term-color-vector term-ansi-current-bg-color)))
3236 (when term-ansi-current-bold 3242
3237 (setq term-current-face 3243 (if (= term-ansi-current-color 0)
3238 (append term-bold-attribute term-current-face))) 3244 (list :foreground term-default-fg-color
3239 (when term-ansi-current-underline 3245 :background term-default-bg-color)
3240 (setq term-current-face 3246 (list :foreground
3241 (append '(:underline t) term-current-face)))) 3247 (elt ansi-term-color-vector term-ansi-current-color)
3242 (if term-ansi-current-invisible 3248 :background
3243 (setq term-current-face 3249 (elt ansi-term-color-vector term-ansi-current-bg-color)))))
3244 (if (= term-ansi-current-bg-color 0) 3250
3245 (list :background 3251 (when term-ansi-current-bold
3246 term-default-bg-color 3252 (setq term-current-face
3247 :foreground 3253 (append term-bold-attribute term-current-face)))
3248 term-default-bg-color) 3254 (when term-ansi-current-underline
3249 (list :foreground 3255 (setq term-current-face
3250 (elt ansi-term-color-vector term-ansi-current-bg-color) 3256 (list* :underline t term-current-face)))))
3251 :background
3252 (elt ansi-term-color-vector term-ansi-current-bg-color)))
3253 ;; No need to bother with anything else if it's invisible
3254 )
3255 (setq term-current-face
3256 (list :foreground
3257 (if (= term-ansi-current-color 0)
3258 term-default-fg-color
3259 (elt ansi-term-color-vector term-ansi-current-color))
3260 :background
3261 (if (= term-ansi-current-bg-color 0)
3262 term-default-bg-color
3263 (elt ansi-term-color-vector term-ansi-current-bg-color))))
3264 (when term-ansi-current-bold
3265 (setq term-current-face
3266 (append term-bold-attribute term-current-face)))
3267 (when term-ansi-current-underline
3268 (setq term-current-face
3269 (append '(:underline t) term-current-face))))))
3270 3257
3271 ;; (message "Debug %S" term-current-face) 3258 ;; (message "Debug %S" term-current-face)
3259 ;; FIXME: shouldn't we set term-ansi-face-already-done to t here? --Stef
3272 (setq term-ansi-face-already-done nil)) 3260 (setq term-ansi-face-already-done nil))
3273 3261
3274 3262