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

(mgp-users 00151) crude font-lock support for mgp-mode.el



i looked at the suggested mgp-mode.el and didn't find any support for
font-locking.  i put something crude together.  it's quite likely that
this can be done in a much better way (read "this is the first
font-lock job i've done"), but it might be better than nothing :-)

--- mgp-mode.el-19990520	Thu May 20 14:35:14 1999
+++ mgp-mode.el	Thu May 20 17:52:27 1999
@@ -205,6 +205,107 @@
   (define-key mgp-mode-map "\C-cS" 'mgp-direc-system)
   (define-key mgp-mode-map "\C-cF" 'mgp-direc-filter))
 
+;; QUICK HACK: should be lots of room for improvement
+(defvar mgp-font-lock-keywords
+  (let ((keywords 
+	 (mapconcat 
+	  'identity
+	  ;; note: order matters -- e.g. "leftfill" should precede "left"
+	  '("size"      "fore"     "back"     "bgrad"
+	   "leftfill"   "left"     "center"   "right"
+	    "shrink"    "lcutin"   "rcutin"   "cont"
+	    "nodefault" "xfont"    "vfont"    "tfont"
+	    "tfont0"    "bar"      "image"    "prefix"
+	    "icon"      "bimage"   "default"  "tab"
+	    "page"      "vgap"     "hgap"     "pause"
+	    "mark"      "again"    "system"   "filter"
+	    "endfilter" "vfcap"    "tfdir"    "deffont"
+	    "font"      "embed"    "endembed" "noop"
+	    "include"   "tmfont"   "ccolor"   "bquality"
+	    )
+	  "\\|"))
+	(icon-specifiers
+	 (mapconcat
+	  'identity
+	  '("arc" "box" "delta1" "delta2" "delta3" "delta4" "dia")
+	  "\\|"))
+	(words-with-directives
+	 (mapconcat
+	  'identity
+	  '("default" "deffont" "tab")
+	  "\\|"))
+	)
+    
+    (list
+
+     ;; match 'keywords'
+     (cons (concat "^%\\(" keywords "\\)") 1)
+
+     ;; shouldn't have to do things this way?
+     ;; match leading %s
+     (cons (concat "^\\(%\\)\\(" keywords "\\)") 1)
+
+     ;; match borders -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+     (cons (concat "^\\(%%+\\)") font-lock-comment-face)
+
+     ;; match keywords following leading keywords
+     (list 
+      (concat "^%\\(" keywords "\\)[^,]*,[ \t]*")
+      (list 1 font-lock-keyword-face)
+      (list (concat "\\(" keywords "\\)[^,]*") 
+	    nil 
+	    nil 
+	    (list 1 font-lock-keyword-face)))
+
+     ;; match strings in quotes following keywords
+     (list
+      (concat "^%\\(" keywords "\\)")
+      (list "\"[^\"]*\"" 
+	    nil 
+	    nil 
+	    (list 0 font-lock-string-face)))
+
+     ;; deal w/ icon specifiers
+     (list
+      (concat "icon[ \t]+\\(" icon-specifiers "\\)")
+      (list 1 font-lock-keyword-face))
+
+     ;; deal w/ %default, %deffont, %tab
+     ;; assumes they occur only at the beginning of a line
+     (list
+      (concat "^%\\(" words-with-directives "\\)")
+      (list (concat "\\(" keywords "\\)")
+	    nil
+	    nil
+	    (list 1 font-lock-keyword-face)))
+
+     ;; for %image, deal w/ things of the form: 800x600
+     (list
+      (concat "^%image")
+      (list "\\([0-9]+x[0-9]+\\)"
+	    nil
+	    nil
+	    (list 1 font-lock-string-face)))
+
+     ;; match numbers following keywords
+     (list
+      (concat "^%\\(" keywords "\\)")
+      (list "\\([0-9]+\\)[^0-9]*"
+	    nil
+	    nil
+	    ;; isn't there something like font-lock-number-face?
+	    (list 1 font-lock-string-face)))
+
+     ;; HACK: problems getting negative signs in front of some numbers to work
+     (list
+      (concat "^%\\(" keywords "\\)")
+      (list "\\(-\\)[0-9]"
+	    nil
+	    nil
+	    (list 1 font-lock-string-face)))
+
+     )))
+
 ;; MagicPoint mode
 (defun mgp-mode ()
   "Major mode for editing MagicPoint files.
@@ -236,6 +337,8 @@
   (make-local-variable 'mgp-page-separator)
   (make-local-variable 'mgp-emph-color)
   (make-local-variable 'mgp-emph-color-normal)
+  (make-local-variable 'font-lock-defaults)
+  (setq font-lock-defaults '(mgp-font-lock-keywords nil t))
   (run-hooks 'mgp-mode-hook))