help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I setup an extremely simple font-lock mode?


From: Matt Noel
Subject: Re: How do I setup an extremely simple font-lock mode?
Date: Thu, 22 May 2003 17:48:39 -0700

Thanks Johann, if it's of any help to others, here's what I settled on:

I made a file named pta-mode.py in my emacs directory, where I keep other lisp files, and put this in it:

;; This is basically a list of lists with a regular expression and
;; then the font name (or face name). The numbers below refer to \\(
;; ... \\) constructs that mark what part of the re you want
;; highlighted
(defconst pta-font-lock-keywords
'(
("- \\(ERROR\\) - \\w*\\(.*\\)" (1 font-lock-warning-face)
(2 font-lock-comment-face))
("- \\(WARN\\) - \\w*\\(.*\\)" (1 font-lock-type-face)
(2 font-lock-comment-face))
)
"Expressions to highlight in PTA mode.")

(defun pta-mode ()
(setq font-lock-defaults '(pta-font-lock-keywords))
)


Then I added this to my .emacs file to load this, and select it for use on all my *.log files (which suits my needs):

(autoload 'pta-mode "pta-mode" "PTA log mode." t)
(add-to-list 'auto-mode-alist '("\\.log$" . pta-mode))


On Thursday, May 22, 2003, at 02:11 PM, myrkraverk@users.sourceforge.net wrote:

Hi,

Matt Noel writes:
I want to setup a very simple mode for colorizing a log file. All I
need to do is highlight any lines with the string ERROR on them. I've
tried reading the documentation for font-lock but it's not clear how to
do this.

Could someone point me to a simple example, or send one?

Here is an example, it doesn't though specify how you use the mode on
the log file. Maybe you can edit it to suit your need.

;; This is basically a list of lists with a regular expression and
;; then the font name (or face name). The numbers below refer to \\(
;; ... \\) constructs that mark what part of the re you want
;; highlighted
(defconst masp-font-lock-keywords
'(("^\\(\\(\\sw\\|\\s_\\)+\\)\\>:?[ \t]*\\(\\sw+\\(\\.[lLwWbBsS]\\)?\\)?"
(1 font-lock-function-name-face) (3 font-lock-keyword-face nil t))
("^\\s +\\(\\(\\sw\\|\\s_\\)+\\(\\.[lLwWbBsS]\\)?\\)" 1 font-lock-keyword-face)
("^\\(\\s-+\\|\\sw+:\\s-+\\)\\(\\\\[a-zA-Z0-9]+\\)"
(2 font-lock-constant-face))
("\\(\\\\\\sw+\\)"
(1 font-lock-variable-name-face)))
"Additional expressions to highlight in Assembler mode.")

(defun masp-mode ()
;;...
(setq font-lock-defaults '(masp-font-lock-keywords))
;;...
)


Hope this helps,

Johann

--
This line is left blank intentionally





reply via email to

[Prev in Thread] Current Thread [Next in Thread]