]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/verilog-mode.el
* font-lock.el (font-lock-maximum-decoration): Mention what numeric levels mean.
[gnu-emacs] / lisp / progmodes / verilog-mode.el
index b565e9aeff46f1ec9057972f66116cc89e164331..f7cb1318dc0c39a27210ccc01f80cf4317eb5207 100644 (file)
@@ -1,7 +1,6 @@
 ;; verilog-mode.el --- major mode for editing verilog source in Emacs
 
-;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+;; Copyright (C) 1996-2011  Free Software Foundation, Inc.
 
 ;; Author: Michael McNamara (mac@verilog.com),
 ;;    Wilson Snyder (wsnyder@wsnyder.org)
 ;;; Code:
 
 ;; This variable will always hold the version number of the mode
-(defconst verilog-mode-version "647"
+(defconst verilog-mode-version "650"
   "Version of this Verilog mode.")
-(defconst verilog-mode-release-date "2010-10-20-GNU"
+(defconst verilog-mode-release-date "2010-11-05-GNU"
   "Release date of this Verilog mode.")
 (defconst verilog-mode-release-emacs t
   "If non-nil, this version of Verilog mode was released with Emacs itself.")
@@ -1378,19 +1377,8 @@ If set will become buffer local.")
 ;;  Macros
 ;;
 
-(defsubst verilog-get-beg-of-line (&optional arg)
-  (save-excursion
-    (beginning-of-line arg)
-    (point)))
-
-(defsubst verilog-get-end-of-line (&optional arg)
-  (save-excursion
-    (end-of-line arg)
-    (point)))
-
 (defsubst verilog-within-string ()
-  (save-excursion
-    (nth 3 (parse-partial-sexp (verilog-get-beg-of-line) (point)))))
+  (nth 3 (parse-partial-sexp (point-at-bol) (point))))
 
 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
   "Replace occurrences of FROM-STRING with TO-STRING.
@@ -1480,7 +1468,7 @@ This speeds up complicated regexp matches."
                (search-forward substr bound noerror))
       (save-excursion
        (beginning-of-line)
-       (setq done (re-search-forward regexp (verilog-get-end-of-line) noerror)))
+       (setq done (re-search-forward regexp (point-at-eol) noerror)))
       (unless (and (<= (match-beginning 0) (point))
                   (>= (match-end 0) (point)))
        (setq done nil)))
@@ -1500,7 +1488,7 @@ This speeds up complicated regexp matches."
                (search-backward substr bound noerror))
       (save-excursion
        (end-of-line)
-       (setq done (re-search-backward regexp (verilog-get-beg-of-line) noerror)))
+       (setq done (re-search-backward regexp (point-at-bol) noerror)))
       (unless (and (<= (match-beginning 0) (point))
                   (>= (match-end 0) (point)))
        (setq done nil)))
@@ -1544,16 +1532,14 @@ portion, will be substituted."
   (cond
    ((or (file-exists-p "makefile")     ;If there is a makefile, use it
        (file-exists-p "Makefile"))
-    (make-local-variable 'compile-command)
-    (setq compile-command "make "))
+    (set (make-local-variable 'compile-command) "make "))
    (t
-    (make-local-variable 'compile-command)
-    (setq compile-command
-         (if verilog-tool
-             (if (string-match "%s" (eval verilog-tool))
-                 (format (eval verilog-tool) (or buffer-file-name ""))
-               (concat (eval verilog-tool) " " (or buffer-file-name "")))
-           ""))))
+    (set (make-local-variable 'compile-command)
+         (if verilog-tool
+             (if (string-match "%s" (eval verilog-tool))
+                 (format (eval verilog-tool) (or buffer-file-name ""))
+               (concat (eval verilog-tool) " " (or buffer-file-name "")))
+           ""))))
   (verilog-modify-compile-command))
 
 (defun verilog-expand-command (command)
@@ -1577,8 +1563,8 @@ be substituted."
   (when (and
         (stringp compile-command)
         (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
-    (make-local-variable 'compile-command)
-    (setq compile-command (verilog-expand-command compile-command))))
+    (set (make-local-variable 'compile-command)
+         (verilog-expand-command compile-command))))
 
 (if (featurep 'xemacs)
     ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
@@ -1599,8 +1585,8 @@ find the errors."
                            (cdr compilation-error-regexp-alist-alist)))))
       (if (boundp 'compilation-font-lock-keywords)
          (progn
-           (make-local-variable 'compilation-font-lock-keywords)
-           (setq compilation-font-lock-keywords  verilog-error-font-lock-keywords)
+            (set (make-local-variable 'compilation-font-lock-keywords)
+                 verilog-error-font-lock-keywords)
            (font-lock-set-defaults)))
       ;; Need to re-run compilation-error-regexp builder
       (if (fboundp 'compilation-build-compilation-error-regexp-alist)
@@ -2986,7 +2972,7 @@ Use filename, if current buffer being edited shorten to just buffer name."
 ;;
 (defvar verilog-which-tool 1)
 ;;;###autoload
-(defun verilog-mode ()
+(define-derived-mode verilog-mode prog-mode "Verilog"
   "Major mode for editing Verilog code.
 \\<verilog-mode-map>
 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
@@ -3114,30 +3100,21 @@ All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
 Key bindings specific to `verilog-mode-map' are:
 
 \\{verilog-mode-map}"
-  (interactive)
-  (kill-all-local-variables)
-  (use-local-map verilog-mode-map)
-  (setq major-mode 'verilog-mode)
-  (setq mode-name "Verilog")
-  (setq local-abbrev-table verilog-mode-abbrev-table)
+  :abbrev-table verilog-mode-abbrev-table
   (set (make-local-variable 'beginning-of-defun-function)
        'verilog-beg-of-defun)
   (set (make-local-variable 'end-of-defun-function)
        'verilog-end-of-defun)
   (set-syntax-table verilog-mode-syntax-table)
-  (make-local-variable 'indent-line-function)
-  (setq indent-line-function 'verilog-indent-line-relative)
+  (set (make-local-variable 'indent-line-function)
+       #'verilog-indent-line-relative)
   (setq comment-indent-function 'verilog-comment-indent)
-  (make-local-variable 'parse-sexp-ignore-comments)
-  (setq parse-sexp-ignore-comments nil)
-  (make-local-variable 'comment-start)
-  (make-local-variable 'comment-end)
-  (make-local-variable 'comment-multi-line)
-  (make-local-variable 'comment-start-skip)
-  (setq comment-start "// "
-       comment-end ""
-       comment-start-skip "/\\*+ *\\|// *"
-       comment-multi-line nil)
+  (set (make-local-variable 'parse-sexp-ignore-comments) nil)
+
+  (set (make-local-variable 'comment-start) "// ")
+  (set (make-local-variable 'comment-end) "")
+  (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
+  (set (make-local-variable 'comment-multi-line) nil)
   ;; Set up for compilation
   (setq verilog-which-tool 1)
   (setq verilog-tool 'verilog-linter)
@@ -3177,10 +3154,10 @@ Key bindings specific to `verilog-mode-map' are:
     (add-hook 'after-change-functions 'verilog-highlight-region t t))
 
   ;; Tell imenu how to handle Verilog.
-  (make-local-variable 'imenu-generic-expression)
-  (setq imenu-generic-expression verilog-imenu-generic-expression)
+  (set (make-local-variable 'imenu-generic-expression)
+       verilog-imenu-generic-expression)
   ;; Tell which-func-modes that imenu knows about verilog
-  (when (boundp 'which-function-modes)
+  (when (boundp 'which-func-modes)
     (add-to-list 'which-func-modes 'verilog-mode))
   ;; hideshow support
   (when (boundp 'hs-special-modes-alist)
@@ -3191,8 +3168,7 @@ Key bindings specific to `verilog-mode-map' are:
                  hs-special-modes-alist))))
 
   ;; Stuff for autos
-  (add-hook 'write-contents-hooks 'verilog-auto-save-check) ; already local
-  (run-hooks 'verilog-mode-hook))
+  (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local))
 \f
 
 ;;
@@ -3925,7 +3901,7 @@ primitive or interface named NAME."
        (or  kill-existing-comment
            (not (save-excursion
                   (end-of-line)
-                  (search-backward "//" (verilog-get-beg-of-line) t)))))
+                  (search-backward "//" (point-at-bol) t)))))
       (let ((nest 1) b e
            m
            (else (if (match-end 2) "!" " ")))
@@ -3978,7 +3954,7 @@ primitive or interface named NAME."
           (or kill-existing-comment
               (not (save-excursion
                      (end-of-line)
-                     (search-backward "//" (verilog-get-beg-of-line) t)))))
+                     (search-backward "//" (point-at-bol) t)))))
       (let ((type (car indent-str)))
        (unless (eq type 'declaration)
          (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends
@@ -4512,7 +4488,7 @@ becomes:
                 (cond
                  ((looking-at "// surefire lint_off_line ")
                   (goto-char (match-end 0))
-                  (let ((lim (save-excursion (end-of-line) (point))))
+                  (let ((lim (point-at-eol)))
                     (if (re-search-forward code lim 'move)
                         (throw 'already t)
                       (insert (concat " " code)))))
@@ -4562,16 +4538,18 @@ FILENAME or defaults to `buffer-file-name`."
                                 default nil nil
                                 'verilog-preprocess-history default)))))
   (unless command (setq command (verilog-expand-command verilog-preprocessor)))
-  (let* ((dir (file-name-directory (or filename buffer-file-name)))
+  (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
+        (dir (file-name-directory (or filename buffer-file-name)))
         (file (file-name-nondirectory (or filename buffer-file-name)))
         (cmd (concat "cd " dir "; " command " " file)))
     (with-output-to-temp-buffer "*Verilog-Preprocessed*"
-      (save-excursion
-       (set-buffer "*Verilog-Preprocessed*")
+      (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
        (insert (concat "// " cmd "\n"))
        (shell-command cmd "*Verilog-Preprocessed*")
        (verilog-mode)
-       (font-lock-mode)))))
+       ;; Without this force, it takes a few idle seconds
+       ;; to get the color, which is very jarring
+       (when fontlocked (font-lock-fontify-buffer))))))
 \f
 
 ;;
@@ -4608,7 +4586,7 @@ This lets programs calling batch mode to easily extract error messages."
               (verilog-mode))))
         (buffer-list))
    ;; Process the files
-   (mapcar '(lambda (buf)
+   (mapcar (lambda (buf)
              (when (buffer-file-name buf)
                (save-excursion
                  (if (not (file-exists-p (buffer-file-name buf)))
@@ -6395,7 +6373,7 @@ for matches of `str' and adding the occurrence tp `all' through point END."
 
 (defun verilog-keyword-completion (keyword-list)
   "Give list of all possible completions of keywords in KEYWORD-LIST."
-  (mapcar '(lambda (s)
+  (mapcar (lambda (s)
             (if (string-match (concat "\\<" verilog-str) s)
                 (if (or (null verilog-pred)
                         (funcall verilog-pred s))
@@ -6515,7 +6493,7 @@ and `verilog-separator-keywords'.)"
                    (all-completions verilog-str 'verilog-completion)))
         (match (if verilog-toggle-completions
                    "" (try-completion
-                       verilog-str (mapcar '(lambda (elm)
+                       verilog-str (mapcar (lambda (elm)
                                              (cons elm 0)) allcomp)))))
     ;; Delete old string
     (delete-region b e)
@@ -7277,7 +7255,10 @@ Return a array of [outputs inouts inputs wire reg assign const]."
         ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
          (goto-char (match-end 0))
          (cond (newsig ; Memory, not just width.  Patch last signal added's memory (nth 3)
-                (setcar (cdr (cdr (cdr newsig))) (match-string 1)))
+                (setcar (cdr (cdr (cdr newsig)))
+                        (if (verilog-sig-memory newsig)
+                            (concat (verilog-sig-memory newsig) (match-string 1))
+                          (match-string 1))))
                (vec ;; Multidimensional
                 (setq multidim (cons vec multidim))
                 (setq vec (verilog-string-replace-matches
@@ -7415,7 +7396,9 @@ Return a array of [outputs inouts inputs wire reg assign const]."
                     (cons (verilog-sig-new
                            sig
                            (if dotname (verilog-sig-bits portdata) vec)
-                           (concat "To/From " comment) nil nil
+                           (concat "To/From " comment)
+                           (verilog-sig-memory portdata)
+                           nil
                            (verilog-sig-signed portdata)
                            (verilog-sig-type portdata)
                            multidim nil)
@@ -7426,7 +7409,9 @@ Return a array of [outputs inouts inputs wire reg assign const]."
                     (cons (verilog-sig-new
                            sig
                            (if dotname (verilog-sig-bits portdata) vec)
-                           (concat "From " comment) nil nil
+                           (concat "From " comment)
+                           (verilog-sig-memory portdata)
+                           nil
                            (verilog-sig-signed portdata)
                            (verilog-sig-type portdata)
                            multidim nil)
@@ -7437,7 +7422,9 @@ Return a array of [outputs inouts inputs wire reg assign const]."
                     (cons (verilog-sig-new
                            sig
                            (if dotname (verilog-sig-bits portdata) vec)
-                           (concat "To " comment) nil nil
+                           (concat "To " comment)
+                           (verilog-sig-memory portdata)
+                           nil
                            (verilog-sig-signed portdata)
                            (verilog-sig-type portdata)
                            multidim nil)
@@ -7447,7 +7434,9 @@ Return a array of [outputs inouts inputs wire reg assign const]."
                     (cons (verilog-sig-new
                            sig
                            (if dotname (verilog-sig-bits portdata) vec)
-                           (concat "To/From " comment) nil nil
+                           (concat "To/From " comment)
+                           (verilog-sig-memory portdata)
+                           nil
                            (verilog-sig-signed portdata)
                            (verilog-sig-type portdata)
                            multidim nil)
@@ -7459,7 +7448,9 @@ Return a array of [outputs inouts inputs wire reg assign const]."
                     (cons (verilog-sig-new
                            sig
                            (if dotname (verilog-sig-bits portdata) vec)
-                           (concat "To/From " comment) nil nil
+                           (concat "To/From " comment)
+                           (verilog-sig-memory portdata)
+                           nil
                            (verilog-sig-signed portdata)
                            (verilog-sig-type portdata)
                            multidim nil)
@@ -8038,8 +8029,7 @@ Optionally associate it with the specified enumeration ENUMNAME."
        (let ((enumvar (intern (concat "venum-" enumname))))
          ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
          (unless (boundp enumvar) (set enumvar nil))
-         (make-local-variable enumvar)
-         (add-to-list enumvar defname)))))
+          (add-to-list (make-local-variable enumvar) defname)))))
 
 (defun verilog-read-defines (&optional filename recurse subcall)
   "Read `defines and parameters for the current file, or optional FILENAME.
@@ -8272,8 +8262,7 @@ Some macros and such are also found and included.  For dinotrace.el."
                       ": Can't find verilog-getopt-file -f file: " filename)))
       (goto-char (point-min))
       (while (not (eobp))
-       (setq line (buffer-substring (point)
-                                    (save-excursion (end-of-line) (point))))
+       (setq line (buffer-substring (point) (point-at-eol)))
        (forward-line 1)
        (when (string-match "//" line)
          (setq line (substring line 0 (match-beginning 0))))
@@ -8874,7 +8863,9 @@ with appropriate INDENT-PT indentation."
   (indent-to (max 24 (+ indent-pt 16)))
   (unless (= (char-syntax (preceding-char)) ?\  )
     (insert " "))  ; Need space between "]name" if indent-to did nothing
-  (insert (verilog-sig-name sig)))
+  (insert (verilog-sig-name sig))
+  (when (verilog-sig-memory sig)
+    (insert " " (verilog-sig-memory sig))))
 
 (defun verilog-insert-definition (sigs direction indent-pt v2k &optional dont-sort)
   "Print out a definition for a list of SIGS of the given DIRECTION,
@@ -9344,10 +9335,9 @@ Typing \\[verilog-inject-auto] will make this into:
 (defun verilog-auto-reeval-locals (&optional force)
   "Read file local variable segment at bottom of file if it has changed.
 If FORCE, always reread it."
-  (make-local-variable 'verilog-auto-last-file-locals)
   (let ((curlocal (verilog-auto-read-locals)))
     (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
-      (setq verilog-auto-last-file-locals curlocal)
+      (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
       ;; Note this may cause this function to be recursively invoked,
       ;; because hack-local-variables may call (verilog-mode)
       ;; The above when statement will prevent it from recursing forever.
@@ -11457,13 +11447,13 @@ Wilson Snyder (wsnyder@wsnyder.org)."
               (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP([^)]*)\\*/" 'verilog-auto-inout-comp)
               ;; next in/outs which need previous sucked inputs first
               (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((\"[^\"]*\")\\)\\*/"
-                                         '(lambda () (verilog-auto-output t)))
+                                         (lambda () (verilog-auto-output t)))
               (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\*/" 'verilog-auto-output)
               (verilog-auto-re-search-do "/\\*AUTOINPUT\\((\"[^\"]*\")\\)\\*/"
-                                         '(lambda () (verilog-auto-input t)))
+                                         (lambda () (verilog-auto-input t)))
               (verilog-auto-re-search-do "/\\*AUTOINPUT\\*/"  'verilog-auto-input)
               (verilog-auto-re-search-do "/\\*AUTOINOUT\\((\"[^\"]*\")\\)\\*/"
-                                         '(lambda () (verilog-auto-inout t)))
+                                         (lambda () (verilog-auto-inout t)))
               (verilog-auto-re-search-do "/\\*AUTOINOUT\\*/" 'verilog-auto-inout)
               ;; Then tie off those in/outs
               (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
@@ -11898,7 +11888,7 @@ Clicking on the middle-mouse button loads them in a buffer (as in dired)."
         (verilog-save-scan-cache
          (let (end-point)
            (goto-char end)
-           (setq end-point (verilog-get-end-of-line))
+           (setq end-point (point-at-eol))
            (goto-char beg)
            (beginning-of-line)  ; scan entire line
            ;; delete overlays existing on this line
@@ -12122,5 +12112,4 @@ but instead, [[Fill in here]] happens!.
 ;; checkdoc-force-docstrings-flag:nil
 ;; End:
 
-;; arch-tag: 87923725-57b3-41b5-9494-be21118c6a6f
 ;;; verilog-mode.el ends here