[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Objective-C font-lock for emacs...
From: |
Alex Lancaster |
Subject: |
Objective-C font-lock for emacs... |
Date: |
Thu, 11 Sep 1997 01:51:49 +1000 |
Hi folks,
I've been working on a font-lock mode for Objective C ever since I
scoured the web looking for one and didn't find any! The standard cc mode
will support the standard fontification of comments and #includes etc - but
nothing for the special selector methods ObjC uses. So, I had no choice
but to write it! Since I know a lot of Swarmers out there will be using
emacs (and possibly use font-lock for editing other kinds of code -
i.e. Perl, C, C++ etc...) I thought I'd share the fruits of my
frustrations. Thanks to Nelson Minar for writing the original version
for hilit19. I have tried to incorporate everything that was in that
version - but it still needs more work.
Font-lock is nice because it fontifies things "on the fly", as it were,
and life without colour is really a drab old coding world indeed! I also
found I seriously boosted my coding productivity after I started using
emacs and gave up on "vi"...
I really would like to improve this version - I am toying with trying
to fontify receivers and ObjC methods. I'm still not sure whether it's
possible to use E-Lisp regexps to recursively fontify nested receiver/
selector pairs - which is what I would like to do. At the moment I have
a bit of kludgy version working (not in this version). Any Emacs/Lisp
gurus out there know how to do it? Comments, suggestions, improvements
and extra E-Lisp are welcome. Ultimately I'd like to polish it up and get
it up to the Swarm site as a user-contrib... think of this as a sort of
condensation nuclei...
Hope someone out there finds it useful...
Alex
Here it is:
Put this in your .emacs file (create one if you don't have one yet!)
or put it somewhere into your /lisp or /site-lisp *.el files in an
appropriate place. You also need to ensure that the package "font-lock"
is loaded - there are many ways to do this, both clever and basic -
the most basic way is just have a line in your .emacs with (load
font-lock). Look in your emacs manual for more clever ways...
cut here-------
(setq auto-mode-alist
(append '(("\\.h$" . objc-mode)
("\\.m$" . objc-mode)
(".emacs$" . emacs-lisp-mode)
("\\.el$" .
emacs-lisp-mode))))
(setq font-lock-maximum-decoration
t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set upp font-lock colours
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq font-lock-face-attributes
'((font-lock-comment-face "chocolate")
(font-lock-string-face "NavyBlue"
nil nil t)
(font-lock-keyword-face "blue")
(font-lock-type-face
"OliveGreen" nil t)
(font-lock-reference-face "Purple" nil t)
(font-lock-function-name-face
"dark blue" nil t)
(font-lock-variable-name-face "seagreen")
(font-lock-hidden-face "grey90")
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
Objective-C-Mode Things ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; set up
Objective C font lock
;; modified objective c - get defuns, id.
;; fontify
define and include's for everything up until a comment
(defvar objc-define
"^#[ \t]*\\(undef\\|define\\)" "Defines ")
(defvar objc-include
"^#\\(import\\)" "Include's")
;; key words
(defvar objc-keywords
"return\\|goto\\|if\\|else\\|case\\|default\\|switch\\|break\\|continue\\|wh
ile\\|do\\|for\\|super\\|self" "Obj C Keywords for font-lock'ing")
;;
types
(defvar objc-types
"const\\|register\\|volatile\\|unsigned\\|extern\\|static\\|float\\|double\\
|void\\|char\\|short\\|int\\|long\\|id\\|FILE\\|struct\\|union\\|enum\\|clas
s" "Obj C Types for font-lock'ing")
;; declarations
(defvar objc-decl
"template\\|typedef\\|struct\\|union\\|class\\|enum\\|public\\|private\\|pro
tected" "Obj C Declarations for font-lock'ing")
(defvar
objc-font-lock-keywords nil "Keywords for Objective C font-locking")
(setq
objc-font-lock-keywords
(list
;; fontify keywords, types and
declarations
(cons (concat "\\<\\(" objc-keywords "\\)\\>")
'font-lock-keyword-face)
(cons (concat "\\<\\(" objc-types "\\)\\>")
'font-lock-type-face)
(cons (concat "\\<\\(" objc-decl "\\)\\>")
'font-lock-type-face)
;; fontify Objective C pre-processor
directives
(list objc-include 1 'font-lock-reference-face)
(list objc-define 1 'font-lock-reference-face)
;; Objective C
stuff: address@hidden gets keyword colouring
(list "^\\(@\\sw*\\)" 1
'font-lock-keyword-face)
;; Objective C style funs (Nelson Minar)
;; ignore typecast in brackets...
(list "^[-+][
\t]*\\(([^)]*)[ \t]*\\)?\\(\\sw*\\)" 2 'font-lock-function-name-face)
))
;; to be continued...
(add-hook 'objc-mode-hook
'turn-on-font-lock)
(add-hook 'emacs-lisp-mode-hook
'turn-on-font-lock)
(add-hook 'objc-mode-hook 'mw::objc-hook)
(defun
mw::objc-hook ()
(setq font-lock-function-name-face (cons
'objc-font-lock-keywords font-lock-defaults))
;; don't overwrite the
global version of the font-lock-defaults
(make-local-variable
'font-lock-defaults)
;; Append the Objective C-style fontification to the
;; standard cc-mode (C/C++) defaults - overriding where necessary
(setq
font-lock-defaults (cons 'objc-font-lock-keywords font-lock-defaults))
)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Alex Lancaster
e-mail: <address@hidden> tel: +61-2-9565-5774 (H)
web: http://www.real.net.au/~alex
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
==================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Objective-C font-lock for emacs...,
Alex Lancaster <=