aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-03-18 11:15:50 +0100
committerLars Ingebrigtsen2021-03-18 11:15:50 +0100
commit4eb030319725cfe7fe17049e91fdbed2e222a3c9 (patch)
tree9b049baef6fc457f11e2238fd0a3e2be77ec60fe
parent869b3efe1e4b72b060d1eb495e17f28008bcbeaf (diff)
downloademacs-4eb030319725cfe7fe17049e91fdbed2e222a3c9.tar.gz
emacs-4eb030319725cfe7fe17049e91fdbed2e222a3c9.zip
Compute chart-face-list dynamically
* lisp/emacs-lisp/chart.el (chart-face-list): Allow a function as the value (bug#47133) so that we can compute the faces dynamically on different displays. (chart--face-list): New function. (chart-draw-data): Use it.
-rw-r--r--lisp/emacs-lisp/chart.el64
1 files changed, 36 insertions, 28 deletions
diff --git a/lisp/emacs-lisp/chart.el b/lisp/emacs-lisp/chart.el
index 40c17b916f9..5afc6d3bde3 100644
--- a/lisp/emacs-lisp/chart.el
+++ b/lisp/emacs-lisp/chart.el
@@ -89,33 +89,39 @@ Useful if new Emacs is used on B&W display.")
89 89
90(declare-function x-display-color-cells "xfns.c" (&optional terminal)) 90(declare-function x-display-color-cells "xfns.c" (&optional terminal))
91 91
92(defvar chart-face-list 92(defvar chart-face-list #'chart--face-list
93 (if (display-color-p)
94 (let ((cl chart-face-color-list)
95 (pl chart-face-pixmap-list)
96 (faces ())
97 nf)
98 (while cl
99 (setq nf (make-face
100 (intern (concat "chart-" (car cl) "-" (car pl)))))
101 (set-face-background nf (if (condition-case nil
102 (> (x-display-color-cells) 4)
103 (error t))
104 (car cl)
105 "white"))
106 (set-face-foreground nf "black")
107 (if (and chart-face-use-pixmaps pl)
108 (condition-case nil
109 (set-face-background-pixmap nf (car pl))
110 (error (message "Cannot set background pixmap %s" (car pl)))))
111 (push nf faces)
112 (setq cl (cdr cl)
113 pl (cdr pl)))
114 faces))
115 "Faces used to colorize charts. 93 "Faces used to colorize charts.
94This should either be a list of faces, or a function that returns
95a list of faces.
96
116List is limited currently, which is ok since you really can't display 97List is limited currently, which is ok since you really can't display
117too much in text characters anyways.") 98too much in text characters anyways.")
118 99
100(defun chart--face-list ()
101 (and
102 (display-color-p)
103 (let ((cl chart-face-color-list)
104 (pl chart-face-pixmap-list)
105 (faces ())
106 nf)
107 (while cl
108 (setq nf (make-face
109 (intern (concat "chart-" (car cl) "-" (car pl)))))
110 (set-face-background nf (if (condition-case nil
111 (> (x-display-color-cells) 4)
112 (error t))
113 (car cl)
114 "white"))
115 (set-face-foreground nf "black")
116 (if (and chart-face-use-pixmaps pl)
117 (condition-case nil
118 (set-face-background-pixmap nf (car pl))
119 (error (message "Cannot set background pixmap %s" (car pl)))))
120 (push nf faces)
121 (setq cl (cdr cl)
122 pl (cdr pl)))
123 faces)))
124
119(define-derived-mode chart-mode special-mode "Chart" 125(define-derived-mode chart-mode special-mode "Chart"
120 "Define a mode in Emacs for displaying a chart." 126 "Define a mode in Emacs for displaying a chart."
121 (buffer-disable-undo) 127 (buffer-disable-undo)
@@ -374,7 +380,10 @@ of the drawing."
374 (let* ((data (oref c sequences)) 380 (let* ((data (oref c sequences))
375 (dir (oref c direction)) 381 (dir (oref c direction))
376 (odir (if (eq dir 'vertical) 'horizontal 'vertical)) 382 (odir (if (eq dir 'vertical) 'horizontal 'vertical))
377 ) 383 (faces
384 (if (functionp chart-face-list)
385 (funcall chart-face-list)
386 chart-face-list)))
378 (while data 387 (while data
379 (if (stringp (car (oref (car data) data))) 388 (if (stringp (car (oref (car data) data)))
380 ;; skip string lists... 389 ;; skip string lists...
@@ -390,10 +399,9 @@ of the drawing."
390 (zp (if (eq dir 'vertical) 399 (zp (if (eq dir 'vertical)
391 (chart-translate-ypos c 0) 400 (chart-translate-ypos c 0)
392 (chart-translate-xpos c 0))) 401 (chart-translate-xpos c 0)))
393 (fc (if chart-face-list 402 (fc (if faces
394 (nth (% i (length chart-face-list)) chart-face-list) 403 (nth (% i (length faces)) faces)
395 'default)) 404 'default)))
396 )
397 (if (< dp zp) 405 (if (< dp zp)
398 (progn 406 (progn
399 (chart-draw-line dir (car rng) dp zp) 407 (chart-draw-line dir (car rng) dp zp)