all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Changing font-lock for combined HTML and PHP code??
@ 2007-04-16 18:22 William Case
  2007-04-16 19:41 ` Lennart Borgman (gmail)
  2007-04-17 18:49 ` Karl Hegbloom
  0 siblings, 2 replies; 9+ messages in thread
From: William Case @ 2007-04-16 18:22 UTC (permalink / raw)
  To: EMACS List

Hi;

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.


-- 
Regards Bill

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Changing font-lock for combined HTML and PHP code??
       [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>
  0 siblings, 2 replies; 9+ messages in thread
From: Eric Lilja @ 2007-04-16 19:13 UTC (permalink / raw)
  To: help-gnu-emacs

On 16 Apr, 20:22, William Case <billli...@rogers.com> wrote:
> Hi;
>
> 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.

I would like to find a good way to handle these kinds of files too,
with both html code and php code.
What I'm experimenting with just now is adding a keyboard setting for
the html-mode to go to php mode and keyboard setting for php mode to
go to html mode. Not ideal but better than what I had before which was
treating php-files like html-files, hehe. I like emacs' html mode. I
downloaded php mode from a third party.

The code is simply:

(require 'php-mode)

; php-mode actually runs this hook, maybe there's a better place to
put this...
(defun my-c-mode-common-hook ()
  (define-key c-mode-base-map "\C-c\C-h" 'html-mode)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)


(defun my-html-mode-hook ()
  (define-key html-mode-map "\C-c\C-p" 'php-mode)
)
(add-hook 'html-mode-hook 'my-html-mode-hook)

The php-mode will actually font lock the html code but I don't like
the way it indents it at all. Thus I switch between the modes with
these keyboard bindings depending on if I'm editing a html part of the
file or a php part. As I said, not ideal, but better than my earlier
approach.

- Eric

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Changing font-lock for combined HTML and PHP code??
  2007-04-16 18:22 William Case
@ 2007-04-16 19:41 ` Lennart Borgman (gmail)
  2007-04-17 18:49 ` Karl Hegbloom
  1 sibling, 0 replies; 9+ messages in thread
From: Lennart Borgman (gmail) @ 2007-04-16 19:41 UTC (permalink / raw)
  To: William Case; +Cc: EMACS List

William Case wrote:
> Hi;
> 
> 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.

Yes, perhaps. If you are using the Emacs 22 beta then you can use nXhtml:

    http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html

But at the moment I am working to fix some bugs, see the "News and Notes 
about nXhtml" at the top. I hope I can upload a new version the nearest 
days, ie version 0.98 (the latest upload is v 0.97).

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Changing font-lock for combined HTML and PHP code??
  2007-04-16 19:13 ` Changing font-lock for combined HTML and PHP code?? Eric Lilja
@ 2007-04-16 19:55   ` William Case
       [not found]   ` <mailman.2146.1176753780.7795.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: William Case @ 2007-04-16 19:55 UTC (permalink / raw)
  To: Eric Lilja; +Cc: help-gnu-emacs

Hi Eric;

Since I am just starting on this HTML/PHP journey I may misspeak but ...

On Mon, 2007-04-16 at 12:13 -0700, Eric Lilja wrote:
> On 16 Apr, 20:22, William Case <billli...@rogers.com> wrote:
> > Hi;
> >
> > 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.
> 
> I would like to find a good way to handle these kinds of files too,
> with both html code and php code.
> What I'm experimenting with just now is adding a keyboard setting for
> the html-mode to go to php mode and keyboard setting for php mode to
> go to html mode. Not ideal but better than what I had before which was
> treating php-files like html-files, hehe. I like emacs' html mode. I
> downloaded php mode from a third party.
> 

Since all the HTML tags are in the form <x> </x> i.e. double angle
brackets, it seems to me I should be able to add a definition somewhere
(where ?) that gets added to a php-mode font-lock mode and assigns a
special meaning and colour to expressions with double angle brackets.

At the moment I am using the global font-locks, so I would have to
create (or edit)
a php-mode font-lock using an amended global font-lock as my template.  

(Easy to say.  Doing is another thing.)

On second thought, it doesn't matter if HTML constants are always shown
in readable yellow while PHP show up in Orange in a global setting.

> The code is simply:
> 
> (require 'php-mode)
> 
> ; php-mode actually runs this hook, maybe there's a better place to
> put this...
> (defun my-c-mode-common-hook ()
>   (define-key c-mode-base-map "\C-c\C-h" 'html-mode)
> )
> (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
> 
> 
> (defun my-html-mode-hook ()
>   (define-key html-mode-map "\C-c\C-p" 'php-mode)
> )
> (add-hook 'html-mode-hook 'my-html-mode-hook)
> 
> The php-mode will actually font lock the html code but I don't like
> the way it indents it at all. Thus I switch between the modes with
> these keyboard bindings depending on if I'm editing a html part of the
> file or a php part. As I said, not ideal, but better than my earlier
> approach.
> 

As I say, my concentration is on the PHP so I only need to differentiate
between PHP and the beginning and ending of a block of HTML.  I don't
need a full different set of syntatical font-locks for HTML.

> - Eric
> 
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
-- 
Regards Bill

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Changing font-lock for combined HTML and PHP code??
  2007-04-16 18:22 William Case
  2007-04-16 19:41 ` Lennart Borgman (gmail)
@ 2007-04-17 18:49 ` Karl Hegbloom
  1 sibling, 0 replies; 9+ messages in thread
From: Karl Hegbloom @ 2007-04-17 18:49 UTC (permalink / raw)
  To: William Case; +Cc: EMACS List

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Changing font-lock for combined HTML and PHP code??
       [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)
  0 siblings, 1 reply; 9+ messages in thread
From: Hadron @ 2007-04-18 15:15 UTC (permalink / raw)
  To: help-gnu-emacs

William Case <billlinux@rogers.com> writes:

> Hi Eric;
>
> Since I am just starting on this HTML/PHP journey I may misspeak but ...
>
> On Mon, 2007-04-16 at 12:13 -0700, Eric Lilja wrote:
>> On 16 Apr, 20:22, William Case <billli...@rogers.com> wrote:
>> > Hi;
>> >
>> > 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.
>> 
>> I would like to find a good way to handle these kinds of files too,
>> with both html code and php code.
>> What I'm experimenting with just now is adding a keyboard setting for
>> the html-mode to go to php mode and keyboard setting for php mode to
>> go to html mode. Not ideal but better than what I had before which was
>> treating php-files like html-files, hehe. I like emacs' html mode. I
>> downloaded php mode from a third party.
>> 
>
> Since all the HTML tags are in the form <x> </x> i.e. double angle
> brackets, it seems to me I should be able to add a definition somewhere
> (where ?) that gets added to a php-mode font-lock mode and assigns a
> special meaning and colour to expressions with double angle brackets.
>
> At the moment I am using the global font-locks, so I would have to
> create (or edit)
> a php-mode font-lock using an amended global font-lock as my template.  
>
> (Easy to say.  Doing is another thing.)
>
> On second thought, it doesn't matter if HTML constants are always shown
> in readable yellow while PHP show up in Orange in a global setting.
>
>> The code is simply:
>> 
>> (require 'php-mode)
>> 
>> ; php-mode actually runs this hook, maybe there's a better place to
>> put this...
>> (defun my-c-mode-common-hook ()
>>   (define-key c-mode-base-map "\C-c\C-h" 'html-mode)
>> )
>> (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
>> 
>> 
>> (defun my-html-mode-hook ()
>>   (define-key html-mode-map "\C-c\C-p" 'php-mode)
>> )
>> (add-hook 'html-mode-hook 'my-html-mode-hook)
>> 
>> The php-mode will actually font lock the html code but I don't like
>> the way it indents it at all. Thus I switch between the modes with
>> these keyboard bindings depending on if I'm editing a html part of the
>> file or a php part. As I said, not ideal, but better than my earlier
>> approach.
>> 
>
> As I say, my concentration is on the PHP so I only need to differentiate
> between PHP and the beginning and ending of a block of HTML.  I don't
> need a full different set of syntatical font-locks for HTML.

I would suggest trying nxhtml - it has come on a lot recently and
Lennart is sufficiently motivated to support it. The whole html/php/css
situation is a bit of a mess for emacs at the moment - too many
competing hacks. nxhtml is quite a nice solution to all that.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Changing font-lock for combined HTML and PHP code??
  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
  0 siblings, 2 replies; 9+ messages in thread
From: Lennart Borgman (gmail) @ 2007-04-18 15:49 UTC (permalink / raw)
  To: Hadron; +Cc: help-gnu-emacs

Hadron wrote:

> I would suggest trying nxhtml - it has come on a lot recently and
> Lennart is sufficiently motivated to support it. The whole html/php/css
> situation is a bit of a mess for emacs at the moment - too many
> competing hacks. nxhtml is quite a nice solution to all that.


Thanks for the kind words. But please hold on for a couple of hours if 
you want to test nXhtml. I am currently trying to add an improvement for 
XHTML completion in PHP. I will tell here when I am ready.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Changing font-lock for combined HTML and PHP code??
  2007-04-18 15:49       ` Lennart Borgman (gmail)
@ 2007-04-18 18:59         ` William Case
  2007-04-29  4:44         ` William Case
  1 sibling, 0 replies; 9+ messages in thread
From: William Case @ 2007-04-18 18:59 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: help-gnu-emacs, Hadron

Thanks Lennart;

You know how it is.  I missed the meeting of our local LUG and got
appointed as one of the maintainers our website.  Have only done very
very basic web stuff before.

On Wed, 2007-04-18 at 17:49 +0200, Lennart Borgman (gmail) wrote:
> Hadron wrote:
> 
> > I would suggest trying nxhtml - it has come on a lot recently and
> > Lennart is sufficiently motivated to support it. The whole html/php/css
> > situation is a bit of a mess for emacs at the moment - too many
> > competing hacks. nxhtml is quite a nice solution to all that.
> 
> 
> Thanks for the kind words. But please hold on for a couple of hours if 
> you want to test nXhtml. I am currently trying to add an improvement for 
> XHTML completion in PHP. I will tell here when I am ready.
> 

I'll wait until I see a posting.  The problem is we seem to have a
mishmash of html and php that started out as php rather than the other
way around.  First, I need something that is just easy to update the
site with current information. 

We use subversion for updating.  In the longer term I think everything
has to be re-done but right now it is all *.php files with HTML tags and
code mixed in.  By the way, there is nothing wrong with the look of our
LUG site but the backend seems to be a dog's breakfast.


Regards Bill

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Changing font-lock for combined HTML and PHP code??
  2007-04-18 15:49       ` Lennart Borgman (gmail)
  2007-04-18 18:59         ` William Case
@ 2007-04-29  4:44         ` William Case
  1 sibling, 0 replies; 9+ messages in thread
From: William Case @ 2007-04-29  4:44 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: help-gnu-emacs, Hadron

Hi Lennart;

On Wed, 2007-04-18 at 17:49 +0200, Lennart Borgman (gmail) wrote:
> Hadron wrote:
> 
> > I would suggest trying nxhtml - it has come on a lot recently and
> > Lennart is sufficiently motivated to support it. The whole html/php/css
> > situation is a bit of a mess for emacs at the moment - too many
> > competing hacks. nxhtml is quite a nice solution to all that.
> 
> 
> Thanks for the kind words. But please hold on for a couple of hours if 
> you want to test nXhtml. I am currently trying to add an improvement for 
> XHTML completion in PHP. I will tell here when I am ready.

Did you ever get the nXhtml program completed ?
If so could you let me know where to get a test copy?
-- 
Regards Bill

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-04-29  4:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.2139.1176748185.7795.help-gnu-emacs@gnu.org>
2007-04-16 19:13 ` Changing font-lock for combined HTML and PHP code?? 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
2007-04-16 18:22 William Case
2007-04-16 19:41 ` Lennart Borgman (gmail)
2007-04-17 18:49 ` Karl Hegbloom

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.