Posts

Showing posts with the label java

Semantic lexer based indent region function in Emacs

Image
  Here is a Semantic lexer based indent region function for formatting code in Emacs. It should work for Java and javascript. Feel free to use it if you like the output or customize it to suit your needs. Code: semantic-indent-region  Features Removes redundant whitespace. Multiple new lines are replaced by two new lines to mark paragraph separation. Adds spaces around punctuation characters. Uses tab for indent and fill-column width to wrap lines. Set values for tab-width and fill-column as per your preference. Uses first token as the anchor point and aligns the code to match the nearest tab-stop. e.g. if tab-width is 4 character, and first token is on 1-3 column, code will be aligned to first column. However, if first token is on 4th column, then alignment is not changed. Adds one indent for each level of nested code. Splits line on semi-colon.

Semantic font-lock for Java in Emacs

Image
I've been working on Semantic font-lock for Java using CEDET Semantic infrastructure which uses Wisent incremental parsing under the hood. Also it only highlights the visible text on the screen to keep the delays acceptable. So far the results look promising. Builtin font-lock uses jit-lock infrastructure. cc-mode provides the keywords and regexes for language specific highlighting. However, this lacks highlighting using any contextual information. Demo: https://youtu.be/4UcPIdTJLOM Noticeable features: Static variables and functions are highlighted differently. Constant variables are highlighted differently. Not only the declaration, but the usages are highlighted also. Package is highlighted correctly. It uses following face definitions for highlighting. (defvar semantic-format-face-alist `( (function . font-lock-function-name-face) (variable . font-lock-variable-name-face) (type . font-lock-type-face) ;; These are differe...

Drupal CMS integration with JEE

Content is best managed in a Content Management System (CMS). However, CMS system doesn't stand alone - it's most useful when integrated with other systems (.e.g. a transactional e-Commerce site). But how to do this integration? Most CMS systems (Teamsite, Drupal, Wordpress, OpenCMS etc.) either export XML content or expose APIs to access the content in XML form. So it's only logical to parse this XML and extract the content. Here's some sample code to integrate Drupal CMS content with JSP. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %> <c:import var="p" url="http://127.0.0.1/modules/drupal77x120607145002/rss.xml"/> <x:parse xml="${p}" var="output"/> <x:out select="$output/rss/channel/item/description" escapeXml="false"/> I'm still trying to figu...