読者です 読者をやめる 読者になる 読者になる

Emacsに黒魔道士

emacs

vallog: ターミナルに黒魔道士


Emacs

コード

(require 'cl)

(defun ff3 ()
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (loop with chars = nil
          while (not (eobp))
          do
          (let ((char (buffer-substring-no-properties (point) (1+ (point)))))
            (cond ((string-match "\\([0-9]\\)" char)
                   (let* ((idx (string-to-number (match-string 1 char)))
                          (color (car (tty-color-by-index idx))))
                     (push (propertize " " 'face `((:background ,color))) chars)))
                  ((string= char "\n") (push "\n" chars))
                  (t (push " " chars)))
            (forward-char 1))
          finally
          (let ((str (mapconcat 'identity (reverse chars) ""))
                (buf (get-buffer-create "*ff3*")))
            (with-current-buffer buf
              (erase-buffer)
              (insert str)
              (goto-char (point-min)))
            (pop-to-buffer buf)))))

イメージ

データとなるファイルを開き "M-x ff3" と実行してください