Loading ...
Sorry, an error occurred while loading the content.

Re: How to re-indent java source files?

Expand Messages
  • John Sumsion
    I use an old version of JIndent. Here are my mappings (cywin on windows): _vimrc_ nmap :call IndentFile( john.jin ) function! IndentFile(indent_type)
    Message 1 of 4 , Jan 31, 2003
    • 0 Attachment
      I use an old version of JIndent. Here are my mappings (cywin on windows):

      _vimrc_
      nmap <F5> :call IndentFile("john.jin")<CR>

      function! IndentFile(indent_type)
      if (&filetype == "java")
      normal gg
      # keep any file comments before package declaration intact
      exe "/^[ ]*package/,$!jindent -p " . a:indent_type
      else
      echo "Cannot indent this file type: " . &filetype
      endif
      endf

      _/usr/local/bin/jindent_
      #!/bin/sh

      DEFAULT="-p john.jin"

      for arg in $*; do
      if [ $arg = "-p" ]; then
      DEFAULT=
      fi
      done

      java -cp 'c:\jindent\jindent.jar;c:\jindent' Jindent $DEFAULT $* | sed -f
      /usr/l
      ocal/bin/jindentpost.sed
      # vim:set wrap:

      _/usr/local/bin/jindentpost.sed_
      #
      # Edits the output of Jindent to remove the
      # jindent processing messages
      #

      # remove the "--- formatted by Jindent" message
      1,2 {
      d
      }

      # keep a rotating buffer of the last four lines
      # read so that we can delete the last four at the
      # end of the file if we need to
      :BEGINNING

      # only try to read another line when we're not at
      # the last line
      $! {
      # if we already have four lines
      /\n.*\n.*\n/ {
      # print the first line
      P

      # and delete it from the rotating buffer
      # to make room for another line coming in
      D
      }

      # read another line into the rotating buffer
      N

      # remove any trailing spaces
      /[ ]$/ s/\(.*\)[ ][ ]*$/\1/

      # jump to the beginning of the script without
      # cycling with the normal sed "p" command
      # (which would clear our rotating buffer)
      b BEGINNING
      }

      # only clean up on the last line of the file
      $ {
      # get rid of the "--- formatting done in"
      # message
      /--- formatting/d

      # if no "--- formatting done in" message, then
      # give the last two buffered lines the boot to
      # stdout
      /--- formatting/! {
      P
      D
      P
      D
      }
      }
      # vim:set tw=50:

      _john.jin_
      ### Jindent 2.1 Property File, (www.c-lab.de/~jindent)

      ### Convention Note
      conventionName = "John's Java Convention"
      setConventionNote = true

      ### Tabulator
      emulateTabs = false
      tabulatorSize = 4

      ### Indent
      indentSize = 4
      firstLevelIndent = 0
      indentCaseFromSwitch = false
      indentDeclarations = false
      indentTooLongComments = false
      indentAlwaysAtTabColumn = true
      minimumCommentIndent = 1

      ### Braces
      leftBraceNewLine = true
      rightBraceNewLine = true
      indentLeftBrace = 0
      indentRightBrace = 0
      indentAfterRightBrace = 0

      cuddleEmptyBraces = false
      indentCuddledBraces = 1

      ### Code Modification
      insertBracesAtIfElse = true
      insertBracesAtFor = true
      insertBracesAtWhile = true
      insertBracesAtDoWhile = true

      ### JavaDocs and Comments
      createMissingJavaDocs = false

      javaDoc_method_top[00] = "/**"
      javaDoc_method_top[01] = " * Method declaration"
      javaDoc_method_param_separator[00] = " *"
      javaDoc_method_param[00] = " * @param"
      javaDoc_method_return[00] = " *"
      javaDoc_method_return[01] = " * @return"
      javaDoc_method_exception_separator[00] = " *"
      javaDoc_method_exception[00] = " * @throws"
      javaDoc_method_bottom[00] = " *"
      javaDoc_method_bottom[01] = " * @see"
      javaDoc_method_bottom[02] = " */"

      javaDoc_constructor_top[00] = "/**"
      javaDoc_constructor_top[01] = " * Constructor declaration"
      javaDoc_constructor_param_separator[00] = " *"
      javaDoc_constructor_param[00] = " * @param"
      javaDoc_constructor_exception_separator[00] = " *"
      javaDoc_constructor_exception[00] = " * @throws"
      javaDoc_constructor_bottom[00] = " *"
      javaDoc_constructor_bottom[01] = " * @see"
      javaDoc_constructor_bottom[02] = " */"

      javaDoc_class[00] = "/**"
      javaDoc_class[01] = " * Class declaration"
      javaDoc_class[02] = " *"
      javaDoc_class[03] = " * @author"
      javaDoc_class[04] = " * @version %I%, %G%"
      javaDoc_class[05] = " */"

      javaDoc_interface[00] = "/**"
      javaDoc_interface[01] = " * Interface declaration"
      javaDoc_interface[02] = " *"
      javaDoc_interface[03] = " * @author"
      javaDoc_interface[04] = " * @version %I%, %G%"
      javaDoc_interface[05] = " */"

      ignoreJavaDocs = false
      ignoreMultiLineComments = false
      ignoreSingleLineComments = false

      ### Blank Lines
      blankLinesAfterDeclarations = 1
      blankLinesAfterMethods = 1

      blankLinesBetweenClassInterface = 2

      blankLinesBetweenChunks = 1

      blankLinesBeforeJavaDocs = 1
      blankLinesAfterJavaDocs = 0

      blankLinesBeforeMultiComments = 0
      blankLinesAfterMultiComments = 0

      blankLinesBeforeSingleComments = 0
      blankLinesAfterSingleComments = 0

      keepBlankLines = true

      ### Whitespaces
      separateAssignmentOperators = true
      separateConditionalOperators = true
      separateComparisonOperators = true
      separateNumericalOperators = true

      spaceAfterComma = true
      spaceAfterSemicolon = true
      spaceAfterCasting = true
      spaceBeforeMethodParameters = false
      spaceBeforeStatementParameters = true

      paddingParenthesis = false
      paddingBrackets = false

      ### Line Wrapping
      wrapLines = true
      wrapBecauseOfComments = true
      wrapLongMethodNames = false
      maxLineLength = 79
      deepIndent = 8
      forceIndent = 8
      forceIndentTolerance = 20

      ### Labels
      labelNewLine = true


      And I'm making jindent available at
      http://home.earthlink.net/~jdsumsion/Jindent21.zip

      John...


      At 03:50 AM 1/31/2003, you wrote:
      >Hi, can I auto-format java source file using vim? Someone tell me using
      >"=%" can do this, but I can't make it work...
      >
      > \\\|///
      > \- - -//
      > ( @ @ )
      >-----------oOOo-(_)-oOOo------------------------------------------------
      >Visit my homepage at http://www.carfield.com.hk
      >
      >Programming discussion groups
      >Software design: news://news.carfield.com.hk/programming.design
      >Design Pattern: news://news.carfield.com.hk/programming.design.pattern
      >java: news://news.carfield.com.hk/programming.java
      >linux: news://news.carfield.com.hk/programming.linux
      >------------------------------------------------------------------------
    Your message has been successfully submitted and would be delivered to recipients shortly.