|
2 | 2 | ;; Copyright (C) 2017 Hlöðver Sigurðsson |
3 | 3 |
|
4 | 4 | ;; Author: Hlöðver Sigurðsson <hlolli@gmail.com> |
5 | | -;; Version: 0.2.0 |
6 | | -;; Package-Requires: ((emacs "25") (shut-up "0.3.2") (multi "2.0.1")) |
| 5 | +;; Version: 0.2.1 |
| 6 | +;; Package-Requires: ((emacs "25") (shut-up "0.3.2") (multi "2.0.1") (highlight "0")) |
7 | 7 | ;; URL: https://github.com/hlolli/csound-mode |
8 | 8 |
|
9 | 9 | ;; This program is free software; you can redistribute it and/or modify |
|
31 | 31 |
|
32 | 32 | (defvar csound-font-lock--missing-faces '()) |
33 | 33 |
|
34 | | -(defcustom csound-font-lock-rainbow-score-parameters-p t |
| 34 | +(defcustom csound-font-lock-rainbow-score-parameters-p nil |
35 | 35 | "Color each parameter field for |
36 | 36 | not events within CsScore/.sco" |
37 | 37 | :type 'boolean |
38 | 38 | :group 'csound-mode-font-lock) |
39 | 39 |
|
40 | 40 | (defface csound-font-lock-eval-flash |
41 | | - '((((class color)) (:background "#0AD600" :foreground "white" :bold t)) |
| 41 | + '((((class color) (background light)) (:foreground "#999601" :background "#42ff42")) |
| 42 | + (((class color) (background dark)) (:background "#637863" :foreground "#00e4f0")) |
42 | 43 | (t (:inverse-video t))) |
43 | 44 | "Face for highlighting during evaluation." |
44 | 45 | :group 'csound-mode-font-lock) |
45 | 46 |
|
46 | 47 | (defface csound-font-lock-eval-flash-error |
47 | | - '((((class color)) (:foreground "#D60000" :bold t)) |
| 48 | + '((((class color)) (:foreground "#5e0d0d" :bold t)) |
48 | 49 | (t (:inverse-video t))) |
49 | 50 | "Face for highlighting signaled errors during evaluation." |
50 | 51 | :group 'csound-mode-font-lock) |
|
162 | 163 | csound-font-lock-strings |
163 | 164 | csound-font-lock-xml-tags)) |
164 | 165 |
|
| 166 | +;;;###autoload |
165 | 167 | (defvar csound-font-lock-list '()) |
166 | 168 |
|
167 | 169 | (defconst csound-font-lock-keywords |
168 | 170 | (ignore-errors |
169 | 171 | (eval-when-compile |
170 | 172 | ;; Regex for i-rates |
171 | 173 | (push '("\\<i+\\w*" . csound-font-lock-i-rate) csound-font-lock-list) |
172 | | - |
| 174 | + |
173 | 175 | ;; Regex for global i-rates |
174 | 176 | (push '("\\<\\(gi\\)+\\w*" . csound-font-lock-global-i-rate) csound-font-lock-list) |
175 | 177 |
|
|
209 | 211 | ;; Regex for csound macros types |
210 | 212 | (push '("\\#\\w*\\|\\$\\w*" . csound-font-lock-macros) csound-font-lock-list) |
211 | 213 |
|
212 | | - ;; Regex for csound string types (use syntactic fontification?) |
| 214 | + ;; Regex for csound string types (use syntactic fontification?) |
213 | 215 | ;; (push '("\\s\"\\(.*?\\)[^\\]\\s\"" . csound-font-lock-strings) csound-font-lock-list) |
214 | 216 |
|
215 | 217 | ;; Regex for core csound xml tags |
|
268 | 270 | "-face"))) |
269 | 271 |
|
270 | 272 | (defun csound-font-lock--fontify-score (beg end) |
271 | | - (let ((backward-search-limit (if (string-match-p ".sco$" (buffer-name (current-buffer))) |
272 | | - 0 |
273 | | - (save-excursion |
274 | | - (end-of-buffer) |
275 | | - (or (search-backward "<CsScore" nil t 1) 0)))) |
276 | | - ;; (score-end-line-num (or (search-forward "</CsScore" nil t 1) (line-number-at-pos (point-max)))) |
277 | | - (beg-line-num (line-number-at-pos beg)) |
278 | | - (end-line-num (1+ (line-number-at-pos end)))) |
| 273 | + (let ((beg-line-num (line-number-at-pos beg)) |
| 274 | + (end-line-num (min (line-number-at-pos (max-char)) |
| 275 | + (+ 2 (line-number-at-pos end))))) |
279 | 276 | (save-excursion |
280 | | - (goto-line beg-line-num) |
| 277 | + (beginning-of-line) |
281 | 278 | (while (< (line-number-at-pos) end-line-num) |
282 | 279 | (let* ((beg-word nil) |
283 | 280 | (end-word nil) |
|
306 | 303 | (setq depth (1+ depth))) |
307 | 304 | ;; If passed i marker |
308 | 305 | (progn |
309 | | - ;; (message "line: %d" (line-number-at-pos)) |
310 | | - (setq beg-word (min (1- (or (save-excursion (search-forward-regexp "[-?0-9a-zA-Z\\[\\.\\+\\<\\>\"]" (line-end-position) t 1)) |
| 306 | + (setq beg-word (min (1- (or (save-excursion (search-forward-regexp "[-?0-9a-zA-Z\\[\\.\\+\\<\\>\"]" (line-end-position) t 1)) |
311 | 307 | (line-end-position)))) |
312 | 308 | end-word (save-excursion |
313 | 309 | (goto-char beg-word) |
314 | 310 | (let ((e (search-forward-regexp "\\s-\\|$" (line-end-position)))) |
315 | 311 | (if (< e end-line) |
316 | 312 | e end-line)))) |
317 | | - ;; (message "beg: %d end: %d" beg-word end-word) |
318 | 313 | (goto-char end-word) |
319 | | - ;; (add-text-properties beg-word end-word `(face ,(funcall #'csound-font-lock-param-delimiters-default-pick-face depth))) |
320 | 314 | (font-lock-prepend-text-property beg-word end-word 'face (funcall #'csound-font-lock-param-delimiters-default-pick-face depth)) |
321 | 315 | (setq depth (1+ depth))))))) |
322 | | - (next-line))))) |
| 316 | + (forward-line))))) |
323 | 317 |
|
324 | 318 | (defun csound-font-lock-fontify-region (beg end &optional loud) |
325 | | - (shut-up |
326 | | - (save-excursion |
327 | | - (let ((within-score-p (or (save-excursion (search-backward "<CsScore" nil t 1)) |
328 | | - (string-match-p ".sco$" (buffer-name (current-buffer))))) |
329 | | - (score-boundry (if (string-match-p ".sco$" (buffer-name (current-buffer))) |
330 | | - 0 |
331 | | - (or (save-excursion (beginning-of-buffer) |
332 | | - (search-forward-regexp "<CsScore" end t 1)) |
333 | | - 0))) |
334 | | - (orchestra-boundry (if (or (string-match-p ".orc$" (buffer-name (current-buffer))) |
335 | | - (string-match-p ".udo$" (buffer-name (current-buffer)))) |
336 | | - (buffer-size) |
337 | | - (or (save-excursion (beginning-of-buffer) |
338 | | - (search-forward-regexp "</CsInstruments>" end t 1)) |
339 | | - (buffer-size))))) |
340 | | - (if (and within-score-p csound-font-lock-rainbow-score-parameters-p) |
341 | | - (csound-font-lock--fontify-score (max score-boundry beg) end) |
342 | | - ;; All normal font-lock calls |
343 | | - (let ((end-line (line-number-at-pos (min end orchestra-boundry)))) |
344 | | - (goto-char beg) |
345 | | - (beginning-of-line) |
346 | | - (while (< (line-number-at-pos) (1+ end-line)) |
347 | | - (save-excursion |
348 | | - (font-lock-default-fontify-region (line-beginning-position) (line-end-position) nil)) |
349 | | - (next-line)))))))) |
| 319 | + (save-excursion |
| 320 | + (let ((within-score-p (or (save-excursion (search-backward "<CsScore" nil t 1)) |
| 321 | + (string-match-p ".sco$" (buffer-name (current-buffer))))) |
| 322 | + (score-boundry (if (string-match-p ".sco$" (buffer-name (current-buffer))) |
| 323 | + (max-char) |
| 324 | + (or (save-excursion (goto-char (point-min)) |
| 325 | + (search-forward-regexp "<CsScore" nil t 1)) |
| 326 | + nil))) |
| 327 | + (orchestra-boundry (if (or (string-match-p ".orc$" (buffer-name (current-buffer))) |
| 328 | + (string-match-p ".udo$" (buffer-name (current-buffer)))) |
| 329 | + (buffer-size) |
| 330 | + (or (save-excursion (goto-char (point-min)) |
| 331 | + (search-forward-regexp "</CsInstruments>" end t 1)) |
| 332 | + (buffer-size))))) |
| 333 | + (if (and within-score-p score-boundry csound-font-lock-rainbow-score-parameters-p) |
| 334 | + (csound-font-lock--fontify-score (max score-boundry beg) (min end (max-char))) |
| 335 | + ;; All normal font-lock calls, but let's keep rainbow delimited fonts untouched |
| 336 | + (let ((end-line (1- (line-number-at-pos (min end (point-max))))) |
| 337 | + (end-line (if (and score-boundry csound-font-lock-rainbow-score-parameters-p) |
| 338 | + (line-number-at-pos score-boundry) |
| 339 | + end-line))) |
| 340 | + (goto-char beg) |
| 341 | + (beginning-of-line) |
| 342 | + (while (< (line-number-at-pos) (1+ end-line)) |
| 343 | + (save-excursion |
| 344 | + (font-lock-default-fontify-region (line-beginning-position) (line-end-position) nil)) |
| 345 | + (forward-line))))))) |
350 | 346 |
|
351 | 347 | (defun csound-font-lock--flush-buffer () |
352 | 348 | (save-excursion |
353 | | - (end-of-buffer) |
| 349 | + (goto-char (point-max)) |
354 | 350 | (let ((line-count (line-number-at-pos))) |
355 | | - (beginning-of-buffer) |
| 351 | + (goto-char (point-min)) |
356 | 352 | (while (< (line-number-at-pos) line-count) |
357 | 353 | (save-excursion (font-lock-default-fontify-region (line-beginning-position) (line-end-position) nil)) |
358 | | - (next-line))))) |
| 354 | + (forward-line))))) |
359 | 355 |
|
360 | 356 | (defun csound-font-lock--flush-score () |
361 | 357 | (when csound-font-lock-rainbow-score-parameters-p |
362 | 358 | (save-excursion |
363 | | - (beginning-of-buffer) |
| 359 | + (goto-char (point-min)) |
364 | 360 | (let ((score-beg (if (string-match-p ".sco$" (buffer-name (current-buffer))) |
365 | 361 | 0 |
366 | 362 | (save-excursion (search-forward "<CsScore" nil t 1)))) |
|
0 commit comments