Reformatting files

ISE sets TABs as 3 spaces and displays correctly within ISE. However, most text viewers treat TABs as 7 spaces which makes reading Verilog more difficult. To reformat, open the file with emacs and replace all TABs with three spaces using the replace-string command:

ESC-x                // open command line for entry
replace-string       // enter "replace-string" (emacs self completes)
TAB                  // enter TAB key
3 spaces             // press the space bar 3 times
save the file.

Verilog Editors

You don't need to use the default ISE editor. You can use any editor you want: gedit, emacs, vim... anything. To change the ISE's default editor, go to "Edit" --> "Preferences" and click the "Editors" tab under "ISE General."

Click the radio button labeled "Editor:" that currently says "ISE Text Editor" and change it to "Custom."

Now in the "Command line syntax" window add the command you would use from the command line to launch your favorite editor, i.e. "gedit $1", "emacs $1" or similar. You have to include the "$1" as an argument since it will point to the path of the file.

You can easily auto-format your code to make it less ugly - especially for uploading and printing. Ugly/messy code makes everything harder and more confusing. It's pretty easy to avoid.

If you use Gedit, run this line in Athena to get an autoformatting plugin:

add 6.111 && mkdir -p ~/.config/gedit/tools/ && cp 
/mit/6.111/verilog-autoformat ~/.config/gedit/tools/ 

Ctrl-Shift-F now auto-formats your code.

If you use vim:

:set tabstop=3 shiftwidth=3 expandtab
:retab
The first command sets tabs to be three spaces within the currently opened file, and also forces all future uses of the tab in the document you have opened to be three spaces. It does not convert already existing tabs...that is what the second command does (retabs the entire document).

If you use emacs, replace TAB with 3 spaces. Open the file in emacs

ESC-x                // open command line for entry
replace-string       // enter "replace-string" (emacs self completes)
TAB                  // enter TAB key
3 spaces             // press the space bar 3 times
save the file.

Alternatively, you can use emacs from the command line to autoformat files. If you use bash, add the following line to the bottom of your ~/.bashrc_mine:

function vf {
 emacs --batch $1 -l /usr/share/emacs/23.2/lisp/progmodes/verilog-mode.elc --eval 
 "(progn (verilog-auto) (verilog-indent-buffer) (delete-trailing-whitespace) 
 (save-buffer))" > /dev/null 2&>1
}

If you use cshell, add the following line to the bottom of your ~/.cshrc_mine:

alias vf 'emacs --batch \!:1 -l 
/usr/share/emacs/23.2/lisp/progmodes/verilog-mode.elc --eval 
"(progn ( verilog-auto ) ( verilog-indent-buffer ) ( delete-trailing-whitespace )
( save-buffer ) ) " >& /dev/null'

If you're not sure which shell you're using, run echo $SHELL

If you're not sure which shell you're using, run echo $SHELL

An example of usage in each case: vf path/to/verilog_code.v Here's the raw command used in both cases:

emacs --batch /path/to/test_file.v -l 
/usr/share/emacs/23.2/lisp/progmodes/verilog-mode.elc 
--eval "(progn (verilog-auto) (verilog-indent-buffer) (delete-trailing-whitespace) 
(save-buffer))"

Credit to Dylan Sherry MIT '12, Joe Steinmeyer