mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-21 06:55:39 +00:00
8903106bb7
* lisp/subr.el (if-let*, when-let*, if-let, when-let): Mark if-let and when-let obsolete (bug#73853 and elsewhere). Move docstring text around so that if-let* and when-let* descriptions no longer refer to if-let and when-let. * etc/NEWS: Announce the change. * admin/admin.el (reminder-for-release-blocking-bugs): * doc/misc/erc.texi (display-buffer): * lisp/ansi-color.el (ansi-color-apply) (ansi-color--face-vec-face): * lisp/ansi-osc.el (ansi-osc-apply-on-region) (ansi-osc-hyperlink): * lisp/arc-mode.el (archive-goto-file) (archive-next-file-displayer): * lisp/auth-source-pass.el (auth-source-pass-search) (auth-source-pass--parse-data) (auth-source-pass--find-match-many): * lisp/autorevert.el (auto-revert-notify-rm-watch): * lisp/buff-menu.el (Buffer-menu-unmark-all-buffers) (Buffer-menu-group-by-root): * lisp/calendar/parse-time.el (parse-iso8601-time-string): * lisp/cedet/pulse.el (pulse-tick): * lisp/comint.el (comint--fontify-input-ppss-flush-indirect) (comint--intersect-regions): * lisp/completion-preview.el (completion-preview--try-table) (completion-preview--capf-wrapper, completion-preview--update): * lisp/cus-edit.el (setopt--set) (custom-dirlocals-maybe-update-cons, custom-dirlocals-validate): * lisp/custom.el (load-theme): * lisp/descr-text.el (describe-char): * lisp/desktop.el (desktop--emacs-pid-running-p): * lisp/dired-x.el (menu): * lisp/dired.el (dired-font-lock-keywords) (dired-insert-directory, dired--insert-disk-space, dired-mode): * lisp/dnd.el (dnd-handle-multiple-urls): * lisp/dom.el (dom-remove-attribute): * lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): * lisp/emacs-lisp/bytecomp.el (bytecomp--custom-declare): * lisp/emacs-lisp/comp-common.el (comp-function-type-spec): * lisp/emacs-lisp/comp-cstr.el (comp--all-classes) (comp-cstr-set-range-for-arithm, comp--cstr-union-1-no-mem) (comp-cstr-intersection-no-mem, comp-cstr-fixnum-p) (comp-cstr-type-p): * lisp/emacs-lisp/comp-run.el (comp-subr-trampoline-install) (native--compile-async): * lisp/emacs-lisp/comp.el (comp--get-function-cstr) (comp--function-pure-p, comp--intern-func-in-ctxt) (comp--addr-to-bb-name, comp--emit-assume, comp--maybe-add-vmvar) (comp--add-call-cstr, comp--compute-dominator-tree) (comp--dom-tree-walker, comp--ssa-rename) (comp--function-call-maybe-fold, comp--fwprop-call) (comp--call-optim-func): * lisp/emacs-lisp/edebug.el (edebug-global-prefix) (edebug-remove-instrumentation): * lisp/emacs-lisp/eieio.el (initialize-instance): * lisp/emacs-lisp/ert-x.el (ert-resource-directory): * lisp/emacs-lisp/ert.el (ert--expand-should-1) (ert-test-location, ert-write-junit-test-report) (ert-test--erts-test): * lisp/emacs-lisp/icons.el (icon-complete-spec, icon-string) (icons--create): * lisp/emacs-lisp/lisp-mode.el (lisp--local-defform-body-p): * lisp/emacs-lisp/loaddefs-gen.el (loaddefs-generate--make-autoload) (loaddefs-generate--parse-file): * lisp/emacs-lisp/multisession.el (multisession-edit-mode--revert, multisession-edit-value): * lisp/emacs-lisp/package-vc.el (package-vc--read-archive-data) (package-vc--version, package-vc--clone): * lisp/emacs-lisp/package.el (package--reload-previously-loaded): * lisp/emacs-lisp/pp.el (pp--insert-lisp): * lisp/emacs-lisp/subr-x.el (add-display-text-property): * lisp/emacs-lisp/tabulated-list.el (tabulated-list-print): * lisp/emacs-lisp/timer.el (run-at-time): * lisp/emacs-lisp/vtable.el (vtable-goto-table) (vtable-goto-column, vtable-update-object, vtable--insert-line) (vtable--compute-widths, vtable--make-keymap): * lisp/emacs-lisp/warnings.el (display-warning): * lisp/epa-file.el (epa-file-insert-file-contents): * lisp/epa.el (epa-show-key): * lisp/erc/erc-backend.el (erc--split-line, erc--conceal-prompt) (PRIVMSG, erc--get-isupport-entry): * lisp/erc/erc-button.el (erc-button-add-nickname-buttons) (erc--button-next): * lisp/erc/erc-common.el (erc--find-group): * lisp/erc/erc-fill.el (erc-fill, erc-fill-static) (erc-fill--wrap-escape-hidden-speaker) (erc-fill--wrap-unmerge-on-date-stamp) (erc-fill--wrap-massage-initial-message-post-clear) (erc-fill-wrap, erc-fill--wrap-rejigger-region): * lisp/erc/erc-goodies.el (erc--scrolltobottom-all) (erc--keep-place-indicator-on-window-buffer-change) (keep-place-indicator, erc--keep-place-indicator-adjust-on-clear) (erc-keep-place-move, erc--command-indicator-display): * lisp/erc/erc-ibuffer.el (erc-members): * lisp/erc/erc-join.el (erc-join--remove-requested-channel) (erc-autojoin--join): * lisp/erc/erc-networks.el (erc-networks--id-qualifying-init-parts, erc-networks--id-reload) (erc-networks--id-ensure-comparable) (erc-networks--reclaim-orphaned-target-buffers) (erc-networks--server-select): * lisp/erc/erc-nicks.el (erc-nicks-invert) (erc-nicks--redirect-face-widget-link, erc-nicks--highlight) (erc-nicks--highlight-button) (erc-nicks--list-faces-help-button-action, erc-nicks-list-faces) (erc-nicks-refresh, erc-nicks--colors-from-faces) (erc-nicks--track-prioritize) (erc-nicks--remember-face-for-track): * lisp/erc/erc-notify.el (querypoll, erc--querypoll-get-next) (erc--querypoll-on-352, erc--querypoll-send): * lisp/erc/erc-sasl.el (erc-sasl--read-password): * lisp/erc/erc-services.el (erc-services-issue-ghost-and-retry-nick): * lisp/erc/erc-speedbar.el (erc-speedbar--ensure, nickbar) (erc-speedbar-toggle-nicknames-window-lock) (erc-speedbar--compose-nicks-face): * lisp/erc/erc-stamp.el (erc-stamp--recover-on-reconnect) (erc-stamp-prefix-log-filter, erc--conceal-prompt) (erc--insert-timestamp-left, erc-insert-timestamp-right) (erc-stamp--defer-date-insertion-on-post-modify) (erc-insert-timestamp-left-and-right) (erc-stamp--redo-right-stamp-post-clear) (erc-stamp--reset-on-clear, erc-stamp--dedupe-date-stamps): * lisp/erc/erc-status-sidebar.el (bufbar) (erc-status-sidebar-prefer-target-as-name) (erc-status-sidebar-default-allsort, erc-status-sidebar-click): * lisp/erc/erc-track.el (erc-track--shortened-names-get) (erc-track--setup, erc-track--select-mode-line-face) (erc-track-modified-channels, erc-track--collect-faces-in) (erc-track--switch-buffer, erc-track--replace-killed-buffer): * lisp/erc/erc-truncate.el (erc-truncate--setup) (erc-truncate-buffer): * lisp/erc/erc.el (erc--ensure-query-member) (erc--ensure-query-members, erc--remove-channel-users-but) (erc--cusr-change-status, erc--find-mode, erc--update-modules) (erc-log-irc-protocol, erc--refresh-prompt) (erc--restore-important-text-props) (erc--order-text-properties-from-hash, erc-send-input-line) (erc-cmd-IGNORE, erc--unignore-user, erc-cmd-QUERY) (erc-cmd-BANLIST, erc--speakerize-nick) (erc--format-speaker-input-message, erc-channel-receive-names) (erc-send-current-line, erc-format-target-and/or-network) (erc-kill-buffer-function, erc-restore-text-properties) (erc--get-eq-comparable-cmd): * lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias--which) (eshell-maybe-replace-by-alias): * lisp/eshell/em-glob.el (eshell-glob-convert): * lisp/eshell/em-pred.el (eshell-pred-user-or-group) (eshell-pred-file-time, eshell-pred-file-type) (eshell-pred-file-mode, eshell-pred-file-links) (eshell-pred-file-size): * lisp/eshell/em-prompt.el (eshell-forward-paragraph) (eshell-next-prompt): * lisp/eshell/esh-arg.el (eshell-resolve-current-argument): * lisp/eshell/esh-cmd.el (eshell-do-eval, eshell/which) (eshell-plain-command--which, eshell-plain-command): * lisp/eshell/esh-io.el (eshell-duplicate-handles) (eshell-protect-handles, eshell-get-target, eshell-close-target): * lisp/eshell/esh-proc.el (eshell-sentinel): * lisp/eshell/esh-var.el (eshell-parse-variable-ref) (eshell-get-variable, eshell-set-variable): * lisp/faces.el (face-at-point): * lisp/ffap.el (ffap-in-project): * lisp/filenotify.el (file-notify--rm-descriptor): * lisp/files-x.el (read-dir-locals-file) (connection-local-update-profile-variables) (connection-local-value): * lisp/files.el (file-remote-p, abbreviate-file-name) (set-auto-mode, hack-local-variables) (revert-buffer-restore-read-only): * lisp/find-dired.el (find-dired-sort-by-filename): * lisp/font-lock.el (font-lock--filter-keywords): * lisp/gnus/gnus-art.el (article-emojize-symbols): * lisp/gnus/gnus-int.el (gnus-close-server): * lisp/gnus/gnus-search.el (gnus-search-transform) (gnus-search-indexed-parse-output, gnus-search-server-to-engine): * lisp/gnus/gnus-sum.el (gnus-collect-urls, gnus-shorten-url): * lisp/gnus/gnus.el (gnus-check-backend-function): * lisp/gnus/message.el (message-send-mail): * lisp/gnus/mml.el (mml-generate-mime, mml-insert-mime-headers): * lisp/gnus/nnatom.el (nnatom--read-feed, nnatom--read-article) (nnatom--read-article-or-group-authors, nnatom--read-publish) (nnatom--read-update, nnatom--read-links): * lisp/gnus/nnfeed.el (nnfeed--read-server, nnfeed--write-server) (nnfeed--parse-feed, nnfeed--group-data, nnfeed-retrieve-article) (nnfeed-retrieve-headers, nnfeed--print-part) (nnfeed-request-article, nnfeed-request-group) (nnfeed-request-list, nnfeed--group-description) (nnfeed-request-group-description) (nnfeed-request-list-newsgroups, nnfeed-request-rename-group): * lisp/gnus/nnmh.el (nnmh-update-gnus-unreads): * lisp/help-fns.el (help-find-source) (help-fns--insert-menu-bindings, help-fns--mention-first-release) (help-fns--mention-shortdoc-groups) (help-fns--customize-variable-version) (help-fns--face-custom-version-info, describe-mode): * lisp/help-mode.el (help-make-xrefs): * lisp/help.el (help-key-description, help--describe-command): * lisp/hfy-cmap.el (htmlfontify-load-rgb-file): * lisp/ibuf-ext.el (ibuffer-jump-to-filter-group) (ibuffer-kill-filter-group, ibuffer-kill-line) (ibuffer-save-filter-groups, ibuffer-save-filters, filename) (basename, file-extension, ibuffer-diff-buffer-with-file-1) (ibuffer-mark-by-file-name-regexp) (ibuffer-mark-by-content-regexp): * lisp/ibuf-macs.el (ibuffer-aif, ibuffer-awhen): * lisp/ibuffer.el (ibuffer-mouse-toggle-mark) (ibuffer-toggle-marks, ibuffer-mark-interactive) (ibuffer-compile-format, process, ibuffer-map-lines): * lisp/image.el (image--compute-map) (image--compute-original-map): * lisp/image/exif.el (exif-parse-buffer): * lisp/image/image-converter.el (image-convert-p, image-convert) (image-converter--find-converter): * lisp/image/image-dired-util.el (image-dired-file-name-at-point): * lisp/image/image-dired.el (image-dired-track-original-file) (image-dired--on-file-in-dired-buffer) (image-dired--with-thumbnail-buffer) (image-dired-jump-original-dired-buffer) (image-dired--slideshow-step, image-dired-display-image): * lisp/image/wallpaper.el (wallpaper--init-action-kill) (wallpaper--find-setter, wallpaper--find-command) (wallpaper--find-command-args, wallpaper--x-monitor-name): * lisp/info-look.el (info-lookup-interactive-arguments) (info-complete)::(:mode): * lisp/info.el (info-pop-to-buffer, Info-read-node-name-1): * lisp/international/emoji.el (emoji--adjust-displayable-1) (emoji--add-recent): * lisp/jsonrpc.el (jsonrpc--call-deferred) (jsonrpc--process-sentinel, jsonrpc--remove): * lisp/keymap.el (keymap-local-lookup): * lisp/mail/emacsbug.el (report-emacs-bug-hook) (submit-emacs-patch): * lisp/mail/ietf-drums.el (ietf-drums-parse-addresses): * lisp/mail/mailclient.el (mailclient-send-it): * lisp/mail/rfc6068.el (rfc6068-parse-mailto-url): * lisp/mail/undigest.el (rmail-digest-parse-mixed-mime): * lisp/minibuffer.el (completion-metadata-get) (completions--after-change) (minibuffer-visible-completions--filter): * lisp/net/browse-url.el (browse-url-url-at-point) (browse-url-file-url, browse-url-emacs): * lisp/net/dbus.el (dbus-byte-array-to-string) (dbus-monitor-goto-serial): * lisp/net/dictionary.el (dictionary-search): * lisp/net/eww.el (eww--download-directory) (eww-auto-rename-buffer, eww-open-in-new-buffer, eww-submit) (eww-follow-link, eww-read-alternate-url) (eww-copy-alternate-url): * lisp/net/goto-addr.el (goto-address-at-point): * lisp/net/mailcap.el (mailcap-mime-info): * lisp/net/rcirc.el (rcirc, rcirc-connect, rcirc-send-string) (rcirc-kill-buffer-hook, rcirc-print, rcirc-when) (rcirc-color-attributes, rcirc-handler-NICK) (rcirc-handler-TAGMSG, rcirc-handler-BATCH): * lisp/net/shr.el (shr-descend, shr-adaptive-fill-function) (shr-correct-dom-case, shr-tag-a): * lisp/net/sieve.el (sieve-manage-quit): * lisp/outline.el (outline-cycle-buffer): * lisp/pcmpl-git.el (pcmpl-git--tracked-file-predicate): * lisp/proced.el (proced-auto-update-timer): * lisp/progmodes/bug-reference.el (bug-reference-try-setup-from-vc): * lisp/progmodes/c-ts-common.el (c-ts-common--fill-paragraph): * lisp/progmodes/c-ts-mode.el (c-ts-mode--preproc-offset) (c-ts-mode--anchor-prev-sibling, c-ts-mode-indent-defun): * lisp/progmodes/compile.el (compilation-error-properties) (compilation-find-file-1): * lisp/progmodes/eglot.el (eglot--check-object) (eglot--read-server, eglot-upgrade-eglot) (eglot-handle-notification, eglot--CompletionParams) (eglot-completion-at-point, eglot--sig-info) (eglot-register-capability): * lisp/progmodes/elisp-mode.el (emacs-lisp-native-compile-and-load) (elisp-eldoc-var-docstring-with-value): * lisp/progmodes/erts-mode.el (erts-mode--goto-start-of-test): * lisp/progmodes/flymake.el (flymake--update-eol-overlays) (flymake-eldoc-function): * lisp/progmodes/gdb-mi.el (gdb-breakpoints-list-handler-custom) (gdb-frame-handler): * lisp/progmodes/go-ts-mode.el (go-ts-mode-docstring) (go-ts-mode--comment-on-previous-line-p) (go-ts-mode--get-test-regexp-at-point) (go-ts-mode-test-this-file): * lisp/progmodes/grep.el (lgrep, rgrep-default-command) (grep-file-at-point): * lisp/progmodes/perl-mode.el (perl--end-of-format-p): * lisp/progmodes/php-ts-mode.el (php-ts-mode--anchor-prev-sibling, php-ts-mode--indent-defun): * lisp/progmodes/project.el (project--other-place-command) (project--find-default-from, project--transplant-file-name) (project-prefixed-buffer-name, project--remove-from-project-list) (project-prompt-project-name, project-remember-projects-under) (project--switch-project-command) (project-uniquify-dirname-transform, project-mode-line-format): * lisp/progmodes/python.el (python-font-lock-keywords-maximum-decoration) (python--treesit-fontify-union-types) (python-shell-get-process-name, python-shell-restart) (python-shell-completion-at-point, python-ffap-module-path) (python-util-comint-end-of-output-p, python--import-sources) (python-add-import, python-remove-import, python-fix-imports): * lisp/progmodes/xref.el (xref--add-log-current-defun): * lisp/repeat.el (repeat-echo-message-string): * lisp/saveplace.el (save-place-dired-hook): * lisp/server.el (server-save-buffers-kill-terminal): * lisp/shadowfile.el (shadow-make-fullname) (shadow-contract-file-name, shadow-define-literal-group): * lisp/shell.el (shell-highlight-undef-mode): * lisp/simple.el (command-completion-using-modes-p) (command-execute, file-user-uid, file-group-gid) (first-completion, last-completion, switch-to-completions): * lisp/startup.el (startup--load-user-init-file): * lisp/tab-line.el (tab-line-tabs-buffer-group-by-project): * lisp/tar-mode.el (tar-goto-file, tar-next-file-displayer): * lisp/term/android-win.el (android-encode-select-string) (gui-backend-set-selection): * lisp/term/haiku-win.el (haiku-dnd-convert-string) (haiku-select-encode-xstring, haiku-select-encode-utf-8-string): * lisp/textmodes/emacs-news-mode.el (emacs-news--buttonize): * lisp/textmodes/ispell.el (ispell-completion-at-point): * lisp/textmodes/sgml-mode.el (sgml-validate) (html-mode--complete-at-point): * lisp/textmodes/tex-mode.el (tex-recenter-output-buffer) (xref-backend-references): * lisp/thingatpt.el (thing-at-point-file-at-point) (thing-at-point-face-at-point): * lisp/thread.el (thread-list--get-status): * lisp/time.el (world-clock-copy-time-as-kill, world-clock): * lisp/touch-screen.el (touch-screen-handle-touch): * lisp/treesit.el (treesit-language-at, treesit-node-at) (treesit-node-on, treesit-buffer-root-node) (treesit-node-field-name, treesit-local-parsers-at) (treesit-local-parsers-on, treesit--cleanup-local-range-overlays) (treesit-font-lock-recompute-features) (treesit-font-lock-fontify-region, treesit-transpose-sexps) (treesit-add-log-current-defun, treesit-major-mode-setup) (treesit--explorer-refresh, treesit-install-language-grammar): * lisp/url/url.el (url-retrieve-synchronously): * lisp/vc/smerge-mode.el (smerge-diff): * lisp/vc/vc-dir.el (vc-dir): * lisp/vc/vc-dispatcher.el (vc-do-async-command): * lisp/vc/vc-git.el (vc-git-dir--branch-headers) (vc-git-dir--stash-headers, vc-git--log-edit-summary-check) (vc-git-stash-list): * lisp/vc/vc.el (vc-responsible-backend, vc-buffer-sync-fileset) (vc-clone): * lisp/visual-wrap.el (visual-wrap--apply-to-line): * lisp/wid-edit.el (widget-text) (widget-editable-list-insert-before): * lisp/window-tool-bar.el (window-tool-bar--keymap-entry-to-string): * lisp/window.el (display-buffer, display-buffer-full-frame) (window-point-context-set, window-point-context-use) (window-point-context-use-default-function): * lisp/xdg.el (xdg-current-desktop): * lisp/xwidget.el (xwidget-webkit-callback): * lisp/yank-media.el (yank-media--get-selection) (yank-media-types): * test/lisp/comint-tests.el (comint-tests/test-password-function): * test/lisp/completion-preview-tests.el (completion-preview-tests--capf): * test/lisp/cus-edit-tests.el (with-cus-edit-test): * test/lisp/erc/erc-scenarios-base-local-modules.el (-phony-sblm-): * test/lisp/erc/erc-scenarios-stamp.el (erc-scenarios-stamp--on-post-modify): * test/lisp/erc/erc-services-tests.el (erc-services-tests--asp-parse-entry): * test/lisp/erc/erc-tests.el (erc-modules--internal-property) (erc--find-mode, erc-tests--update-modules): * test/lisp/erc/resources/erc-d/erc-d-i.el (erc-d-i--parse-message): * test/lisp/erc/resources/erc-d/erc-d-t.el (erc-d-t-kill-related-buffers, erc-d-t-with-cleanup): * test/lisp/erc/resources/erc-d/erc-d-tests.el (erc-d-i--parse-message--irc-parser-tests): * test/lisp/erc/resources/erc-d/erc-d-u.el (erc-d-u--read-exchange-slowly): * test/lisp/erc/resources/erc-d/erc-d.el (erc-d--expire) (erc-d--finalize-done, erc-d--command-handle-all): * test/lisp/erc/resources/erc-scenarios-common.el (erc-scenarios-common-with-cleanup): * test/lisp/erc/resources/erc-tests-common.el (erc-tests--common-display-message) (erc-tests-common-create-subprocess): * test/lisp/ibuffer-tests.el (ibuffer-test-Bug25058): * test/lisp/international/mule-tests.el (mule-cmds-tests--ucs-names-missing-names): * test/lisp/progmodes/python-tests.el (python-tests-get-shell-interpreter) (python-tests--get-interpreter-info): * test/lisp/progmodes/ruby-ts-mode-tests.el (ruby-ts-resource-file): * test/lisp/replace-tests.el (replace-tests-with-undo): * test/src/emacs-tests.el (emacs-tests--seccomp-debug): * test/src/process-tests.el (process-tests--emacs-command) (process-tests--emacs-binary, process-tests--dump-file): * test/src/treesit-tests.el (treesit--ert-test-defun-navigation): Replace use of the now-obsolete if-let and when-let.
1071 lines
39 KiB
EmacsLisp
1071 lines
39 KiB
EmacsLisp
;;; ansi-color.el --- translate ANSI escape sequences into faces -*- lexical-binding: t -*-
|
||
|
||
;; Copyright (C) 1999-2024 Free Software Foundation, Inc.
|
||
|
||
;; Author: Alex Schroeder <alex@gnu.org>
|
||
;; Version: 3.4.2
|
||
;; Keywords: comm processes terminals services
|
||
|
||
;; This file is part of GNU Emacs.
|
||
|
||
;; GNU Emacs is free software: you can redistribute it and/or modify
|
||
;; it under the terms of the GNU General Public License as published by
|
||
;; the Free Software Foundation, either version 3 of the License, or
|
||
;; (at your option) any later version.
|
||
|
||
;; GNU Emacs is distributed in the hope that it will be useful,
|
||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
;; GNU General Public License for more details.
|
||
|
||
;; You should have received a copy of the GNU General Public License
|
||
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
||
|
||
;;; Commentary:
|
||
|
||
;; This file provides a function that takes a string or a region
|
||
;; containing Select Graphic Rendition (SGR) control sequences (formerly
|
||
;; known as ANSI escape sequences) and tries to translate these into
|
||
;; faces.
|
||
;;
|
||
;; This allows you to run ls --color=yes in shell-mode. It is now
|
||
;; enabled by default; to disable it, set ansi-color-for-comint-mode
|
||
;; to nil.
|
||
;;
|
||
;; Note that starting your shell from within Emacs might set the TERM
|
||
;; environment variable. The new setting might disable the output of
|
||
;; SGR control sequences. Using ls --color=yes forces ls to produce
|
||
;; these.
|
||
;;
|
||
;; SGR control sequences are defined in section 3.8.117 of the ECMA-48
|
||
;; standard (identical to ISO/IEC 6429), which is freely available as a
|
||
;; PDF file <URL:https://www.ecma-international.org/publications/standards/Ecma-048.htm>.
|
||
;; The "Graphic Rendition Combination Mode (GRCM)" implemented is
|
||
;; "cumulative mode" as defined in section 7.2.8. Cumulative mode
|
||
;; means that whenever possible, SGR control sequences are combined
|
||
;; (i.e. blue and bold).
|
||
|
||
;; The basic functions are:
|
||
;;
|
||
;; `ansi-color-apply' to colorize a string containing SGR control
|
||
;; sequences.
|
||
;;
|
||
;; `ansi-color-filter-apply' to filter SGR control sequences from a
|
||
;; string.
|
||
;;
|
||
;; `ansi-color-apply-on-region' to colorize a region containing SGR
|
||
;; control sequences.
|
||
;;
|
||
;; `ansi-color-filter-region' to filter SGR control sequences from a
|
||
;; region.
|
||
|
||
;;; Thanks
|
||
|
||
;; Georges Brun-Cottan <gbruncot@emc.com> for improving ansi-color.el
|
||
;; substantially by adding the code needed to cope with arbitrary chunks
|
||
;; of output and the filter functions.
|
||
;;
|
||
;; Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk> for pointing me to ECMA-48.
|
||
;;
|
||
;; Stefan Monnier <foo@acm.com> for explaining obscure font-lock stuff and for
|
||
;; code suggestions.
|
||
|
||
|
||
|
||
;;; Code:
|
||
|
||
(defvar comint-last-output-start)
|
||
(defvar compilation-filter-start)
|
||
|
||
;; Customization
|
||
|
||
(defgroup ansi-colors nil
|
||
"Translating SGR control sequences to faces.
|
||
This translation effectively colorizes strings and regions based upon
|
||
SGR control sequences embedded in the text. SGR (Select Graphic
|
||
Rendition) control sequences are defined in section 8.3.117 of the
|
||
ECMA-48 standard (identical to ISO/IEC 6429), which is freely available
|
||
at <URL:https://www.ecma-international.org/publications/standards/Ecma-048.htm>
|
||
as a PDF file."
|
||
:version "21.1"
|
||
:group 'processes)
|
||
|
||
(defface ansi-color-bold
|
||
'((t :inherit bold))
|
||
"Face used to render bold text."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-faint
|
||
'((t :weight light))
|
||
"Face used to render faint text."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-italic
|
||
'((t :inherit italic))
|
||
"Face used to render italic text."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-underline
|
||
'((t :inherit underline))
|
||
"Face used to render underlined text."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-slow-blink
|
||
'((t :box (:line-width -1)))
|
||
"Face used to render slowly blinking text."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-fast-blink
|
||
'((t :box (:line-width -1)))
|
||
"Face used to render rapidly blinking text."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-inverse
|
||
'((t :inverse-video t))
|
||
"Face used to render inverted video text."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-black
|
||
'((t :foreground "black" :background "black"))
|
||
"Face used to render black color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-red
|
||
'((t :foreground "red3" :background "red3"))
|
||
"Face used to render red color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-green
|
||
'((t :foreground "green3" :background "green3"))
|
||
"Face used to render green color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-yellow
|
||
'((t :foreground "yellow3" :background "yellow3"))
|
||
"Face used to render yellow color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-blue
|
||
'((t :foreground "blue2" :background "blue2"))
|
||
"Face used to render blue color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-magenta
|
||
'((t :foreground "magenta3" :background "magenta3"))
|
||
"Face used to render magenta color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-cyan
|
||
'((t :foreground "cyan3" :background "cyan3"))
|
||
"Face used to render cyan color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-white
|
||
'((t :foreground "grey90" :background "gray90"))
|
||
"Face used to render white color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-bright-black
|
||
'((t :foreground "gray30" :background "gray30"))
|
||
"Face used to render bright black color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-bright-red
|
||
'((t :foreground "red2" :background "red2"))
|
||
"Face used to render bright red color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-bright-green
|
||
'((t :foreground "green2" :background "green2"))
|
||
"Face used to render bright green color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-bright-yellow
|
||
'((t :foreground "yellow2" :background "yellow2"))
|
||
"Face used to render bright yellow color code."
|
||
:group 'ansi-colors)
|
||
|
||
(defface ansi-color-bright-blue
|
||
'((t :foreground "blue1" :background "blue1"))
|
||
"Face used to render bright blue color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-bright-magenta
|
||
'((t :foreground "magenta2" :background "magenta2"))
|
||
"Face used to render bright magenta color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-bright-cyan
|
||
'((t :foreground "cyan2" :background "cyan2"))
|
||
"Face used to render bright cyan color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defface ansi-color-bright-white
|
||
'((t :foreground "white" :background "white"))
|
||
"Face used to render bright white color code."
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defcustom ansi-color-faces-vector
|
||
[default bold default italic underline success warning error]
|
||
"Faces used for SGR control sequences determining a face.
|
||
This vector holds the faces used for SGR control sequence parameters 0
|
||
to 7.
|
||
|
||
This variable is obsolete. To customize the display of faces used by
|
||
ansi-color, change `ansi-color-FACE', e.g. `ansi-color-bold'. To
|
||
customize the actual faces used (e.g. to temporarily display SGR
|
||
control sequences differently), use `ansi-color-basic-faces-vector'."
|
||
:type '(vector face face face face face face face face)
|
||
:group 'ansi-colors)
|
||
(make-obsolete-variable 'ansi-color-faces-vector 'ansi-color-basic-faces-vector
|
||
"28.1")
|
||
|
||
(defcustom ansi-color-names-vector
|
||
["black" "red3" "green3" "yellow3" "blue2" "magenta3" "cyan3" "gray90"]
|
||
"Colors used for SGR control sequences determining a color.
|
||
This vector holds the colors used for SGR control sequence parameters
|
||
30 to 37 (foreground colors) and 40 to 47 (background colors).
|
||
|
||
This variable is obsolete. To customize the display of colors used by
|
||
ansi-color, change `ansi-color-COLOR', e.g. `ansi-color-red'. To
|
||
customize the actual faces used (e.g. to temporarily display SGR
|
||
control sequences differently), use `ansi-color-normal-colors-vector'."
|
||
:type '(vector (choice color (cons color color))
|
||
(choice color (cons color color))
|
||
(choice color (cons color color))
|
||
(choice color (cons color color))
|
||
(choice color (cons color color))
|
||
(choice color (cons color color))
|
||
(choice color (cons color color))
|
||
(choice color (cons color color)))
|
||
:version "24.4" ; default colors copied from `xterm-standard-colors'
|
||
:group 'ansi-colors)
|
||
(make-obsolete-variable 'ansi-color-faces-vector
|
||
'ansi-color-normal-colors-vector "28.1")
|
||
|
||
(defvar ansi-color-basic-faces-vector
|
||
[nil
|
||
ansi-color-bold
|
||
ansi-color-faint
|
||
ansi-color-italic
|
||
ansi-color-underline
|
||
ansi-color-slow-blink
|
||
ansi-color-fast-blink
|
||
ansi-color-inverse]
|
||
"Faces used for SGR control sequences determining a face.
|
||
This vector holds the faces used for SGR control sequence parameters 0
|
||
to 7.
|
||
|
||
Parameter Description
|
||
0 default
|
||
1 bold
|
||
2 faint
|
||
3 italic
|
||
4 underlined
|
||
5 slowly blinking
|
||
6 rapidly blinking
|
||
7 negative image")
|
||
|
||
(defvar ansi-color-normal-colors-vector
|
||
[ansi-color-black
|
||
ansi-color-red
|
||
ansi-color-green
|
||
ansi-color-yellow
|
||
ansi-color-blue
|
||
ansi-color-magenta
|
||
ansi-color-cyan
|
||
ansi-color-white]
|
||
"Faces used for SGR control sequences determining a color.
|
||
This vector holds the faces used for SGR control sequence parameters
|
||
30 to 37 (foreground colors) and 40 to 47 (background colors).
|
||
|
||
Parameter Color
|
||
30 40 black
|
||
31 41 red
|
||
32 42 green
|
||
33 43 yellow
|
||
34 44 blue
|
||
35 45 magenta
|
||
36 46 cyan
|
||
37 47 white")
|
||
|
||
(defvar ansi-color-bright-colors-vector
|
||
[ansi-color-bright-black
|
||
ansi-color-bright-red
|
||
ansi-color-bright-green
|
||
ansi-color-bright-yellow
|
||
ansi-color-bright-blue
|
||
ansi-color-bright-magenta
|
||
ansi-color-bright-cyan
|
||
ansi-color-bright-white]
|
||
"Faces used for SGR control sequences determining a \"bright\" color.
|
||
This vector holds the faces used for SGR control sequence parameters
|
||
90 to 97 (bright foreground colors) and 100 to 107 (bright background
|
||
colors).
|
||
|
||
Parameter Color
|
||
90 100 bright black
|
||
91 101 bright red
|
||
92 102 bright green
|
||
93 103 bright yellow
|
||
94 104 bright blue
|
||
95 105 bright magenta
|
||
96 106 bright cyan
|
||
97 107 bright white")
|
||
|
||
(defcustom ansi-color-bold-is-bright nil
|
||
"If set to non-nil, combining ANSI bold and a color produces the bright
|
||
version of that color."
|
||
:type 'boolean
|
||
:version "28.1"
|
||
:group 'ansi-colors)
|
||
|
||
(defconst ansi-color-control-seq-regexp
|
||
;; See ECMA 48, section 5.4 "Control Sequences".
|
||
"\e\\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]"
|
||
"Regexp matching an ANSI control sequence.")
|
||
|
||
(defconst ansi-color--control-seq-fragment-regexp
|
||
"\e\\[[\x30-\x3F]*[\x20-\x2F]*\\|\e"
|
||
"Regexp matching a partial ANSI control sequence.")
|
||
|
||
(defconst ansi-color-parameter-regexp "\\([0-9]*\\)[m;]"
|
||
"Regexp that matches SGR control sequence parameters.")
|
||
|
||
;; Convenience functions for comint modes (eg. shell-mode)
|
||
|
||
|
||
(defcustom ansi-color-for-comint-mode t
|
||
"Determines what to do with comint output.
|
||
If nil, do nothing.
|
||
If the symbol `filter', then filter all SGR control sequences.
|
||
If anything else (such as t), then translate SGR control sequences
|
||
into text properties.
|
||
|
||
In order for this to have any effect, `ansi-color-process-output' must
|
||
be in `comint-output-filter-functions'.
|
||
|
||
This can be used to enable colorized ls --color=yes output
|
||
in shell buffers. You set this variable by calling one of:
|
||
\\[ansi-color-for-comint-mode-on]
|
||
\\[ansi-color-for-comint-mode-off]
|
||
\\[ansi-color-for-comint-mode-filter]"
|
||
:type '(choice (const :tag "Do nothing" nil)
|
||
(const :tag "Filter" filter)
|
||
(const :tag "Translate" t))
|
||
:group 'ansi-colors
|
||
:version "23.2")
|
||
|
||
(defcustom ansi-color-for-compilation-mode t
|
||
"Determines what to do with compilation output.
|
||
If nil, do nothing.
|
||
|
||
If the symbol `filter', then filter all ANSI graphical control
|
||
sequences.
|
||
|
||
If anything else (such as t), then translate ANSI graphical
|
||
control sequences into text properties.
|
||
|
||
In order for this to have any effect, `ansi-color-compilation-filter'
|
||
must be in `compilation-filter-hook'."
|
||
:type '(choice (const :tag "Do nothing" nil)
|
||
(const :tag "Filter" filter)
|
||
(other :tag "Translate" t))
|
||
:group 'ansi-colors
|
||
:version "28.1")
|
||
|
||
(defvar ansi-color-apply-face-function #'ansi-color-apply-overlay-face
|
||
"Function for applying an Ansi Color face to text in a buffer.
|
||
This function should accept three arguments: BEG, END, and FACE,
|
||
and it should apply face FACE to the text between BEG and END.")
|
||
|
||
;;;###autoload
|
||
(defun ansi-color-for-comint-mode-on ()
|
||
"Set `ansi-color-for-comint-mode' to t."
|
||
(interactive)
|
||
(setq ansi-color-for-comint-mode t))
|
||
|
||
(defun ansi-color-for-comint-mode-off ()
|
||
"Set `ansi-color-for-comint-mode' to nil."
|
||
(interactive)
|
||
(setq ansi-color-for-comint-mode nil))
|
||
|
||
(defun ansi-color-for-comint-mode-filter ()
|
||
"Set `ansi-color-for-comint-mode' to symbol `filter'."
|
||
(interactive)
|
||
(setq ansi-color-for-comint-mode 'filter))
|
||
|
||
;;;###autoload
|
||
(defun ansi-color-process-output (_ignored)
|
||
"Maybe translate SGR control sequences of comint output into text properties.
|
||
|
||
Depending on variable `ansi-color-for-comint-mode' the comint output is
|
||
either not processed, SGR control sequences are filtered using
|
||
`ansi-color-filter-region', or SGR control sequences are translated into
|
||
text properties using `ansi-color-apply-on-region'.
|
||
|
||
The comint output is assumed to lie between the marker
|
||
`comint-last-output-start' and the process-mark.
|
||
|
||
This is a good function to put in `comint-output-filter-functions'."
|
||
(let ((start-marker (if (and (markerp comint-last-output-start)
|
||
(eq (marker-buffer comint-last-output-start)
|
||
(current-buffer))
|
||
(marker-position comint-last-output-start))
|
||
comint-last-output-start
|
||
(point-min-marker)))
|
||
(end-marker (process-mark (get-buffer-process (current-buffer)))))
|
||
(cond ((eq ansi-color-for-comint-mode nil))
|
||
((eq ansi-color-for-comint-mode 'filter)
|
||
(ansi-color-filter-region start-marker end-marker))
|
||
(t
|
||
(ansi-color-apply-on-region start-marker end-marker)))))
|
||
|
||
;;;###autoload
|
||
(defun ansi-color-compilation-filter ()
|
||
"Maybe translate SGR control sequences into text properties.
|
||
This function depends on the `ansi-color-for-compilation-mode'
|
||
variable, and is meant to be used in `compilation-filter-hook'."
|
||
(let ((inhibit-read-only t))
|
||
(pcase ansi-color-for-compilation-mode
|
||
('nil nil)
|
||
('filter
|
||
(ansi-color-filter-region compilation-filter-start (point)))
|
||
(_
|
||
(ansi-color-apply-on-region compilation-filter-start (point))))))
|
||
|
||
;; Working with strings
|
||
(defvar-local ansi-color-context nil
|
||
"Context saved between two calls to `ansi-color-apply'.
|
||
This is a list of the form (FACE-VEC FRAGMENT) or nil. FACE-VEC
|
||
represents the state the last call to `ansi-color-apply' ended
|
||
with, currently a list of the form:
|
||
|
||
(BASIC-FACES FG BG)
|
||
|
||
BASIC-FACES is a bool-vector that specifies which basic faces
|
||
from `ansi-color-basic-faces-vector' to apply. FG and BG are
|
||
ANSI color codes for the foreground and background color.
|
||
|
||
FRAGMENT is a string starting with an escape sequence, possibly
|
||
the start of a new escape sequence.")
|
||
|
||
(defun ansi-color-filter-apply (string)
|
||
"Filter out all ANSI control sequences from STRING.
|
||
|
||
Every call to this function will set and use the buffer-local variable
|
||
`ansi-color-context' to save partial escape sequences. This information
|
||
will be used for the next call to `ansi-color-apply'. Set
|
||
`ansi-color-context' to nil if you don't want this.
|
||
|
||
This function can be added to `comint-preoutput-filter-functions'."
|
||
(let ((context (ansi-color--ensure-context 'ansi-color-context nil))
|
||
(start 0) end result)
|
||
;; if context was saved and is a string, prepend it
|
||
(setq string (concat (cadr context) string))
|
||
(setcar (cdr context) "")
|
||
;; find the next escape sequence
|
||
(while (setq end (string-match ansi-color-control-seq-regexp string start))
|
||
(push (substring string start end) result)
|
||
(setq start (match-end 0)))
|
||
;; save context, add the remainder of the string to the result
|
||
(let ((fragment ""))
|
||
(push (substring string start
|
||
(if (string-match
|
||
(concat "\\(?:"
|
||
ansi-color--control-seq-fragment-regexp
|
||
"\\)\\'")
|
||
string start)
|
||
(let ((pos (match-beginning 0)))
|
||
(setq fragment (substring string pos))
|
||
pos)
|
||
nil))
|
||
result)
|
||
(setcar (cdr context) fragment))
|
||
(apply #'concat (nreverse result))))
|
||
|
||
(defun ansi-color-apply (string)
|
||
"Translates SGR control sequences into text properties.
|
||
Delete all other control sequences without processing them.
|
||
|
||
Applies SGR control sequences setting foreground and background colors
|
||
to STRING using text properties and returns the result. See function
|
||
`ansi-color-apply-sequence' for details.
|
||
|
||
Every call to this function will set and use the buffer-local variable
|
||
`ansi-color-context' to save partial escape sequences and current ansi codes.
|
||
This information will be used for the next call to `ansi-color-apply'.
|
||
Set `ansi-color-context' to nil if you don't want this.
|
||
|
||
This function can be added to `comint-preoutput-filter-functions'."
|
||
(let* ((context
|
||
(ansi-color--ensure-context 'ansi-color-context nil))
|
||
(face-vec (car context))
|
||
(start 0)
|
||
end result)
|
||
;; If context was saved and is a string, prepend it.
|
||
(setq string (concat (cadr context) string))
|
||
(setcar (cdr context) "")
|
||
;; Find the next escape sequence.
|
||
(while (setq end (string-match ansi-color-control-seq-regexp string start))
|
||
(let ((esc-end (match-end 0)))
|
||
;; Colorize the old block from start to end using old face.
|
||
(when-let* ((face (ansi-color--face-vec-face face-vec)))
|
||
(put-text-property start end 'font-lock-face
|
||
face string))
|
||
(push (substring string start end) result)
|
||
(setq start (match-end 0))
|
||
;; If this is a color escape sequence,
|
||
(when (eq (aref string (1- esc-end)) ?m)
|
||
;; create a new face from it.
|
||
(let ((cur-pos end))
|
||
(ansi-color--update-face-vec
|
||
face-vec
|
||
(lambda ()
|
||
(when (string-match ansi-color-parameter-regexp
|
||
string cur-pos)
|
||
(setq cur-pos (match-end 0))
|
||
(when (<= cur-pos esc-end)
|
||
(string-to-number (match-string 1 string))))))))))
|
||
;; if the rest of the string should have a face, put it there
|
||
(when-let* ((face (ansi-color--face-vec-face face-vec)))
|
||
(put-text-property start (length string)
|
||
'font-lock-face face string))
|
||
;; save context, add the remainder of the string to the result
|
||
(if (string-match
|
||
(concat "\\(?:" ansi-color--control-seq-fragment-regexp "\\)\\'")
|
||
string start)
|
||
(let ((pos (match-beginning 0)))
|
||
(setcar (cdr context) (substring string pos))
|
||
(push (substring string start pos) result))
|
||
(push (substring string start) result))
|
||
(apply 'concat (nreverse result))))
|
||
|
||
(defun ansi-color--ensure-context (context-sym position)
|
||
"Return CONTEXT-SYM's value as a valid context.
|
||
If it is nil, set CONTEXT-SYM's value to a new context and return it.
|
||
Context is a list of the form as described in `ansi-color-context' if
|
||
POSITION is nil, or `ansi-color-context-region' if POSITION is non-nil.
|
||
|
||
If CONTEXT-SYM's value is already non-nil, return it. If its
|
||
marker doesn't point anywhere yet, position it before character
|
||
number POSITION, if non-nil."
|
||
(let ((context (symbol-value context-sym)))
|
||
(if context
|
||
(if position
|
||
(let ((marker (cadr context)))
|
||
(unless (marker-position marker)
|
||
(set-marker marker position))
|
||
context)
|
||
context)
|
||
(set context-sym
|
||
(list (list (make-bool-vector 8 nil)
|
||
nil nil)
|
||
(if position
|
||
(copy-marker position)
|
||
""))))))
|
||
|
||
(defun ansi-color--face-vec-face (face-vec)
|
||
"Return the face corresponding to FACE-VEC.
|
||
FACE-VEC is a list containing information about the ANSI sequence
|
||
code. It is usually stored as the car of the variable
|
||
`ansi-color-context-region'."
|
||
(let* ((basic-faces (car face-vec))
|
||
(colors (cdr face-vec))
|
||
(bright (and ansi-color-bold-is-bright (aref basic-faces 1)))
|
||
(faces nil))
|
||
|
||
(when-let* ((fg (car colors)))
|
||
(push
|
||
`(:foreground
|
||
,(or (ansi-color--code-as-hex fg)
|
||
(face-foreground
|
||
(aref (if (or bright (>= fg 8))
|
||
ansi-color-bright-colors-vector
|
||
ansi-color-normal-colors-vector)
|
||
(mod fg 8))
|
||
nil 'default)))
|
||
faces))
|
||
(when-let* ((bg (cadr colors)))
|
||
(push
|
||
`(:background
|
||
,(or (ansi-color--code-as-hex bg)
|
||
(face-background
|
||
(aref (if (or bright (>= bg 8))
|
||
ansi-color-bright-colors-vector
|
||
ansi-color-normal-colors-vector)
|
||
(mod bg 8))
|
||
nil 'default)))
|
||
faces))
|
||
|
||
(let ((i 8))
|
||
(while (> i 0)
|
||
(setq i (1- i))
|
||
(when (aref basic-faces i)
|
||
(push (aref ansi-color-basic-faces-vector i) faces))))
|
||
;; Avoid some long-lived conses in the common case.
|
||
(if (cdr faces)
|
||
faces
|
||
(car faces))))
|
||
|
||
(defun ansi-color--code-as-hex (color)
|
||
"Convert COLOR to hexadecimal string representation.
|
||
COLOR is an ANSI color code. If it is between 16 and 255
|
||
inclusive, it corresponds to a color from an 8-bit color cube.
|
||
If it is greater or equal than 256, it is subtracted by 256 to
|
||
directly specify a 24-bit color.
|
||
|
||
Return a hexadecimal string, specifying the color, or nil, if
|
||
COLOR is less than 16."
|
||
(cond
|
||
((< color 16) nil)
|
||
((>= color 256) (format "#%06X" (- color 256)))
|
||
((>= color 232) ;; Grayscale
|
||
(format "#%06X" (* #x010101 (+ 8 (* 10 (- color 232))))))
|
||
(t ;; 6x6x6 color cube
|
||
(setq color (- color 16))
|
||
(let ((res 0)
|
||
(frac (* 6 6)))
|
||
(while (<= 1 frac) ; Repeat 3 times
|
||
(setq res (* res #x000100))
|
||
(let ((color-num (mod (/ color frac) 6)))
|
||
(unless (zerop color-num)
|
||
(setq res (+ res #x37 (* #x28 color-num)))))
|
||
(setq frac (/ frac 6)))
|
||
(format "#%06X" res)))))
|
||
|
||
;; Working with regions
|
||
|
||
(defvar-local ansi-color-context-region nil
|
||
"Context saved between two calls to `ansi-color-apply-on-region'.
|
||
This is a list of the form (FACE-VEC MARKER) or nil. FACE-VEC
|
||
represents the state the last call to `ansi-color-apply-on-region'
|
||
ended with, currently a list of the form:
|
||
|
||
(BASIC-FACES FG BG).
|
||
|
||
BASIC-FACES is a bool-vector that specifies which basic faces
|
||
from `ansi-color-basic-faces-vector' to apply. FG and BG are
|
||
ANSI color codes for the foreground and background color.
|
||
|
||
MARKER is a buffer position within an escape sequence or the last
|
||
position processed.")
|
||
|
||
(defun ansi-color-filter-region (begin end)
|
||
"Filter out all ANSI control sequences from region BEGIN to END.
|
||
|
||
Every call to this function will set and use the buffer-local variable
|
||
`ansi-color-context-region' to save position. This information will be
|
||
used for the next call to `ansi-color-apply-on-region'. Specifically,
|
||
it will override BEGIN, the start of the region. Set
|
||
`ansi-color-context-region' to nil if you don't want this."
|
||
(let* ((end-marker (copy-marker end))
|
||
(context (ansi-color--ensure-context
|
||
'ansi-color-context-region begin))
|
||
(start (cadr context)))
|
||
(save-excursion
|
||
(goto-char start)
|
||
;; Delete escape sequences.
|
||
(while (re-search-forward ansi-color-control-seq-regexp end-marker t)
|
||
(delete-region (match-beginning 0) (match-end 0)))
|
||
;; save context, add the remainder of the string to the result
|
||
(set-marker start (point))
|
||
(while (re-search-forward ansi-color--control-seq-fragment-regexp
|
||
end-marker t))
|
||
(if (and (/= (point) start)
|
||
(= (point) end-marker))
|
||
(set-marker start (match-beginning 0))
|
||
(set-marker start nil)))))
|
||
|
||
(defun ansi-color-apply-on-region (begin end &optional preserve-sequences)
|
||
"Translates SGR control sequences into overlays or extents.
|
||
Delete all other control sequences without processing them.
|
||
|
||
SGR control sequences are applied by calling the function
|
||
specified by `ansi-color-apply-face-function'. The default
|
||
function sets foreground and background colors to the text
|
||
between BEGIN and END, using overlays. See function
|
||
`ansi-color-apply-sequence' for details.
|
||
|
||
Every call to this function will set and use the buffer-local
|
||
variable `ansi-color-context-region' to save position and current
|
||
ansi codes. This information will be used for the next call to
|
||
`ansi-color-apply-on-region'. Specifically, it will override
|
||
BEGIN, the start of the region and set the face with which to
|
||
start. Set `ansi-color-context-region' to nil if you don't want
|
||
this.
|
||
|
||
If PRESERVE-SEQUENCES is t, the sequences are hidden instead of
|
||
being deleted."
|
||
(let* ((context (ansi-color--ensure-context
|
||
'ansi-color-context-region begin))
|
||
(face-vec (car context))
|
||
(start-marker (cadr context))
|
||
(end-marker (copy-marker end)))
|
||
(save-excursion
|
||
(goto-char start-marker)
|
||
;; Find the next escape sequence.
|
||
(while (re-search-forward ansi-color-control-seq-regexp end-marker t)
|
||
;; Extract escape sequence.
|
||
(let ((esc-beg (match-beginning 0))
|
||
(esc-end (point)))
|
||
;; Colorize the old block from start to end using old face.
|
||
(funcall ansi-color-apply-face-function
|
||
(prog1 (marker-position start-marker)
|
||
;; Store new start position.
|
||
(set-marker start-marker esc-end))
|
||
esc-beg (ansi-color--face-vec-face face-vec))
|
||
;; If this is a color sequence,
|
||
(when (eq (char-before esc-end) ?m)
|
||
(goto-char esc-beg)
|
||
(ansi-color--update-face-vec
|
||
face-vec (lambda ()
|
||
(when (re-search-forward ansi-color-parameter-regexp
|
||
esc-end t)
|
||
(string-to-number (match-string 1))))))
|
||
|
||
(if preserve-sequences
|
||
;; Make the escape sequence transparent.
|
||
(overlay-put (make-overlay esc-beg esc-end) 'invisible t)
|
||
;; Otherwise, strip.
|
||
(delete-region esc-beg esc-end))))
|
||
;; search for the possible start of a new escape sequence
|
||
(while (re-search-forward ansi-color--control-seq-fragment-regexp
|
||
end-marker t))
|
||
(if (and (/= (point) start-marker)
|
||
(= (point) end-marker))
|
||
(progn
|
||
(goto-char (match-beginning 0))
|
||
(funcall ansi-color-apply-face-function
|
||
start-marker (point)
|
||
(ansi-color--face-vec-face face-vec))
|
||
(set-marker start-marker (point)))
|
||
(let ((faces (ansi-color--face-vec-face face-vec)))
|
||
(funcall ansi-color-apply-face-function
|
||
start-marker end-marker faces)
|
||
;; Save a restart position when there are codes active. It's
|
||
;; convenient for man.el's process filter to pass `begin'
|
||
;; positions that overlap regions previously colored; these
|
||
;; `codes' should not be applied to that overlap, so we need
|
||
;; to know where they should really start.
|
||
(set-marker start-marker (when faces end-marker)))))
|
||
;; Clean up our temporary marker.
|
||
(set-marker end-marker nil)))
|
||
|
||
(defun ansi-color-apply-overlay-face (beg end face)
|
||
"Make an overlay from BEG to END, and apply face FACE.
|
||
If FACE is nil, do nothing."
|
||
(when face
|
||
(overlay-put (ansi-color-make-extent beg end) 'face face)))
|
||
|
||
(defun ansi-color-apply-text-property-face (beg end face)
|
||
"Set the `font-lock-face' property to FACE in region BEG..END.
|
||
If FACE is nil, do nothing."
|
||
(when face
|
||
(put-text-property beg end 'font-lock-face face)))
|
||
|
||
;; This function helps you look for overlapping overlays. This is
|
||
;; useful in comint-buffers. Overlapping overlays should not happen!
|
||
;; A possible cause for bugs are the markers. If you create an overlay
|
||
;; up to the end of the region, then that end might coincide with the
|
||
;; process-mark. As text is added BEFORE the process-mark, the overlay
|
||
;; will keep growing. Therefore, as more overlays are created later on,
|
||
;; there will be TWO OR MORE overlays covering the buffer at that point.
|
||
;; This function helps you check your buffer for these situations.
|
||
; (defun ansi-color-debug-overlays ()
|
||
; (interactive)
|
||
; (let ((pos (point-min)))
|
||
; (while (< pos (point-max))
|
||
; (if (<= 2 (length (overlays-at pos)))
|
||
; (progn
|
||
; (goto-char pos)
|
||
; (error "%d overlays at %d" (length (overlays-at pos)) pos))
|
||
; (let (message-log-max)
|
||
; (message "Reached %d." pos)))
|
||
; (setq pos (next-overlay-change pos)))))
|
||
|
||
(defun ansi-color-make-face (property color)
|
||
"Return a face with PROPERTY set to COLOR.
|
||
PROPERTY can be either symbol `foreground' or symbol `background'.
|
||
|
||
For Emacs, we just return the cons cell (PROPERTY . COLOR)."
|
||
(cond ((eq property 'foreground)
|
||
(cons 'foreground-color color))
|
||
((eq property 'background)
|
||
(cons 'background-color color))
|
||
(t
|
||
(cons property color))))
|
||
|
||
(defun ansi-color-make-extent (from to &optional buffer)
|
||
"Make an extent for the range [FROM, TO) in BUFFER.
|
||
|
||
BUFFER defaults to the current buffer."
|
||
;; The overlay might end at the process-mark in comint
|
||
;; buffers. In that case, new text will be inserted before the
|
||
;; process-mark, ie. inside the overlay (using insert-before-marks).
|
||
;; In order to avoid this, we use the `insert-behind-hooks' overlay
|
||
;; property to make sure it works.
|
||
(let ((overlay (make-overlay from to buffer)))
|
||
(overlay-put overlay 'evaporate t)
|
||
(overlay-put overlay 'modification-hooks '(ansi-color-freeze-overlay))
|
||
(overlay-put overlay 'insert-behind-hooks '(ansi-color-freeze-overlay))
|
||
overlay))
|
||
|
||
(defun ansi-color-freeze-overlay (overlay is-after begin end &optional len)
|
||
"Prevent OVERLAY from being extended.
|
||
This function can be used for the `modification-hooks' overlay
|
||
property."
|
||
;; if stuff was inserted at the end of the overlay
|
||
(when (and is-after
|
||
(= 0 len)
|
||
(= end (overlay-end overlay)))
|
||
;; reset the end of the overlay
|
||
(move-overlay overlay (overlay-start overlay) begin)))
|
||
|
||
(defun ansi-color-set-extent-face (extent face)
|
||
"Set the `face' property of EXTENT to FACE."
|
||
(declare (obsolete overlay-put "27.1"))
|
||
(overlay-put extent 'face face))
|
||
|
||
;; Helper functions
|
||
|
||
(defsubst ansi-color-parse-sequence (escape-seq)
|
||
"Return the list of all the parameters in ESCAPE-SEQ.
|
||
|
||
ESCAPE-SEQ is a SGR control sequences such as \\033[34m. The parameter
|
||
34 is used by `ansi-color-get-face-1' to return a face definition.
|
||
|
||
Returns nil only if there's no match for `ansi-color-parameter-regexp'."
|
||
(let ((i 0)
|
||
codes val)
|
||
(while (string-match ansi-color-parameter-regexp escape-seq i)
|
||
(setq i (match-end 0)
|
||
val (string-to-number (match-string 1 escape-seq) 10))
|
||
;; It so happens that (string-to-number "") => 0.
|
||
(push val codes))
|
||
(nreverse codes)))
|
||
|
||
(defun ansi-color-apply-sequence (escape-sequence codes)
|
||
"Apply ESCAPE-SEQUENCE to CODES and return the new list of codes.
|
||
|
||
ESCAPE-SEQUENCE is an escape sequence parsed by
|
||
`ansi-color-parse-sequence'.
|
||
|
||
For each new code, the following happens: if it is 1-7, add it to
|
||
the list of codes; if it is 21-25 or 27, delete appropriate
|
||
parameters from the list of codes; if it is 30-37 (or 90-97) resp. 39,
|
||
the foreground color code is replaced or added resp. deleted; if it
|
||
is 40-47 (or 100-107) resp. 49, the background color code is replaced
|
||
or added resp. deleted; any other code is discarded together with the
|
||
old codes. Finally, the so changed list of codes is returned."
|
||
(declare (obsolete ansi-color--update-face-vec "29.1"))
|
||
(let ((new-codes (ansi-color-parse-sequence escape-sequence)))
|
||
(while new-codes
|
||
(let* ((new (pop new-codes))
|
||
(q (/ new 10)))
|
||
(setq codes
|
||
(pcase q
|
||
(0 (unless (memq new '(0 8 9))
|
||
(cons new (remq new codes))))
|
||
(2 (unless (memq new '(20 26 28 29))
|
||
;; The standard says `21 doubly underlined' while
|
||
;; https://en.wikipedia.org/wiki/ANSI_escape_code claims
|
||
;; `21 Bright/Bold: off or Underline: Double'.
|
||
(remq (- new 20) (pcase new
|
||
(22 (remq 1 codes))
|
||
(25 (remq 6 codes))
|
||
(_ codes)))))
|
||
((or 3 4 9 10) (let ((r (mod new 10)))
|
||
(unless (= r 8)
|
||
(let (beg)
|
||
(while (and codes (/= q (/ (car codes) 10)))
|
||
(push (pop codes) beg))
|
||
(setq codes (nconc (nreverse beg) (cdr codes)))
|
||
(if (= r 9)
|
||
codes
|
||
(cons new codes))))))
|
||
(_ nil)))))
|
||
codes))
|
||
|
||
(defun ansi-color--update-face-vec (face-vec iterator)
|
||
"Apply escape sequences to FACE-VEC.
|
||
|
||
Destructively modify FACE-VEC, which should be a list containing
|
||
face information. It is described in
|
||
`ansi-color-context-region'. ITERATOR is a function which is
|
||
called repeatedly with zero arguments and should return either
|
||
the next ANSI code in the current sequence as a number or nil if
|
||
there are no more ANSI codes left.
|
||
|
||
For each new code, the following happens: if it is 1-7, set the
|
||
corresponding properties; if it is 21-25 or 27, unset appropriate
|
||
properties; if it is 30-37 (or 90-97) or resp. 39, set the
|
||
foreground color or resp. unset it; if it is 40-47 (or 100-107)
|
||
resp. 49, set the background color or resp. unset it; if it is 38
|
||
or 48, the following codes are used to set the foreground or
|
||
background color and the correct color mode; any other code will
|
||
unset all properties and colors."
|
||
(let ((basic-faces (car face-vec))
|
||
(colors (cdr face-vec))
|
||
new q do-clear)
|
||
(while (setq new (funcall iterator))
|
||
(setq q (/ new 10))
|
||
(pcase q
|
||
(0 (if (memq new '(0 8 9))
|
||
(setq do-clear t)
|
||
(aset basic-faces new t)))
|
||
(2 (if (memq new '(20 26 28 29))
|
||
(setq do-clear t)
|
||
;; The standard says `21 doubly underlined' while
|
||
;; https://en.wikipedia.org/wiki/ANSI_escape_code claims
|
||
;; `21 Bright/Bold: off or Underline: Double'.
|
||
(aset basic-faces (- new 20) nil)
|
||
(aset basic-faces (pcase new (22 1) (25 6) (_ 0)) nil)))
|
||
((or 3 4 9 10)
|
||
(let ((r (mod new 10))
|
||
(cell (if (memq q '(3 9)) colors (cdr colors))))
|
||
(pcase r
|
||
(8
|
||
(pcase (funcall iterator)
|
||
(5 (setq new (setcar cell (funcall iterator)))
|
||
(setq do-clear (or (null new) (>= new 256))))
|
||
(2
|
||
(let ((red (funcall iterator))
|
||
(green (funcall iterator))
|
||
(blue (funcall iterator)))
|
||
(if (and red green blue
|
||
(progn
|
||
(setq new (+ (* #x010000 red)
|
||
(* #x000100 green)
|
||
(* #x000001 blue)))
|
||
(<= new #xFFFFFF)))
|
||
(setcar cell (+ 256 new))
|
||
(setq do-clear t))))
|
||
(_ (setq do-clear t))))
|
||
(9 (setcar cell nil))
|
||
(_ (setcar cell (+ (if (memq q '(3 4)) 0 8) r))))))
|
||
(_ (setq do-clear t)))
|
||
|
||
(when do-clear
|
||
(setq do-clear nil)
|
||
;; Zero out our bool vector without any allocation.
|
||
(bool-vector-intersection basic-faces #&8"\0" basic-faces)
|
||
(setcar colors nil)
|
||
(setcar (cdr colors) nil)))))
|
||
|
||
(defun ansi-color-make-color-map ()
|
||
"Create a vector of face definitions and return it.
|
||
|
||
The index into the vector is an ANSI code. See the documentation of
|
||
`ansi-color-map' for an example.
|
||
|
||
The face definitions are based upon the variables
|
||
`ansi-color-faces-vector' and `ansi-color-names-vector'.
|
||
|
||
This function is obsolete, and no longer needed to use ansi-color."
|
||
(let ((map (make-vector 50 nil))
|
||
(index 0))
|
||
;; miscellaneous attributes
|
||
(mapc
|
||
(lambda (e)
|
||
(aset map index e)
|
||
(setq index (1+ index)) )
|
||
ansi-color-faces-vector)
|
||
;; foreground attributes
|
||
(setq index 30)
|
||
(mapc
|
||
(lambda (e)
|
||
(aset map index
|
||
(ansi-color-make-face 'foreground
|
||
(if (consp e) (car e) e)))
|
||
(setq index (1+ index)) )
|
||
ansi-color-names-vector)
|
||
;; background attributes
|
||
(setq index 40)
|
||
(mapc
|
||
(lambda (e)
|
||
(aset map index
|
||
(ansi-color-make-face 'background
|
||
(if (consp e) (cdr e) e)))
|
||
(setq index (1+ index)) )
|
||
ansi-color-names-vector)
|
||
map))
|
||
(make-obsolete 'ansi-color-make-color-map "you can remove it." "28.1")
|
||
|
||
(defvar ansi-color-map
|
||
(with-no-warnings (ansi-color-make-color-map))
|
||
"A brand new color map, formerly suitable for `ansi-color-get-face'.
|
||
|
||
The value of this variable is usually constructed by
|
||
`ansi-color-make-color-map'. The values in the array are such that the
|
||
numbers included in an SGR control sequences point to the correct
|
||
foreground or background colors.
|
||
|
||
This variable is obsolete, and no longer needed to use ansi-color.")
|
||
(make-obsolete-variable 'ansi-color-map "you can remove it." "28.1")
|
||
|
||
(defun ansi-color-map-update (symbol value)
|
||
"Update `ansi-color-map'.
|
||
|
||
This function is obsolete, and no longer needed to use ansi-color."
|
||
(set-default symbol value)
|
||
(with-no-warnings
|
||
(setq ansi-color-map (ansi-color-make-color-map))))
|
||
(make-obsolete 'ansi-color-map-update "you can remove it." "28.1")
|
||
|
||
(defun ansi-color-get-face-1 (ansi-code &optional bright)
|
||
"Get face definition for ANSI-CODE.
|
||
BRIGHT, if non-nil, requests \"bright\" ANSI colors, even if ANSI-CODE
|
||
is a normal-intensity color."
|
||
(declare (obsolete ansi-color--face-vec-face "29.1"))
|
||
(when (and bright (<= 30 ansi-code 49))
|
||
(setq ansi-code (+ ansi-code 60)))
|
||
(cond ((<= 0 ansi-code 7)
|
||
(aref ansi-color-basic-faces-vector ansi-code))
|
||
((<= 30 ansi-code 38)
|
||
(list :foreground
|
||
(face-foreground
|
||
(aref ansi-color-normal-colors-vector (- ansi-code 30))
|
||
nil 'default)))
|
||
((<= 40 ansi-code 48)
|
||
(list :background
|
||
(face-background
|
||
(aref ansi-color-normal-colors-vector (- ansi-code 40))
|
||
nil 'default)))
|
||
((<= 90 ansi-code 98)
|
||
(list :foreground
|
||
(face-foreground
|
||
(aref ansi-color-bright-colors-vector (- ansi-code 90))
|
||
nil 'default)))
|
||
((<= 100 ansi-code 108)
|
||
(list :background
|
||
(face-background
|
||
(aref ansi-color-bright-colors-vector (- ansi-code 100))
|
||
nil 'default)))))
|
||
|
||
(provide 'ansi-color)
|
||
|
||
;;; ansi-color.el ends here
|