]> code.delx.au - gnu-emacs/blobdiff - lisp/shell.el
Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[gnu-emacs] / lisp / shell.el
index d79ca363a0fc27694c32d9cc069f02c2c14cf470..d09d7aee43f958bc5697647aa36e336d3d835c0e 100644 (file)
@@ -562,10 +562,8 @@ buffer."
   ;; very inefficient in Shell buffers (e.g. Bug#10835).  We use a
   ;; custom `ansi-color-apply-face-function' to convert color escape
   ;; sequences into `font-lock-face' properties.
-  (set (make-local-variable 'ansi-color-apply-face-function)
-       (lambda (beg end face)
-        (when face
-          (put-text-property beg end 'font-lock-face face))))
+  (setq-local ansi-color-apply-face-function #'shell-apply-ansi-color)
+  (shell-reapply-ansi-color)
 
   ;; This is not really correct, since the shell buffer does not really
   ;; edit this directory.  But it is useful in the buffer list and menus.
@@ -604,6 +602,27 @@ buffer."
                   'shell-filter-ctrl-a-ctrl-b nil t)))
     (comint-read-input-ring t)))
 
+(defun shell-apply-ansi-color (beg end face)
+  "Apply FACE as the ansi-color face for the text between BEG and END."
+  (when face
+    (put-text-property beg end 'ansi-color-face face)
+    (put-text-property beg end 'font-lock-face face)))
+
+(defun shell-reapply-ansi-color ()
+  "Reapply ansi-color faces to the existing contents of the buffer."
+  (save-restriction
+    (widen)
+    (let* ((pos (point-min))
+          (end (or (next-single-property-change pos 'ansi-color-face)
+                   (point-max)))
+          face)
+      (while end
+       (if (setq face (get-text-property pos 'ansi-color-face))
+           (put-text-property pos (or end (point-max))
+                              'font-lock-face face))
+       (setq pos end
+             end (next-single-property-change pos 'ansi-color-face))))))
+
 (defun shell-filter-ctrl-a-ctrl-b (string)
   "Remove `^A' and `^B' characters from comint output.
 
@@ -672,7 +691,12 @@ Otherwise, one argument `-i' is passed to the shell.
     (and current-prefix-arg
         (prog1
             (read-buffer "Shell buffer: "
-                         (generate-new-buffer-name "*shell*"))
+                         ;; If the current buffer is an inactive
+                         ;; shell buffer, use it as the default.
+                         (if (and (eq major-mode 'shell-mode)
+                                  (null (get-buffer-process (current-buffer))))
+                             (buffer-name)
+                           (generate-new-buffer-name "*shell*")))
           (if (file-remote-p default-directory)
               ;; It must be possible to declare a local default-directory.
                ;; FIXME: This can't be right: it changes the default-directory