From: Karl Hegbloom <karlheg@gmail.com>
To: William Case <billlinux@rogers.com>
Cc: EMACS List <help-gnu-emacs@gnu.org>
Subject: Re: Changing font-lock for combined HTML and PHP code??
Date: Tue, 17 Apr 2007 12:49:15 -0600 [thread overview]
Message-ID: <1176835755.14001.52.camel@oaktree.lan> (raw)
In-Reply-To: <1176747727.3057.13.camel@CASE>
[-- Attachment #1: Type: text/plain, Size: 703 bytes --]
On Mon, 2007-04-16 at 14:22 -0400, William Case wrote:
> I am working on web site made up of files that combine HTML and PHP. My
> main interest is in the PHP coding. Is there a relatively easy way to
> set the font-lock colors for the tags (constants) that distinguishes
> between a HTML tag and a PHP tag when I am in php-mode.
>
> In case I am misusing terminology, by tag I mean expressions like
> <p> ... </p> in HTML; <?php ... ?> in PHP.
The attached elisp file uses mmm-mode, psgml html mode, and php-mode
(which I obtained from Debian or via a google search) to make it do what
you want. I have not used the php stuff in there very much, so it will
probably need a small amount of work.
[-- Attachment #2: Type: text/x-emacs-lisp, Size: 3679 bytes --]
;;; mmm-html-ext.el
;;;
(require 'css-mode)
(mmm-add-classes
'((embedded-css
:submode css-mode
:face mmm-declaration-submode-face
:front "<style[^>]*>"
:back "</style>")))
(require 'generic-x)
(mmm-add-classes
'((embedded-javascript
:submode javascript-generic-mode
:face mmm-code-submode-face
:front "<script.*?\\(?:type\\|language\\)=\"\\(?:text/\\)?[Jj]ava[Ss]cript.*>"
:back "</script>")))
\f
;;; At the top of a mason component written in the style that I like
;;; to use is:
;;;
;;; <?xml version="1.0"?>
;;; <!DOCTYPE div PUBLIC "-//W3C//DTD XHTML 1.1//EN" "xhtml11.dtd">
;;;
;;; The thing is that those should not appear mid-document in the
;;; generated output. It's computationaly cheaper to comment them off
;;; than to filter them out with a <%filter> section. This next block
;;; of code sets things up so that the XML and DOCTYPE declarations
;;; are automatically commented off in the file saved to disk, but not
;;; commented off in the editor buffer, so that the normal mmm-mode
;;; and PSGML mode DTD parsing can take place.
;;;
;;; Copyright (c) 2005
;;; Karl Hegbloom <hegbloom@pdx.edu>
;;; GPL
;;;
(defun mason-comment-decls (arg)
(interactive "p")
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(cond
((and (< arg 0) (looking-at "%#"))
(progn
(delete-char 2)
(forward-line 1)
(beginning-of-line)
(delete-char 2)))
((and (>= arg 0) (not (looking-at "%#")))
(progn
(insert "%#")
(forward-line 1)
(beginning-of-line)
(insert "%#")))))))
(defvar mason-comment-decls nil)
(make-variable-buffer-local 'mason-comment-decls)
(defun %mason-file-hook (arg)
(when (and mmm-mode
mason-comment-decls)
(mason-comment-decls arg)))
(defun mason-find-file-hook ()
(%mason-file-hook -1)
(set-buffer-modified-p nil))
(defun mason-write-file-hook ()
(%mason-file-hook 1))
(defun mason-after-save-hook ()
(mason-find-file-hook))
(add-hook 'find-file-hooks #'mason-find-file-hook)
(add-hook 'write-file-hooks #'mason-write-file-hook)
(add-hook 'after-save-hook #'mason-after-save-hook)
\f
(require 'php-mode)
(setq auto-mode-alist
(remove-if #'(lambda (elt)
(eq (cdr elt) 'php-mode))
auto-mode-alist))
(let ((ext '("\\.php[345]?\\'" "\\.phtml\\'")))
(while ext
(add-to-list 'auto-mode-alist (cons (car ext) 'html-mode))
(add-to-list 'mmm-mode-ext-classes-alist (list 'html-mode (car ext) 'php))
(setq ext (cdr ext))))
(mmm-add-group
'php
'((php-xml-processing-directive
:submode php-mode
:face mmm-code-submode-face
:front "<[?]php"
:back "[?]>"
:insert ((?p php nil @ "<?php " @ _ @ " ?>" @))
)
(php-inline=
:submode php-mode
:face mmm-output-submode-face
:front "<[?]="
:back "[?]>"
:insert ((?= php nil @ "<?= " @ _ @ " ?>" @))
)
(php-inline
:submode php-mode
:face mmm-output-submode-face
:front "<[?]"
:back "[?]>"
:insert ((?\? php nil @ "<? " @ _ @ " ?>" @))
)
(php-inline-asp=
:submode php-mode
:face mmm-output-submode-face
:front "<%="
:back "%>"
)
(php-inline-asp
:submode php-mode
:face mmm-output-submode-face
:front "<%"
:back "%>"
)
(php-script
:submode php-mode
:face mmm-code-submode-face
:front "<script language=\"?php.*?>"
:back "</script>"
)
))
(mmm-add-group
'HTML::Template
'((html-template-tag
:submode text-mode
:face mmm-special-submode-face
:front "<TMPL_"
:include-front t
:back ">"
:include-back t
:insert ((?t HTML::Template nil @ @ "<TMPL_" _ ">" @ @))
)))
(provide 'mmm-html-ext)
[-- Attachment #3: Type: text/plain, Size: 152 bytes --]
_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
next prev parent reply other threads:[~2007-04-17 18:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-16 18:22 Changing font-lock for combined HTML and PHP code?? William Case
2007-04-16 19:41 ` Lennart Borgman (gmail)
2007-04-17 18:49 ` Karl Hegbloom [this message]
[not found] <mailman.2139.1176748185.7795.help-gnu-emacs@gnu.org>
2007-04-16 19:13 ` Eric Lilja
2007-04-16 19:55 ` William Case
[not found] ` <mailman.2146.1176753780.7795.help-gnu-emacs@gnu.org>
2007-04-18 15:15 ` Hadron
2007-04-18 15:49 ` Lennart Borgman (gmail)
2007-04-18 18:59 ` William Case
2007-04-29 4:44 ` William Case
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1176835755.14001.52.camel@oaktree.lan \
--to=karlheg@gmail.com \
--cc=billlinux@rogers.com \
--cc=help-gnu-emacs@gnu.org \
/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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.