[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: diary font-lock issue
From: |
martin rudalics |
Subject: |
Re: diary font-lock issue |
Date: |
Tue, 16 May 2006 17:50:06 +0200 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
> elisp:
> -------
> (setq foo-font-lock-keywords
> '(("\\(\\(?:Fri\\|Mon\\|S\\(?:atur\\|un\\)\\|\\(?:T\\(?:hur\\|ue\\)\\|Wedne\\)s\\)day\\), \\(A\\(?:pril\\|ugust\\)\\|December\\|February\\|J\\(?:anuary\\|u\\(?:ly\\|ne\\)\\)\\|Ma\\(?:rch\\|y\\)\\|\\(?:Novem\\|Octo\\|Septem\\)ber\\)
[0-9]+, -?[0-9]+\n=+$" . font-lock-keyword-face)))
>
> (define-derived-mode foo-mode fundamental-mode
> "foo"
> (set (make-local-variable 'font-lock-defaults)
> '(foo-font-lock-keywords t))
> (set (make-local-variable 'font-lock-multiline) t))
>
>
> sample input file:
> -------
> Friday, May 5, 2006
> ===================
> 9.00 Xxxx Xxxxxx Xxxxx xXxxxxxxxxxxxx
> 15.20-15.50 Xxxx Xxxxxxxxxxxxxxxxx
> 17.30-19.00 Xxxx Xxxxxxxxxx
> 18.00-19.30 Xxxx XXX
>
> Monday, May 8, 2006
> ===================
> 8.00 Xxxxxxxx xx Xxxxxxxx Xxxxxxxxxx xxx Xxxxxxxxxxxxx
> 14.30 Xxxxxx XxxxxXXxXxxxxx xxx Xxxx
> 15.30-17.00 Xxxx XxxxxXX
> 16.45 Xxxx xxx XxxxxXX xxxxxxx
> 17.15-18.15 Xxxx XxxxxXx
>
> Tuesday, May 9, 2006
> ====================
> 14.50 Xxxx xxx Xxxxxxxxxxxxxxxxxxxxx xxxxxxx
> 15.30-16.00 Xxxx
>
> Wednesday, May 10, 2006
<----------------------------------- end of font-lock-fontify-region
> =======================
> 20.00-21.15 Xxxxxx Xxxxxx
`foo-font-lock-keywords' will fail to find a match when the end of
`font-lock-fontify-region' is positioned as indicated above.
Earlier it was possible to handle this - in most cases - by setting
`font-lock-lines-before' to 1, but I don't know how this will be done in
the future. So far you could try the largely untested code I attached.
As soon as `font-lock-extend-region' has undergone its final revision
you should be able to replace the after-change-hook by writing an
appropriate `font-lock-extend-region-function'. If
`font-lock-extend-region' will be regularly called by say
`font-lock-default-fontify-region', you will have to simply check
whether the first character to be fontified is an "=" and you may use
your original code practically unchanged.
(defun foo-bar (bound)
(let (beg end)
(and (re-search-forward
"\\(\\(?:\\(?:Fri\\|Mon\\|S\\(?:atur\\|un\\)\\|\\(?:T\\(?:hur\\|ue\\)\\|Wedne\\)s\\)day\\)\
,
\\(?:A\\(?:pril\\|ugust\\)\\|December\\|February\\|J\\(?:anuary\\|u\\(?:ly\\|ne\\)\\)\
\\|Ma\\(?:rch\\|y\\)\\|\\(?:Novem\\|Octo\\|Septem\\)ber\\) [0-9]+,
-?[0-9]+\n\\)\\(=+\n\\)?" bound t)
(or (and (> (match-end 0) (match-end 1))
(setq beg (match-beginning 0))
(setq end (match-end 0)))
(and (= (match-end 1) bound)
(setq beg (match-beginning 0))
(save-excursion
(save-match-data
(and (looking-at "=+\n")
(setq end (match-end 0)))))))
(and beg end
(or (put-text-property beg end 'font-lock-multiline t) t)))))
(setq foo-font-lock-keywords
'((foo-bar 1 'font-lock-keyword-face)))
(defun foo-mode-after-change (start end old-len)
(save-excursion
(goto-char start)
(beginning-of-line)
(when (eq (char-after) ?\=))
(let* ((buffer-undo-list t)
(inhibit-read-only t)
(inhibit-point-motion-hooks t)
(inhibit-modification-hooks t)
deactivate-mark
buffer-file-name
buffer-file-truename)
(put-text-property
(line-beginning-position 0) (line-beginning-position) 'fontified
nil))))
(define-derived-mode foo-mode fundamental-mode
"foo"
(set (make-local-variable 'font-lock-defaults)
'(foo-font-lock-keywords t))
(set (make-local-variable 'font-lock-multiline) t)
(add-hook 'after-change-functions 'foo-mode-after-change nil t))