GNU bug report logs - #7089
23.2; slow ansi-color-apply

Previous Next

Package: emacs;

Reported by: Leo <sdl.web <at> gmail.com>

Date: Thu, 23 Sep 2010 09:14:02 UTC

Severity: normal

Found in version 23.2

Done: Leo <sdl.web <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Leo <sdl.web <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: bug#7089: 23.2; slow ansi-color-apply
Date: Thu, 23 Sep 2010 11:38:05 +0100
The following version fixed some glitches in setting ansi-color-context.
Also I have received an email from Alex that welcomes the improvement.
Let me know if I should send a patch in.

(defun ansi-color-apply* (string)
  "A more efficient implementation of `ansi-color-apply' (which see)."
  (let ((face (car ansi-color-context))
        start end fragment escape-sequence)
    ;; If context was saved and is a string, prepend it.
    (if (cadr ansi-color-context)
        (setq string (concat (cadr ansi-color-context) string)
              ansi-color-context nil))
    (prog1
        (with-temp-buffer
          (insert string)
          (setq start (point-min-marker))
          (goto-char start)
          (while (re-search-forward ansi-color-drop-regexp nil t)
            (replace-match ""))
          (goto-char start)
          ;; Find the next escape sequence.
          (while (re-search-forward ansi-color-regexp nil t)
            (setq end (match-beginning 0))
            (when face
              (put-text-property start end 'ansi-color t)
              (put-text-property start end 'face face))
            (setq start (copy-marker (match-end 0)))
            (setq escape-sequence (match-string 1))
            (replace-match "")
            (setq face (ansi-color-apply-sequence escape-sequence face)))
          ;; search for the possible start of a new escape sequence
          (if (re-search-forward "\033" nil t)
              (setq fragment
                    (delete-and-extract-region (match-beginning 0)
                                               (point-max))))
          ;; if the rest of the string should have a face, put it there
          (when face
            (put-text-property start (point-max) 'ansi-color t)
            (put-text-property start (point-max) 'face face))
          ;; return the string
          (buffer-string))
      ;; save context; NB: ansi-color-context is buffer-local so set it after
      ;; return to the original buffer
      (if (or face fragment)
          (setq ansi-color-context (list face fragment))
        (setq ansi-color-context nil)))))

Leo





This bug report was last modified 14 years and 258 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.