Posts

Showing posts with the label code format

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.

GNU Emacs as a lightweight IDE

Image
If you have a small project in any of the supported languages, you can get IDE like features without any additional installation in Emacs. Given the CEDET framework, supporting more languages boils down to simply adding a new grammar and overloading few functions. Presently, it works for the following languages (demo links in brackets): - C ( Auto-suggest data structure , Auto-suggest basic , generate header ) - LaTex ( Auto-suggest ) - SQL ( Auto-suggest from connected DB , Auto-suggest local names and statements ) - HTML, JS , CSS - Java ( Auto-suggest , Refactoring , Debugging , Type hierarchy , Semantic font-lock , Getter/setter ) - Elisp ( Auto-suggest , Refactoring ) - PHP - Assembly   - IDE Basics , Outline view , Rename symbol , Lexer based indent region , Call tree, Semantic font lock Complete playlist is here .   Steps Build Emacs from source  https://gitlab.com/atamariya/emacs/tree/dev You should put the following in your .emacs file.  Co...