all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* log-reading major mode
@ 2006-12-05 16:30 Matzi Kratzi
  0 siblings, 0 replies; 2+ messages in thread
From: Matzi Kratzi @ 2006-12-05 16:30 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 1580 bytes --]

Hi.
I am trying to make me a log reading major mode.
I want to be able to change face of text matching certain regexps. To
achieve this, I set font-lock-defaults and this works.

My problem is that I would like to be able to change what text that is to be
specially faced as I go along, i.e. identify interesting texts and add - or
subtract - them from the regexps without having to revisit the file.

Let say I usually want to highlight write, read and weblog. I use this:
(defvar log-font-lock-keywords
  '(("\\(\\write\\)"    . font-lock-function-name-face)
    ("\\(\\weblog\\)"     . font-lock-doc-face)
    ("\\(\\read\\)"      . font-lock-keyword-face)
    )
  "Keyword highlighting specification for `log-mode'.")

As I read 061205.log, I decide not to highlight "weblog" any more. How do I
disable it? Later on, I want to highlight "user" instead, now with
font-lock-comment-face. How do I do that? I do not want to close the file to
reopen it again.

Best Regards
Matzi

This is my attempt so far. It is a surprisingly small amount of code, but
then again, it does not do what I want. =)

(defvar log-font-lock-keywords
  '(("\\(\\write\\)"    . font-lock-function-name-face)
    ("\\(\\weblog\\)"     . font-lock-doc-face)
    ("\\(\\read\\)"      . font-lock-keyword-face)
    )
  "Keyword highlighting specification for `log-mode'.")

;;;###autoload
(define-derived-mode log-mode fundamental-mode "log"
  "A major mode for editing log files."
  (set (make-local-variable 'font-lock-defaults)
       '(log-font-lock-keywords))
  )

(provide 'log)
;;; log.el ends here

[-- Attachment #1.2: Type: text/html, Size: 2095 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: log-reading major mode
       [not found] <mailman.1566.1165336218.2155.help-gnu-emacs@gnu.org>
@ 2006-12-05 19:53 ` Robert Thorpe
  0 siblings, 0 replies; 2+ messages in thread
From: Robert Thorpe @ 2006-12-05 19:53 UTC (permalink / raw)


Matzi Kratzi wrote:
> Hi.
> I am trying to make me a log reading major mode.
> I want to be able to change face of text matching certain regexps. To
> achieve this, I set font-lock-defaults and this works.
>
> My problem is that I would like to be able to change what text that is to be
> specially faced as I go along, i.e. identify interesting texts and add - or
> subtract - them from the regexps without having to revisit the file.
>
> Let say I usually want to highlight write, read and weblog. I use this:
> (defvar log-font-lock-keywords
>   '(("\\(\\write\\)"    . font-lock-function-name-face)
>     ("\\(\\weblog\\)"     . font-lock-doc-face)
>     ("\\(\\read\\)"      . font-lock-keyword-face)
>     )
>   "Keyword highlighting specification for `log-mode'.")
>
> As I read 061205.log, I decide not to highlight "weblog" any more. How do I
> disable it? Later on, I want to highlight "user" instead, now with
> font-lock-comment-face. How do I do that? I do not want to close the file to
> reopen it again.
>
> Best Regards
> Matzi
>
> This is my attempt so far. It is a surprisingly small amount of code, but
> then again, it does not do what I want. =)
>
> (defvar log-font-lock-keywords
>   '(("\\(\\write\\)"    . font-lock-function-name-face)
>     ("\\(\\weblog\\)"     . font-lock-doc-face)
>     ("\\(\\read\\)"      . font-lock-keyword-face)
>     )
>   "Keyword highlighting specification for `log-mode'.")
>
> ;;;###autoload
> (define-derived-mode log-mode fundamental-mode "log"
>   "A major mode for editing log files."
>   (set (make-local-variable 'font-lock-defaults)
>        '(log-font-lock-keywords))
>   )
>
> (provide 'log)
> ;;; log.el ends here

This is quite a difficult problem.  The code that font-locks a buffer
is optimized, it is intended to work well on large files.  Generally it
does not colour what is not on the users screen, it colours things in
as it goes, and plays other tricks.

One way to do it would be to use hi-lock-face-buffer and the other
functions in hi-lock.

I'm not sure this is the best way though.  Probably the best way is to
read font-lock.el and figure out how to do it from there.  I expect it
will not be easy.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-12-05 19:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1566.1165336218.2155.help-gnu-emacs@gnu.org>
2006-12-05 19:53 ` log-reading major mode Robert Thorpe
2006-12-05 16:30 Matzi Kratzi

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.