unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Matt Noel <mgn000@mac.com>
Subject: Re: How do I setup an extremely simple font-lock mode?
Date: Thu, 22 May 2003 17:48:39 -0700	[thread overview]
Message-ID: <4B53EABC-8CB8-11D7-8FED-000393DC711A@mac.com> (raw)
In-Reply-To: <16077.15618.129314.900191@jin.tekken>


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

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
>
>



[-- Attachment #1.2: Type: text/enriched, Size: 2555 bytes --]

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:


<fixed><fontfamily><param>Courier New</param>;; 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))

)</fontfamily></fixed>


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):


<fixed><fontfamily><param>Courier New</param>(autoload 'pta-mode
"pta-mode" "PTA log mode." t)

(add-to-list 'auto-mode-alist '("\\.log$" . pta-mode))</fontfamily></fixed>


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


<excerpt>Hi,


Matt Noel writes:

<excerpt>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?

</excerpt>

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



</excerpt>



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

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

  reply	other threads:[~2003-05-23  0:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-22 20:47 How do I setup an extremely simple font-lock mode? Matt Noel
2003-05-22 21:11 ` myrkraverk
2003-05-23  0:48   ` Matt Noel [this message]
     [not found] <mailman.6601.1053636524.21513.help-gnu-emacs@gnu.org>
2003-05-22 23:58 ` Alex Schroeder
2003-05-23 13:50 ` Barman Brakjoller
2003-05-23 15:02 ` kgold
2003-05-23 15:24   ` Bryan W. Lepore
     [not found] <mailman.6614.1053651042.21513.help-gnu-emacs@gnu.org>
2003-05-23 15:03 ` Stefan Monnier
2003-05-23 15:05   ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B53EABC-8CB8-11D7-8FED-000393DC711A@mac.com \
    --to=mgn000@mac.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).