From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Matt Noel Newsgroups: gmane.emacs.help Subject: Re: How do I setup an extremely simple font-lock mode? Date: Thu, 22 May 2003 17:48:39 -0700 Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <4B53EABC-8CB8-11D7-8FED-000393DC711A@mac.com> References: <16077.15618.129314.900191@jin.tekken> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (Apple Message framework v552) Content-Type: multipart/mixed; boundary="===============62448430417220568==" X-Trace: main.gmane.org 1053651048 9903 80.91.224.249 (23 May 2003 00:50:48 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 23 May 2003 00:50:48 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Fri May 23 02:50:45 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19J0lg-0002ZY-00 for ; Fri, 23 May 2003 02:50:45 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19J0m5-00077P-63 for gnu-help-gnu-emacs@m.gmane.org; Thu, 22 May 2003 20:51:09 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19J0l3-0006Kx-Jc for help-gnu-emacs@gnu.org; Thu, 22 May 2003 20:50:05 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19J0kG-0004Qx-Vi for help-gnu-emacs@gnu.org; Thu, 22 May 2003 20:49:48 -0400 Original-Received: from smtpout.mac.com ([17.250.248.88]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19J0kB-00046T-FS for help-gnu-emacs@gnu.org; Thu, 22 May 2003 20:49:11 -0400 Original-Received: from mac.com (smtpin08-en2 [10.13.10.153]) by smtpout.mac.com (Xserve/MantshX 2.0) with ESMTP id h4N0n9iL019693 for ; Thu, 22 May 2003 17:49:10 -0700 (PDT) Original-Received: from mac.com ([216.15.8.249]) (authenticated bits=0) by mac.com (Xserve/MantshX 2.0) with ESMTP id h4N0mVqE009748 for ; Thu, 22 May 2003 17:48:32 -0700 (PDT) Original-To: help-gnu-emacs@gnu.org In-Reply-To: <16077.15618.129314.900191@jin.tekken> X-Mailer: Apple Mail (2.552) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:10075 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:10075 --===============62448430417220568== content-type: multipart/alternative; boundary="Apple-Mail-4-181791993" --Apple-Mail-4-181791993 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed 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 > > --Apple-Mail-4-181791993 Content-Transfer-Encoding: 7bit Content-Type: text/enriched; charset=US-ASCII 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: Courier New;; 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): Courier New(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 --Apple-Mail-4-181791993-- --===============62448430417220568== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit _______________________________________________ Help-gnu-emacs mailing list Help-gnu-emacs@gnu.org http://mail.gnu.org/mailman/listinfo/help-gnu-emacs --===============62448430417220568==--