[mew-int 00720] Additional highlighting for PBeM email games

Eduard Werner edi.werner at example.com
Thu Feb 21 01:45:03 JST 2002


> > How can things like that be achieved? I've tried with font-lock-mode
> > w.o. success and remarked that mew uses it's own code to to the
> > highlighting but I didn't understand how and where to add my own
> > definitions.
> 
> Please use mew-message-hook.
> (This hook is called whenever a message is displayed.)
> 
> --Kazu
> 

Thank you for your help. I've hacked together a little file displaying
my email game (ASCII) board (Shogi, Tori Shogi, Chu Shogi, Xiangqi,
adding support for other games is easy) with colors for better
readability. It's tailored to work with the PBeM server (www.gamerz.net).
Since it is very short, I have included it at the end in case anybody
is interested (comments on my coding welcome, I'm not a programmer and
like to improve my knowledge).

Best

Edi 
-----
;; PBeM.el by E.Werner, 2002
;; addition to mew to display messages from the PBeM server in color
;; for Shogi, Tori Shogi, Chu Shogi and Xiangqi

(add-hook 'mew-message-hook 'pbem-display)

;; the From: sent by Richard's Server
(defvar pbem-header-from "\"Richard's PBeM Server\" <pbmserv at example.com>")
;; list of supported games
(defvar pbem-losg '("Shogi" "ToriShogi" "ChuShogi" "Xiangqi"))

;; assoc list to get function for supported game
(defvar pbem-losg-assoc '(("Shogi" . pbem-shogi)
			  ("ToriShogi" . pbem-tori)
			  ("ChuShogi" . pbem-chu)
			  ("Xiangqi" . pbem-xiangqi)))

;; faces for the pieces

(defface pbem-red-piece 
  `((((class color) (type tty)) 
     (:foreground "red" :bold t)) 
    (((class color) (background light)) 
     (:foreground "red" :bold t)) 
    (((class color) (background dark)) 
     (:foreground "red" :bold t)) 
    (t (:bold t))) "Red pieces" :group 'pbem-pieces)

(defface pbem-green-piece 
  `((((class color) (type tty)) 
     (:foreground "green" :bold t)) 
    (((class color) (background light)) 
     (:foreground "ForestGreen" :bold t)) 
    (((class color) (background dark)) 
     (:foreground "LimeGreen" :bold t)) 
    (t (:bold t))) "Green pieces" :group 'pbem-pieces)

(defface pbem-black-piece 
  `((((class color) (type tty)) 
     (:foreground "black" :bold t)) 
    (((class color) (background light)) 
     (:foreground "Black" :bold t)) 
    (((class color) (background dark)) 
     (:foreground "Black" :bold t)) 
    (t (:bold t))) "Black pieces" :group 'pbem-pieces)


(defface pbem-white-piece 
  `((((class color) (type tty)) 
     (:foreground "red" :bold t)) 
    (((class color) (background light)) 
     (:foreground "chocolate" :bold t)) 
    (((class color) (background dark)) 
     (:foreground "chocolate" :bold t)) 
    (t (:bold t))) "White pieces" :group 'pbem-pieces)

;; the main function

(defun pbem-display ()
  "Main function to be hooked into mew-message-hook."
  (setq pbem-from (mew-header-get-value mew-from:))
  (if (string= pbem-from pbem-header-from)
      (pbem-parse-message)))

(defun pbem-parse-message () 
  "Parses the email from the PBeM Server."
  ;; first step: decide which game it is
  ;; and whether the game is supported
  (setq pbem-which-game (car (split-string (mew-header-get-value mew-subj:))))
  (if (string= pbem-which-game "New")
      (setq pbem-which-game (car (cdr (split-string (mew-header-get-value mew-subj:))))))
  (if (member pbem-which-game pbem-losg)
      (funcall (cdr (assoc pbem-which-game pbem-losg-assoc)))
    (message "This PBeM game is not (yet) supported")))


(defun pbem-xiangqi ()
  (message "Modern Xiangqi")
  (setq case-fold-search nil)
  (while (re-search-forward "\\(r\\([SCHERGK]\\)\\)" nil t)
    (replace-match "-\\2")
    (put-text-property (match-beginning 1) (match-end 1) 'face 'pbem-red-piece))
  (beginning-of-buffer)
  (while (re-search-forward "\\(g\\([SCHERGK]\\)\\)" nil t)
    (replace-match "-\\2")
    (put-text-property (match-beginning 1) (match-end 1) 'face 'pbem-green-piece))
  (beginning-of-buffer)
  (message "Xiangqi fontified"))

(defun pbem-shogi ()
  (message "Modern Shogi")
  (setq case-fold-search nil)
  (while (re-search-forward "\\(\\(\\+\\)?w\\([KGSNLPBR]\\)\\)" nil t)
    (replace-match "\\2\\3 ")
    (put-text-property (match-beginning 1) (match-end 1) 'face 'pbem-white-piece))
  (beginning-of-buffer)
  (while (re-search-forward "\\(\\(\\+\\)?b\\([KGSNLPBR]\\)\\)" nil t)
    (replace-match "\\2\\3 ")
    (put-text-property (match-beginning 1) (match-end 1) 'face 'pbem-green-piece))
  (beginning-of-buffer)
  (message "Shogi fontified"))

(defun pbem-tori ()
  (message "Tori Shogi")
  (setq case-fold-search nil)
  (while (re-search-forward "\\(\\(\\+\\)?w\\([QPFCES][rtlhwa]\\)\\)" nil t)
    (replace-match "\\2\\3 ")
    (put-text-property (match-beginning 1) (match-end 1) 'face 'pbem-white-piece))
  (beginning-of-buffer)
  (while (re-search-forward "\\(\\(\\+\\)?b\\([QPFCES][rtlhwa]\\)\\)" nil t)
    (replace-match "\\2\\3 ")
    (put-text-property (match-beginning 1) (match-end 1) 'face 'pbem-green-piece))
  (beginning-of-buffer)
  (message "Tori Shogi fontified"))



(defun pbem-chu ()
  (message "Chu Shogi")
  (setq case-fold-search nil)
  (while (re-search-forward "\\(\\(\\+\\)?w\\([A-Z]\\([A-Za-z]\\)?\\)\\)" nil t)
    (replace-match "\\2\\3 ")
    (put-text-property (match-beginning 1) (match-end 1) 'face 'pbem-white-piece))
  (beginning-of-buffer)
  (while (re-search-forward "\\(\\(\\+\\)?b\\([A-Z]\\([A-Za-z]\\)?\\)\\)" nil t)
    (replace-match "\\2\\3 ")
    (put-text-property (match-beginning 1) (match-end 1) 'face 'pbem-green-piece))
  (beginning-of-buffer)
  (message "Chu Shogi fontified"))

;; end of pbem.el



More information about the Mew-int mailing list