>>>> "Jim" == Jim Crossley
<jcrossley(a)ifleet.com> writes:
Jim> Hi. I've written a jsp-mode (derived from the psgml xml-mode) that
Jim> IMHO indents better than any other jsp mode I've come across. I'm
Jim> still developing it, but it's pretty useful in its present state.
Jim> I think it would be useful to others, but I'm not sure of the best way
Jim> to make it available.
Jim> So I'm sending it to you. :-)
Hello Jim,
webmaster(a)xemacs.org is the right address to report problems with the
website itself (broken URLs, incorrect, incomplete, or confusing
content).
Please turn to the mailing lists advertized in
http://www.xemacs.org/Debug/index.html
for help configuring, compiling and using XEmacs.
You may offer your jsp-mode for inclusion at xemacs-beta(a)xemacs.org.
Best regards,
Adrian
Jim> Thanks
Jim> --
Jim> Jim Crossley
Jim>
http://www.lads.com/~jim
Jim> ;;; jsp.el --- for editing Java Server Pages
Jim> ;; Copyright (C) 2002 Jim Crossley
Jim> ;; Author: Jim Crossley <crossley(a)charter.net
Jim> ;; Maintainer: Jim Crossley <crossley(a)charter.net>
Jim> ;; Keywords: java, jsp
Jim> ;; XEmacs is free software; you can redistribute it and/or modify it
Jim> ;; under the terms of the GNU General Public License as published by
Jim> ;; the Free Software Foundation; either version 2, or (at your option)
Jim> ;; any later version.
Jim> ;; XEmacs is distributed in the hope that it will be useful, but
Jim> ;; WITHOUT ANY WARRANTY; without even the implied warranty of
Jim> ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Jim> ;; General Public License for more details.
Jim> ;; You should have received a copy of the GNU General Public License
Jim> ;; along with XEmacs; see the file COPYING. If not, write to the Free
Jim> ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
Jim> ;; 02111-1307, USA.
Jim> ;;; Commentary:
Jim> ;; This simple mode is derived from the PSGML package's xml-mode.
Jim> ;; Historically, editing JSP files in [x]emacs is not fun. It is not
Jim> ;; practical to define DTD's for them, even when they're totally
Jim> ;; well-formed XML, because any number of custom tag libraries can be
Jim> ;; specified in the file, making the set of possible elements and/or
Jim> ;; attributes infinite. The DOCTYPE declaration in a JSP file
Jim> ;; specifies the type of the resulting document *after* the JSP
Jim> ;; processor has resolved the custom tags into their "real" values.
Jim> ;; But I (and I suspect most other jsp developers) don't care about
Jim> ;; any of that, useful as it is for well-defined documents. What we
Jim> ;; care about most is indentation!! To my knowledge, there is no
Jim> ;; emacs mode that indents JSP code satisfactorily. This mode is my
Jim> ;; own personal attempt.
Jim> ;; My solution is fairly simple. I basically prevent the PSGML parser
Jim> ;; from discovering the DOCTYPE. I derive a jsp-mode from xml-mode,
Jim> ;; because a well written jsp file should be well-formed XML.
Jim> ;; BEWARE: No indentation takes place within scriptlets or HTML
Jim> ;; comments. This is by design.
Jim> ;;; Code:
Jim> ;;; The JSP major mode
Jim> (define-derived-mode jsp-mode xml-mode "JSP"
Jim> (require 'psgml-parse)
Jim> (cond
Jim> (running-xemacs
Jim> (require 'psgml-html)
Jim> (put 'jsp-mode 'font-lock-defaults '(html-font-lock-keywords
nil t))))
Jim> (make-local-variable 'sgml-default-doctype-name)
Jim> (setq sgml-default-doctype-name "jsp"
Jim> indent-line-function 'jsp-indent-line)
Jim> (sgml-setup-doctype sgml-default-doctype-name nil)
Jim> (define-key jsp-mode-map "\r"
'reindent-then-newline-and-indent)
Jim> )
Jim> ;;; Indentation in JSP mode
Jim> (defun jsp-indent-line ()
Jim> "Indent sgml-indent-step number of spaces fewer than
sgml-indent-line."
Jim> (when (null (jsp-inside-comment))
Jim> (let ((col (sgml-indent-line)))
Jim> (when (and col
Jim> (eq sgml-default-doctype-name
Jim> (sgml-dtd-doctype sgml-dtd-info)))
Jim> (save-excursion
Jim> (beginning-of-line 1)
Jim> (delete-horizontal-space)
Jim> (indent-to (- col sgml-indent-step)))))))
Jim> ;;; Inside jsp comment
Jim> (defun jsp-inside-comment ()
Jim> "Return true if point is within either <% %> or <!--
-->."
Jim> (let ((here (point)))
Jim> (save-excursion
Jim> (back-to-indentation)
Jim> (search-backward-regexp "<[!%]" nil t)
Jim> (forward-char)
Jim> (if (looking-at "%")
Jim> (progn (search-forward "%>" nil t) (>
(match-beginning 0) here))
Jim> (progn (search-forward "-->" nil t) (>
(match-beginning 0) here))))))
--
Adrian Aichner
mailto:adrianï¼ xemacs.org
http://www.xemacs.org/