|
emacs好像没有标准的jsp模式,我在国外的网站上找到这么一个东东,但是java语法还是没有对齐,不知道怎么回事?
- ; functions to perform correct indentation of java code within a
- ; JSP page. I can live without syntax coloring - I can't live
- ; without proper indentation
- ;
- (setq auto-mode-alist
- (cons '("\\.jsp\\'" . html-mode) auto-mode-alist))
- (defun jsp-java-sob ()
- "Return the point for the enclosing <% or nil if not present"
- (save-excursion
- (search-backward "<%")))
- (defun jsp-java-eob ()
- "Return the point for the enclosing %> or nil if not present"
- (save-excursion
- (search-forward "%>")))
- (defun jsp-in-java-debug ()
- (interactive)
- (if (jsp-in-java)
- (message "debug: in java code")
- (message "debug: not in java code")))
- (defun jsp-in-java ()
- (save-excursion
- (let* ((current-point (point))
- (start-java-tag (jsp-java-sob))
- (end-java-tag (jsp-java-eob)))
- (and (> current-point start-java-tag)
- (< current-point end-java-tag)))))
- (defun jsp-indent-java ()
- (interactive)
- "Indent a java block within a JSP page "
- (save-excursion
- (let ((start (+ 2 (jsp-java-sob)))
- (end (jsp-java-eob) ))
- (if (string= "!" (char-to-string (char-after start)))
- (setq start (+ start 1))
- nil)
- (if (jsp-in-java)
- (progn
- (java-mode)
- (goto-char start)
- ;; needed for proper indentation - removed later
- (newline)
- (insert "{")
- (newline)
-
- (goto-char end)
- ;; needed for proper indentation - removed later
- (newline)
- (insert "}")
- (newline)
- ;;
- ;; perform the indentation
- ;;
- (indent-region (+ start 2) (- end 0) nil)
- ;;
- ;; now remove the text we termporarily added for indentation
- ;;
- (delete-region (- (point) 3) (point))
- (delete-region start (+ start 3))
- (html-mode))
- ()))))
- (setq html-mode-hook
- '(lambda ()
- (define-key sgml-mode-map "\C-c\C-q" 'jsp-indent-java)
- ))
复制代码 |
|