How to Install Verilog-Mode version 3.29 for Emacs


Click here if you've got it installed, but got no colors...

 Click here if you want to see some frequently asked questions and answers.
 
 

    OK, you want to use the Verilog emacs mode, but have never used emacs, or always had some one else do the messy set up details. Here is a step by step recipe for installing the verilog-mode: 
     
     
  1. Take the mail message your received, and save it into a file. Let us say you save it into a file called foo.

  2.  

     

  3. Run uudecode on the file. There is no need to worry about deleting any mail headers; uudecode is pretty smart about all that. What you would type is:

  4.  

     

            % uudecode < foo
                  
                  This will create a file called verilog-mode.el.gz in your
                  current directory. Now you can remove the file called
                  foo.
    If your uudecode doesn't work right, feel free to use this perl version of uudecode.
     
     
  5. Now you need to uncompress the file; use gunzip which you should have, if not you can get it from the Free Software Foundation. Run:

  6.  

     

            % gunzip verilog-mode.el.gz
                  
                
  7. To install verilog mode for just your own use continue as follows:

  8.  

     

    • Make a directory called   elisp  in your home directory.

    •  

       

    • put the file verilog-mode.el in this directory, and call the file 
    • verilog-mode.el
                      
    • edit the file .emacs in your home directory. Create this file if it does not already exist.

    •  

       

    • Add the lines below (starting with (defun) to that file. Then run a new emacs process. You are all set; this new emacs and all subsequent emacsen now will know about verilog files and how to indent them, and colorize them.

    • Note: you can remove the old lisp you may have from using a previous version of verilog-mode; the below is all you need. The old stuff tried to complete the installation of font-lock mode, pick rational colors, and figure out what color your background screen was. Emacs is a fair bit better at this now.
       
       


        (defun prepend-path ( my-path )
        (setq load-path (cons (expand-file-name my-path) load-path)))
        
        (defun append-path ( my-path )
        (setq load-path (append load-path (list (expand-file-name my-path)))))
        ;; Look first in the directory ~/elisp for elisp files
        (prepend-path "~/elisp")
        ;; Load verilog mode only when needed
        (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
        ;; Any files that end in .v should be in verilog mode
        (setq auto-mode-alist (cons  '("\\.v\\'" . verilog-mode) auto-mode-alist))
        ;; Any files in verilog mode should have their keywords colorized
        (add-hook 'verilog-mode-hook '(lambda () (font-lock-mode 1)))
              
              
    
              
  9. To install verilog mode for general use, continue as follows: 
    • put the file verilog-mode.el in the appropriate directories, for XEmacs, it is likely to be /usr/local/lib/xemacs/site-lisp, and for FSF emacs it is likely to be is /usr/local/share/emacs/site-lisp. I say likely, because the person who installed emacs at your site is free to customize this to their preference. 

    • An easy way to determine the right place is to type C-h v load-path RET to emacs; this will give you a list of the paths that are searched to find lisp files. Here, typing at FSF emacs, I get: 

      load-path's value is ("/home/mac/emacs/lisp"
       "/usr/local/share/emacs/19.34/site-lisp"
       "/usr/local/share/emacs/site-lisp"
       "/usr/local/share/emacs/19.34/lisp")
      Documentation:
      *List of directories to search for files to load.
                      
                      From examining this, I deduce that
                      /usr/local/share/emacs/site-lisp seems appropriate. I
                      didn't choose /usr/local/share/emacs/19.34/site-lisp as
                      verilog-mode.el is not emacs-version specific.
    • Edit the file site-start.el in the site-lisp directory. Create this file if it does not already exist.

    •  

       

    • Add the lines below to that file. Then run a new emacs process. You are all set; this new emacs and all subsequent emacses you or anyone else at your site ever startup will know about verilog files and how to indent them, and colorize them.!

    ;; Load verilog mode only when needed
    (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
    ;; Any files that end in .v should be in verilog mode
    (setq auto-mode-alist (cons  '("\\.v\\'" . verilog-mode) auto-mode-alist))
    ;; Any files in verilog mode should have their keywords colorized
    (add-hook 'verilog-mode-hook '(lambda () (font-lock-mode 1)))
              
              
    
            

    Colors 

    Coloring your code is really cool, impresses your friends, and actually does help one code quicker, and helps one understand others code. The only problem is that each version of emacs has different ways of specifying what color should be used, and hence it is a bear. 

    For a while, I distributed code folks could put in their .emacs that would attempt to figure out what version of emacs (FSF or XEmacs) was installed, and which sub version of the two major packages was in use. Further, it attempted to determine if the user had a dark, or a light background, and then would install my notion of what might be nice colors. 

    The world is changing too fast; and both XEmacs and FSF emacs now have easy to modify, and quite reasonable defaults. Therefore I removed my distributed code, and have added this section to support folks still using older emacsen. Find your version below, and see what hints I have for getting colors to work. 

    First: install verilog-mode as per the above instructions. 

    XEmacs 20.x 
    Use menu bar Options->Customize->Faces... and set the font-lock-* faces to pleasing colors.

     

     

    XEmacs 19.16, XEmacs 19.14 
    Use menu bar Options->Edit Faces... and set the font-lock-* faces to pleasing colors. Then in menu bar Options->Syntax Highlighting select Colors

     

     

    FSF emacs 19.34 
    1. Visit a file, and get it in verilog-mode as per above install instructions. 
    2. Gag at the ugly default colors. 
    3. Include the following elisp in your .emacs: 
    4.   (setq font-lock-face-attributes
        '((font-lock-comment-face "Firebrick")
        (font-lock-string-face "RosyBrown")
        (font-lock-keyword-face "Purple")
        (font-lock-function-name-face "Blue")
        (font-lock-variable-name-face "DarkGoldenrod")
        (font-lock-type-face "DarkOliveGreen")
        (font-lock-reference-face "CadetBlue")))
       
                        These are the defaults; go ahead and change the
                        values in quotes to anything you'd rather
                        have. Clicking on the Edit->Text
                        Properties->Display Colors gives you a buffer of
                        color names, alternatively with the foreground, or
                        background in that color. This can be useful for
                        addressing the question, "That's ugly, what would be
                        a better color?" Going to Edit->Text
                        Properties->Display Faces will show you the
                        faces that have already been set up.
                    
    Older versions 
    Best is to upgrade if you can. Try: 

    To learn more about how to use emacs in general, type control-h t to an emacs process; it will lead you through a step by step tutorial about emacs. 


    Frequently Asked Questions (and Answers!)


    Q 1: I share my verilog to someone using codewrite. When they edit the code it looks unindented. Is the problems tabs, can I control whether the tools inserts tabs??? 
    A 1: This is a general problem sharing files between folks. It also occurs between folks using the same editor, as many editors allow one to set the tab width. The general solution is for you to add a write file hook that expands tabs to spaces. 


    Add the following to your .emacs file:

    (add-hook 'verilog-mode-hook '(lambda ()
                         (add-hook 'local-write-file-hooks
                         (lambda() (untabify (point-min) (point-max))))))
    
            
    Some explanation: This arranges so that any file in verilog mode (the "add-hook 'verilog-mode-hook" part) gets added to it's 'local-write-file-hooks' a call to the function 'untabify' with arguments that are the first and last character in the buffer.
    untabify does:
    `untabify' is an interactive autoloaded Lisp function
      -- autoloads from "tabify"
    
    Convert all tabs in region to multiple spaces, preserving columns.
    Called non-interactively, the region is specified by arguments
    START and END, rather than by the position of point and mark.
    The variable `tab-width' controls the spacing of tab stops.
    
                            

    Q 2: If I use Helvetica as my font, the auto indent doesn't work. 
    A 2: The indent scheme used by the verilog mode is based on counting spaces, and hence only works if you are using constant width fonts. Helvetica is not constant width, while Courier, or Fixed and the like are constant width. Sorry. 

    Q 3: How do I indent a region of code; typing TAB on every line is getting old... 

    Is there any way to indent a whole module/function/if clause etc. like c-indent-exp [M-C-q] in C-mode ? 
    A 3: Use C-M-\ to indent a region (selected by setting the point at one end, and having the cursor at the other end, as usual). Perhaps a future version of the emacs mode will include functions that mimic some of C's extra bindings. 
    Take heart; The learning curve is steep; but the view from the top is wonderful!
     
     
    Michael McNamara

    Last modified: Thu Feb 11 13:38:51 PST 1999