annotate lisp/modes/verilog-mode.el @ 157:6b37e6ddd302 r20-3b5

Import from CVS: tag r20-3b5
author cvs
date Mon, 13 Aug 2007 09:40:41 +0200
parents 25f70ba0133c
children 28f395d8dc7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1 ;;; verilog-mode.el --- major mode for editing verilog source in Emacs
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2 ;;
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 142
diff changeset
3 ;; $Header: /afs/informatik.uni-tuebingen.de/local/web/xemacs/xemacs-cvs/XEmacs/xemacs/lisp/modes/Attic/verilog-mode.el,v 1.5 1997/05/29 23:49:56 steve Exp $
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5 ;; Copyright (C) 1996 Free Software Foundation, Inc.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
7 ;; Author: Michael McNamara (mac@silicon-sorcery.com)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
8 ;; President, Silicon Sorcery
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
9 ;; Keywords: languages
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
10
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
12
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
13 ;; This program is free software; you can redistribute it and/or modify
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2 of the License, or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
16 ;; (at your option) any later version.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
17
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
18 ;; This program is distributed in the hope that it will be useful,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
21 ;; GNU General Public License for more details.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
22
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
24 ;; along with this program; if not, write to the Free Software
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
25 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
26
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
27 ;;; Commentary:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
28
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
29 ;;; This mode borrows heavily from the pascal-mode and the cc-mode of emacs
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
30
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
31 ;;; USAGE
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
32 ;;; =====
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
33
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
34 ;;; A major mode for editing Verilog HDL source code. When you have
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
35 ;;; entered Verilog mode, you may get more info by pressing C-h m. You
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
36 ;;; may also get online help describing various functions by: C-h f
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
37 ;;; <Name of function you want described>
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
38
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
39 ;;; To set up automatic verilog mode, put this file in your load path,
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
40 ;;; and include stuff like this in your .emacs:
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
41
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
42 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
43 ; (setq auto-mode-alist (cons '("\\.v\\'" . verilog-mode) auto-mode-alist))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
44 ; (setq auto-mode-alist (cons '("\\.dv\\'" . verilog-mode) auto-mode-alist))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
45
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
46 ;;; If you want to customize Verilog mode to fit your needs better,
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
47 ;;; you may add these lines (the values of the variables presented
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
48 ;;; here are the defaults):
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
49 ;;;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
50 ;;; ;; User customization for Verilog mode
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
51 ;;; (setq verilog-indent-level 3
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
52 ;;; verilog-indent-level-module 3
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
53 ;;; verilog-indent-level-declaration 3
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
54 ;;; verilog-indent-level-behavorial 3
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
55 ;;; verilog-case-indent 2
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
56 ;;; verilog-auto-newline t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
57 ;;; verilog-auto-indent-on-newline t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
58 ;;; verilog-tab-always-indent t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
59 ;;; verilog-auto-endcomments t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
60 ;;; verilog-minimum-comment-distance 40
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
61 ;;; verilog-indent-begin-after-if t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
62 ;;; verilog-auto-lineup '(all))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
63
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
64 ;;; KNOWN BUGS / BUGREPORTS
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
65 ;;; ======================= This is beta code, and likely has
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
66 ;;; bugs. Please report any and all bugs to me at mac@silicon-sorcery.com.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
67 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
68 ;;; Code:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
69
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
70 (provide 'verilog-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
71
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
72 ;; This variable will always hold the version number of the mode
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 142
diff changeset
73 (defconst verilog-mode-version "$$Revision: 1.5 $$"
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
74 "Version of this verilog mode.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
75
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
76 ;;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
77 ;; A hack so we can support either custom, or the old defvar
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
78 ;;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
79 (eval-and-compile
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
80 (condition-case ()
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
81 (require 'custom)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
82 (error nil))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
83 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
84 nil ;; We've got what we needed
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
85 ;; We have the old custom-library, hack around it!
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
86 (defmacro defgroup (&rest args)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
87 nil)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
88 (defmacro customize (&rest args)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
89 (message "Sorry, Customise is not available with this version of emacs"))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
90 (defmacro defcustom (var value doc &rest args)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
91 (` (defvar (, var) (, value) (, doc))))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
92
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
93 (defun verilog-customize ()
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
94 "Link to customize screen for Verilog"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
95 (interactive)
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
96 (customize 'verilog)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
97 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
98
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
99 (defgroup verilog nil
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
100 "Faciliates easy editing of Verilog source text"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
101 :group 'languages)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
102
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
103 (defcustom verilog-indent-level 3
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
104 "*Indentation of Verilog statements with respect to containing block."
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
105 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
106 :type 'integer
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
107 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
108
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
109 (defcustom verilog-indent-level-module 3
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
110 "* Indentation of Module level Verilog statements. (eg always, initial)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
111 Set to 0 to get initial and always statements lined up
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
112 on the left side of your screen."
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
113 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
114 :type 'integer
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
115 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
116
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
117 (defcustom verilog-indent-level-declaration 3
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
118 "*Indentation of declarations with respect to containing block.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
119 Set to 0 to get them list right under containing block."
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
120 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
121 :type 'integer
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
122 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
123
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
124 (defcustom verilog-indent-level-behavorial 3
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
125 "*Absolute indentation of first begin in a task or function block
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
126 Set to 0 to get such code to start at the left side of the screen."
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
127 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
128 :type 'integer
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
129 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
130
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
131 (defcustom verilog-cexp-indent 1
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
132 "*Indentation of Verilog statements split across lines."
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
133 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
134 :type 'integer
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
135 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
136
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
137 (defcustom verilog-case-indent 2
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
138 "*Indentation for case statements."
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
139 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
140 :type 'integer
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
141 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
142
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
143 (defcustom verilog-auto-newline t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
144 "*Non-nil means automatically newline after semicolons"
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
145 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
146 :type 'integer
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
147 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
148
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
149 (defcustom verilog-auto-indent-on-newline t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
150 "*Non-nil means automatically indent line after newline"
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
151 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
152 :type 'integer
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
153 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
154
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
155 (defcustom verilog-tab-always-indent t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
156 "*Non-nil means TAB in Verilog mode should always reindent the
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
157 current line, regardless of where in the line point is when the TAB
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
158 command is used."
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
159 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
160 :type 'integer
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
161 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
162
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
163 (defcustom verilog-indent-begin-after-if t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
164 "*If true, indent begin statements following if, else, while, for
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
165 and repeat. otherwise, line them up."
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
166 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
167 :type 'boolean )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
168
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
169 (defcustom verilog-auto-endcomments t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
170 "*Non-nil means a comment /* ... */ is set after the ends which ends
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
171 cases and functions. The name of the function or case will be set
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
172 between the braces."
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
173 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
174 :type 'boolean )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
175
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
176 (defcustom verilog-minimum-comment-distance 40
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
177 "*Minimum distance between begin and end required before a comment
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
178 will be inserted. Setting this variable to zero results in every
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
179 end aquiring a comment; the default avoids too many redundanet
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
180 comments in tight quarters"
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 134
diff changeset
181 :group 'verilog
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
182 :type 'integer
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
183 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
184
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
185 (defvar verilog-auto-lineup '(all)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
186 "*List of contexts where auto lineup of :'s or ='s should be done.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
187 Elements can be of type: 'declaration' or 'case', which will do auto
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
188 lineup in declarations or case-statements respectively. The word 'all'
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
189 will do all lineups. '(case declaration) for instance will do lineup
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
190 in case-statements and parameterlist, while '(all) will do all
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
191 lineups."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
192 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
193
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
194 (defvar verilog-mode-abbrev-table nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
195 "Abbrev table in use in Verilog-mode buffers.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
196
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
197 (defvar verilog-font-lock-keywords-after-1930
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
198 '(
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
199 ;;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
200 ("^\\s-*\\(function\\|task\\|module\\|macromodule\\|primitive\\)\\>"
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
201 1 font-lock-keyword-face)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
202 ("^\\s-*\\(function\\|task\\|module\\|macromodule\\|primitive\\)\\>\\s-*\\(\\sw+\\)"
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
203 2 font-lock-function-name-face nil t)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
204 ("\\\\\\s-*" 0 'font-lock-function-name-face)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
205 ("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9\]+\\('[hdxbo][0-9_xz]*\\)?\\)\\|\\((\[^)\]*)\\|\\sw+\\)\\)\\)" 0 font-lock-type-face)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
206 ("\\(`\\s-*[A-Za-z][A-Za-z0-9_]*\\)" 0 font-lock-type-face)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
207 ("\\<\\(in\\(teger\\|put\\|out\\)\\|parameter\\|defparam\\|output\\|supply[01]?\\|event\\|tri\\(0\\|1\\|reg\\|and\\|or\\)?\\|w\\(ire\\|or\\|and\\)\\|time\\|re\\(al\\(time\\)?\\|g\\)\\)\\>"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
208 0 font-lock-type-face)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
209 ("\\(\\$[a-zA-Z][a-zA-Z0-9_\\$]*\\)\\|\\(\\<\\(begin\\|case[xz]?\\|end\\(case\\|function\\|task\\|module\\|table\\|primitive\\|specify\\)?\\|a\\(ssign\\|lways\\)\\|default\\|initial\\|table\\|\\(pos\\|neg\\)edge\\|else\\|for\\(ever\\|k\\)?\\|join\\|if\\|repeat\\|then\\|while\\|specify\\)\\>\\)"
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
210 0 font-lock-keyword-face)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
211 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
212 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
213
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
214 (defvar verilog-font-lock-keywords-before-1930
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
215 '(
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
216 ("^\\s-*\\(function\\|task\\|module\\|macromodule\\|primitive\\)\\>" . 1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
217 ("^\\s-*\\(function\\|task\\|module\\|macromodule\\|primitive\\)\\>\\s-*\\(\\sw+\\)"
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
218 2 font-lock-function-name-face nil t)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
219 ("\\(\\\\\\s-*\\)\\|\\(`[ \t]*[A-Za-z][A-Za-z0-9_]*\\)" 0 font-lock-function-name-face)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
220 ("[@#]" . font-lock-type-face)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
221 ("\\<\\(in\\(teger\\|put\\|out\\)\\|parameter\\|defparam\\|output\\|supply[01]?\\|event\\|tri\\(0\\|1\\|reg\\|and\\|or\\)?\\|w\\(ire\\|or\\|and\\)\\|time\\|re\\(al\\(time\\)?\\|g\\)\\)\\>"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
222 0 font-lock-type-face)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
223 ("\\(\\$[a-zA-Z][a-zA-Z0-9_\\$]*\\)\\|\\(\\<\\(begin\\|case[xz]?\\|end\\(case\\|function\\|task\\|module\\|table\\|primitive\\|specify\\)?\\|a\\(ssign\\|lways\\)\\|default\\|initial\\|table\\|\\(pos\\|neg\\)edge\\|else\\|for\\(ever\\|k\\)?\\|join\\|if\\|repeat\\|then\\|while\\|specify\\)\\>\\)" . font-lock-keyword-face)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
224 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
225 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
226
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
227 ;; Insure we have certain packages
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
228
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
229 (if (fboundp 'eval-when-compile)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
230 (eval-when-compile
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
231 (condition-case nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
232 (require 'imenu)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
233 (error nil))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
234 (condition-case nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
235 (require 'reporter)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
236 (error nil))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
237 (condition-case nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
238 (require 'easymenu)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
239 (error nil))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
240
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
241 (defvar verilog-imenu-generic-expression
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
242 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 3)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
243 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\)\\s-+\\(\\|\\[[^\\]+]\\s-+\\)\\([-A-Za-z0-9+]+\\)" 3))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
244 "Imenu expression for Verilog-mode. See `imenu-generic-expression'.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
245
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
246 (defvar verilog-mode-abbrev-table nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
247 "Abbrev table in use in Verilog-mode buffers.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
248
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
249
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
250 (define-abbrev-table 'verilog-mode-abbrev-table ())
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
251
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
252 (defvar verilog-mode-map ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
253 "Keymap used in Verilog mode.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
254 (if verilog-mode-map
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
255 ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
256 (setq verilog-mode-map (make-sparse-keymap))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
257 (define-key verilog-mode-map ";" 'electric-verilog-semi)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
258 (define-key verilog-mode-map ":" 'electric-verilog-colon)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
259 (define-key verilog-mode-map "=" 'electric-verilog-equal)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
260 (define-key verilog-mode-map "\`" 'electric-verilog-tick)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
261 (define-key verilog-mode-map "\t" 'electric-verilog-tab)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
262 (define-key verilog-mode-map "\r" 'electric-verilog-terminate-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
263 (define-key verilog-mode-map "\M-\C-b" 'electric-verilog-backward-sexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
264 (define-key verilog-mode-map "\M-\C-f" 'electric-verilog-forward-sexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
265 (define-key verilog-mode-map "\M-\r" (function (lambda ()
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
266 (interactive) (electric-verilog-terminate-line 1))))
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 142
diff changeset
267 ;; GDF - Leave the DEL key alone
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 142
diff changeset
268 ;; (define-key verilog-mode-map "\177" 'backward-delete-char-untabify)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
269 (define-key verilog-mode-map "\M-\t" 'verilog-complete-word)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
270 (define-key verilog-mode-map "\M-?" 'verilog-show-completions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
271 (define-key verilog-mode-map "\M-\C-h" 'verilog-mark-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
272 (define-key verilog-mode-map "\C-c\C-b" 'verilog-insert-block)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
273 (define-key verilog-mode-map "\C-cb" 'verilog-label-be)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
274 (define-key verilog-mode-map "\C-ci" 'verilog-pretty-declarations)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
275 (define-key verilog-mode-map "\C-cC-b" 'verilog-submit-bug-report)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
276 (define-key verilog-mode-map "\M-*" 'verilog-star-comment)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
277 (define-key verilog-mode-map "\C-c\C-c" 'verilog-comment-region)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
278 (define-key verilog-mode-map "\C-c\C-u" 'verilog-uncomment-region)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
279 (define-key verilog-mode-map "\M-\C-a" 'verilog-beg-of-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
280 (define-key verilog-mode-map "\M-\C-e" 'verilog-end-of-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
281 (define-key verilog-mode-map "\C-c\C-d" 'verilog-goto-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
282 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
283
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
284 ;; menus
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
285
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
286 (if (string-match "XEmacs" emacs-version)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
287 (defvar verilog-xemacs-menu
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
288 '("Verilog"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
289 ["Line up declarations around point" verilog-pretty-declarations t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
290 ["Redo/insert comments on every end" verilog-label-be t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
291 "----"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
292 ["Beginning of function" verilog-beg-of-defun t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
293 ["End of function" verilog-end-of-defun t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
294 ["Mark function" verilog-mark-defun t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
295 "----"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
296 ["Move to beginning of block" electric-verilog-backward-sexp t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
297 ["Move to end of block" electric-verilog-forward-sexp t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
298 "----"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
299 ["Comment Region" verilog-comment-region t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
300 ["UnComment Region" verilog-uncomment-region t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
301 ["Multi-line comment insert" verilog-star-comment t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
302 "----"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
303 ["Insert begin-end block" verilog-insert-block t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
304 ["Complete word" verilog-complete-word t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
305 "----"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
306 ["Submit bug report" verilog-submit-bug-report t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
307 ["Customize Verilog Mode..." verilog-customize t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
308 "XEmacs menu for VERILOG mode."))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
309 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
310 (easy-menu-define verilog-menu verilog-mode-map "Menu for Verilog mode"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
311 '("Verilog"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
312 ["Line up declarations around point" verilog-pretty-declarations t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
313 ["Redo/insert comments on every end" verilog-label-be t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
314 "----"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
315 ["Beginning of function" verilog-beg-of-defun t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
316 ["End of function" verilog-end-of-defun t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
317 ["Mark function" verilog-mark-defun t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
318 "----"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
319 ["Move to beginning of block" electric-verilog-backward-sexp t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
320 ["Move to end of block" electric-verilog-forward-sexp t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
321 "----"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
322 ["Comment Region" verilog-comment-region t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
323 ["UnComment Region" verilog-uncomment-region t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
324 ["Multi-line comment insert" verilog-star-comment t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
325 "----"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
326 ["Insert begin-end block" verilog-insert-block t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
327 ["Complete word" verilog-complete-word t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
328 "----"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
329 ["Submit bug report" verilog-submit-bug-report t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
330 ["Customize Verilog Mode..." verilog-customize t]
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
331 ))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
332
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
333 (defvar verilog-mode-abbrev-table nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
334 "Abbrev table in use in Verilog-mode buffers.")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
335
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
336 (define-abbrev-table 'verilog-mode-abbrev-table ())
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
337
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
338
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
339 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
340 ;;; Regular expressions used to calculate indent, etc.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
341 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
342 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
343 (defconst verilog-case-re "\\(\\<case[xz]?\\>\\)")
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
344 ;; Want to match
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
345 ;; aa :
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
346 ;; aa,bb :
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
347 ;; a[34:32] :
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
348 ;; a,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
349 ;; b :
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
350 (defconst
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
351 verilog-no-indent-begin-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
352 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\)\\>")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
353 (defconst verilog-ends-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
354 (concat
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
355 "\\(\\<else\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
356 "\\(\\<if\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
357 "\\(\\<end\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
358 "\\(\\<join\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
359 "\\(\\<endcase\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
360 "\\(\\<endtable\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
361 "\\(\\<endspecify\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
362 "\\(\\<endfunction\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
363 "\\(\\<endtask\\>\\)"))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
364
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
365
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
366 (defconst verilog-enders-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
367 (concat "\\(\\<endcase\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
368 "\\(\\<end\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
369 "\\(\\<end\\(\\(function\\)\\|\\(task\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
370 "\\(module\\)\\|\\(primitive\\)\\)\\>\\)"))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
371 (defconst verilog-endcomment-reason-re
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
372 (concat
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
373 "\\(\\<fork\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
374 "\\(\\<begin\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
375 "\\(\\<if\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
376 "\\(\\<else\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
377 "\\(\\<end\\>.*\\<else\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
378 "\\(\\<task\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
379 "\\(\\<function\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
380 "\\(\\<initial\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
381 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
382 "\\(\\<while\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
383 "\\(\\<for\\(ever\\)?\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
384 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
385 "#"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
386
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
387 (defconst verilog-named-block-re "begin[ \t]*:")
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
388 (defconst verilog-beg-block-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
389 ;; "begin" "case" "casex" "fork" "casez" "table" "specify" "function" "task"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
390 "\\(\\<\\(begin\\>\\|case\\(\\>\\|x\\>\\|z\\>\\)\\|f\\(ork\\>\\|unction\\>\\)\\|specify\\>\\|ta\\(ble\\>\\|sk\\>\\)\\)\\)")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
391
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
392 (defconst verilog-beg-block-re-1
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
393 "\\<\\(begin\\)\\|\\(case[xz]?\\)\\|\\(fork\\)\\|\\(table\\)\\|\\(specify\\)\\|\\(function\\)\\|\\(task\\)\\>")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
394 (defconst verilog-end-block-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
395 ;; "end" "join" "endcase" "endtable" "endspecify" "endtask" "endfunction"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
396 "\\<\\(end\\(\\>\\|case\\>\\|function\\>\\|specify\\>\\|ta\\(ble\\>\\|sk\\>\\)\\)\\|join\\>\\)")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
397
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
398 (defconst verilog-end-block-re-1 "\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\>\\)\\|\\(\\<endtable\\>\\)\\|\\(\\<endspecify\\>\\)\\|\\(\\<endfunction\\>\\)\\|\\(\\<endtask\\>\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
399 (defconst verilog-declaration-re
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
400 ;; "input" "inout" "output" "integer" "parameter" "defparam" "event"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
401 ;; "real" "reg" "realtime" "time" "tri" "tri0" "tri1" "trireg" "triand"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
402 ;; "trior" "supply0" "supply1" "wire" "wor" "wand"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
403 "\\(\\<\\(defparam\\>\\|event\\>\\|in\\(out\\>\\|put\\>\\|teger\\>\\)\\|output\\>\\|parameter\\>\\|re\\(al\\(\\>\\|time\\>\\)\\|g\\>\\)\\|supply\\(0\\>\\|1\\>\\)\\|t\\(ime\\>\\|ri\\(0\\>\\|1\\>\\|\\>\\|and\\>\\|or\\>\\|reg\\>\\)\\)\\|w\\(and\\>\\|ire\\>\\|or\\>\\)\\)\\)")
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
404 (defconst verilog-declaration-re-1 (concat "^[ \t]*" verilog-declaration-re "[ \t]*\\(\\[[^]]*\\][ \t]*\\)?"))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
405 (defconst verilog-declaration-re-2 (concat "[ \t]*" verilog-declaration-re "[ \t]*\\(\\[[^]]*\\][ \t]*\\)?"))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
406 (defconst verilog-defun-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
407 ;;"module" "macromodule" "primitive"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
408 "\\(\\<\\(m\\(acromodule\\>\\|odule\\>\\)\\|primitive\\>\\)\\)")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
409 (defconst verilog-end-defun-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
410 ;; "endmodule" "endprimitive"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
411 "\\(\\<end\\(module\\>\\|primitive\\>\\)\\)")
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
412 (defconst verilog-zero-indent-re
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
413 (concat verilog-defun-re "\\|" verilog-end-defun-re))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
414 (defconst verilog-directive-re
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
415 ;; "`else" "`ifdef" "`endif" "`define" "`undef" "`include"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
416 "\\(\\<`\\(define\\>\\|e\\(lse\\>\\|ndif\\>\\)\\|i\\(fdef\\>\\|nclude\\>\\)\\|undef\\>\\)\\)")
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
417 (defconst verilog-autoindent-lines-re
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
418 ;; "macromodule" "module" "primitive" "end" "endcase" "endfunction"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
419 ;; "endtask" "endmodule" "endprimitive" "endspecify" "endtable" "join"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
420 ;; "begin" "else" "`else" "`ifdef" "`endif" "`define" "`undef" "`include"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
421 "\\(\\<\\(`\\(define\\>\\|e\\(lse\\>\\|ndif\\>\\)\\|i\\(fdef\\>\\|nclude\\>\\)\\|undef\\>\\)\\|begin\\>\\|e\\(lse\\>\\|nd\\(\\>\\|case\\>\\|function\\>\\|module\\>\\|primitive\\>\\|specify\\>\\|ta\\(ble\\>\\|sk\\>\\)\\)\\)\\|join\\>\\|m\\(acromodule\\>\\|odule\\>\\)\\|primitive\\>\\)\\)")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
422
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
423 (defconst verilog-behavorial-block-beg-re
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
424 "\\(\\<initial\\>\\|\\<always\\>\\|\\<function\\>\\|\\<task\\>\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
425 (defconst verilog-indent-reg
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
426 (concat
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
427 "\\(\\<begin\\>\\|\\<case[xz]?\\>\\|\\<specify\\>\\|\\<fork\\>\\|\\<table\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
428 "\\(\\<end\\>\\|\\<join\\>\\|\\<endcase\\>\\|\\<endtable\\>\\|\\<endspecify\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
429 "\\(\\<module\\>\\|\\<macromodule\\>\\|\\<primitive\\>\\|\\<initial\\>\\|\\<always\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
430 "\\(\\<endmodule\\>\\|\\<endprimitive\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
431 "\\(\\<endtask\\>\\|\\<endfunction\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
432 "\\(\\<function\\>\\|\\<task\\>\\)"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
433 ;; "\\|\\(\\<if\\>\\|\\<else\\>\\)"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
434 ))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
435 (defconst verilog-indent-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
436 "\\(\\<\\(always\\>\\|begin\\>\\|case\\(\\>\\|x\\>\\|z\\>\\)\\|end\\(\\>\\|case\\>\\|function\\>\\|module\\>\\|primitive\\>\\|specify\\>\\|ta\\(ble\\>\\|sk\\>\\)\\)\\|f\\(ork\\>\\|unction\\>\\)\\|initial\\>\\|join\\>\\|m\\(acromodule\\>\\|odule\\>\\)\\|primitive\\>\\|specify\\>\\|ta\\(ble\\>\\|sk\\>\\)\\)\\)")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
437
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
438 (defconst verilog-defun-level-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
439 ;; "module" "macromodule" "primitive" "initial" "always" "endtask" "endfunction"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
440 "\\(\\<\\(always\\>\\|end\\(function\\>\\|task\\>\\)\\|initial\\>\\|m\\(acromodule\\>\\|odule\\>\\)\\|primitive\\>\\)\\)")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
441 (defconst verilog-cpp-level-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
442 ;;"endmodule" "endprimitive"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
443 "\\(\\<end\\(module\\>\\|primitive\\>\\)\\)")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
444 (defconst verilog-behavorial-level-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
445 ;; "function" "task"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
446 "\\(\\<\\(function\\>\\|task\\>\\)\\)")
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
447 (defconst verilog-complete-reg
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
448 ;; "always" "repeat" "case" "casex" "casez" "while" "if" "for" "forever"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
449 "\\(\\<\\(always\\>\\|case\\(\\>\\|x\\>\\|z\\>\\)\\|else\\|for\\(\\>\\|ever\\>\\)\\|if\\>\\|repeat\\>\\|while\\>\\)\\)")
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
450 (defconst verilog-end-statement-re
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
451 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
452 verilog-end-block-re "\\)"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
453 (defconst verilog-endcase-re
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
454 (concat verilog-case-re "\\|"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
455 "\\(endcase\\)\\|"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
456 verilog-defun-re
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
457 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
458 ;;; Strings used to mark beginning and end of excluded text
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
459 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
460 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
461
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
462 (defconst verilog-emacs-features
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
463 (let ((major (and (boundp 'emacs-major-version)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
464 emacs-major-version))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
465 (minor (and (boundp 'emacs-minor-version)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
466 emacs-minor-version))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
467 flavor comments)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
468 ;; figure out version numbers if not already discovered
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
469 (and (or (not major) (not minor))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
470 (string-match "\\([0-9]+\\).\\([0-9]+\\)" emacs-version)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
471 (setq major (string-to-int (substring emacs-version
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
472 (match-beginning 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
473 (match-end 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
474 minor (string-to-int (substring emacs-version
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
475 (match-beginning 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
476 (match-end 2)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
477 (if (not (and major minor))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
478 (error "Cannot figure out the major and minor version numbers."))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
479 ;; calculate the major version
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
480 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
481 ((= major 18) (setq major 'v18)) ;Emacs 18
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
482 ((= major 4) (setq major 'v18)) ;Epoch 4
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
483 ((= major 20) (setq major 'v20
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
484 flavor 'XEmacs))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
485 ((= major 19) (setq major 'v19 ;Emacs 19
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
486 flavor (if (or (string-match "Lucid" emacs-version)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
487 (string-match "XEmacs" emacs-version))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
488 'XEmacs 'FSF)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
489 ;; I don't know
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
490 (t (error "Cannot recognize major version number: %s" major)))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
491 ;; XEmacs 19 uses 8-bit modify-syntax-entry flags, as do all
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
492 ;; patched Emacs 19, Emacs 18, Epoch 4's. Only Emacs 19 uses a
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
493 ;; 1-bit flag. Let's be as smart as we can about figuring this
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
494 ;; out.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
495 (if (or (eq major 'v20) (eq major 'v19))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
496 (let ((table (copy-syntax-table)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
497 (modify-syntax-entry ?a ". 12345678" table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
498 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
499 ;; XEmacs pre 20 and Emacs pre 19.30 use vectors for syntax tables.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
500 ((vectorp table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
501 (if (= (logand (lsh (aref table ?a) -16) 255) 255)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
502 (setq comments '8-bit)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
503 (setq comments '1-bit)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
504 ;; XEmacs 20 is known to be 8-bit
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
505 ((eq flavor 'XEmacs) (setq comments '8-bit))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
506 ;; Emacs 19.30 and beyond are known to be 1-bit
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
507 ((eq flavor 'FSF) (setq comments '1-bit))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
508 ;; Don't know what this is
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
509 (t (error "Couldn't figure out syntax table format."))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
510 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
511 ;; Emacs 18 has no support for dual comments
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
512 (setq comments 'no-dual-comments))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
513 ;; lets do some minimal sanity checking.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
514 (if (or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
515 ;; Lemacs before 19.6 had bugs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
516 (and (eq major 'v19) (eq flavor 'XEmacs) (< minor 6))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
517 ;; Emacs 19 before 19.21 has known bugs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
518 (and (eq major 'v19) (eq flavor 'FSF) (< minor 21))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
519 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
520 (with-output-to-temp-buffer "*verilog-mode warnings*"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
521 (print (format
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
522 "The version of Emacs that you are running, %s,
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
523 has known bugs in its syntax parsing routines which will affect the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
524 performance of verilog-mode. You should strongly consider upgrading to the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
525 latest available version. verilog-mode may continue to work, after a
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
526 fashion, but strange indentation errors could be encountered."
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
527 emacs-version))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
528 ;; Emacs 18, with no patch is not too good
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
529 (if (and (eq major 'v18) (eq comments 'no-dual-comments))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
530 (with-output-to-temp-buffer "*verilog-mode warnings*"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
531 (print (format
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
532 "The version of Emacs 18 you are running, %s,
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
533 has known deficiencies in its ability to handle the dual verilog
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
534 (and C++) comments, (e.g. the // and /* */ comments). This will
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
535 not be much of a problem for you if you only use the /* */ comments,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
536 but you really should strongly consider upgrading to one of the latest
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
537 Emacs 19's. In Emacs 18, you may also experience performance degradations.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
538 Emacs 19 has some new built-in routines which will speed things up for you.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
539 Because of these inherent problems, verilog-mode is not supported
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
540 on emacs-18."
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
541 emacs-version))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
542 ;; Emacs 18 with the syntax patches are no longer supported
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
543 (if (and (eq major 'v18) (not (eq comments 'no-dual-comments)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
544 (with-output-to-temp-buffer "*verilog-mode warnings*"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
545 (print (format
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
546 "You are running a syntax patched Emacs 18 variant. While this should
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
547 work for you, you may want to consider upgrading to Emacs 19.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
548 The syntax patches are no longer supported either for verilog-mode."))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
549 (list major comments))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
550 "A list of features extant in the Emacs you are using.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
551 There are many flavors of Emacs out there, each with different
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
552 features supporting those needed by verilog-mode. Here's the current
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
553 supported list, along with the values for this variable:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
554
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
555 Vanilla Emacs 18/Epoch 4: (v18 no-dual-comments)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
556 Emacs 18/Epoch 4 (patch2): (v18 8-bit)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
557 XEmacs (formerly Lucid) 19: (v19 8-bit)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
558 XEmacs 20: (v20 8-bit)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
559 Emacs 19: (v19 1-bit).")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
560
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
561 (defconst verilog-comment-start-regexp "//\\|/\\*"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
562 "Dual comment value for `comment-start-regexp'.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
563
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
564 (defun verilog-populate-syntax-table (table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
565 ;; Populate the syntax TABLE
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
566 ;; DO NOT TRY TO SET _ (UNDERSCORE) TO WORD CLASS!
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
567 (modify-syntax-entry ?\\ "\\" table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
568 (modify-syntax-entry ?+ "." table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
569 (modify-syntax-entry ?- "." table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
570 (modify-syntax-entry ?= "." table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
571 (modify-syntax-entry ?% "." table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
572 (modify-syntax-entry ?< "." table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
573 (modify-syntax-entry ?> "." table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
574 (modify-syntax-entry ?& "." table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
575 (modify-syntax-entry ?| "." table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
576 (modify-syntax-entry ?_ "w" table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
577 (modify-syntax-entry ?\' "." table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
578 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
579
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
580 (defun verilog-setup-dual-comments (table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
581 ;; Set up TABLE to handle block and line style comments
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
582 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
583 ((memq '8-bit verilog-emacs-features)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
584 ;; XEmacs (formerly Lucid) has the best implementation
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
585 (modify-syntax-entry ?/ ". 1456" table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
586 (modify-syntax-entry ?* ". 23" table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
587 (modify-syntax-entry ?\n "> b" table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
588 ;; Give CR the same syntax as newline, for selective-display
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
589 (modify-syntax-entry ?\^m "> b" table))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
590 ((memq '1-bit verilog-emacs-features)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
591 ;; Emacs 19 does things differently, but we can work with it
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
592 (modify-syntax-entry ?/ ". 124b" table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
593 (modify-syntax-entry ?* ". 23" table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
594 (modify-syntax-entry ?\n "> b" table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
595 ;; Give CR the same syntax as newline, for selective-display
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
596 (modify-syntax-entry ?\^m "> b" table))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
597 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
598
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
599 (defvar verilog-mode-syntax-table nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
600 "Syntax table used in verilog-mode buffers.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
601 (if verilog-mode-syntax-table
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
602 ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
603 (setq verilog-mode-syntax-table (make-syntax-table))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
604 (verilog-populate-syntax-table verilog-mode-syntax-table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
605 ;; add extra comment syntax
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
606 (verilog-setup-dual-comments verilog-mode-syntax-table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
607 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
608
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
609 (defvar verilog-font-lock-keywords nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
610 "keyword highlighting used in verilog-mode buffers.")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
611 (defvar verilog-font-lock-keywords-1 nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
612 "keyword highlighting used in verilog-mode buffers.")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
613 (defvar verilog-font-lock-keywords-2 nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
614 "keyword highlighting used in verilog-mode buffers.")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
615 (defvar verilog-font-lock-keywords-3 nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
616 "keyword highlighting used in verilog-mode buffers.")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
617 (defvar verilog-font-lock-keywords-4 nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
618 "keyword highlighting used in verilog-mode buffers.")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
619 (if verilog-font-lock-keywords
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
620 ()
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
621 (cond
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
622 ;; We can assume 8-bit syntax table emacsen aupport new syntax
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
623 ((memq '8-bit verilog-emacs-features)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
624 (setq verilog-font-lock-keywords verilog-font-lock-keywords-after-1930
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
625 verilog-font-lock-keywords-1 verilog-font-lock-keywords-after-1930
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
626 verilog-font-lock-keywords-2 verilog-font-lock-keywords-after-1930
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
627 verilog-font-lock-keywords-3 verilog-font-lock-keywords-after-1930
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
628 verilog-font-lock-keywords-4 verilog-font-lock-keywords-after-1930)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
629 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
630 (t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
631 (setq verilog-font-lock-keywords verilog-font-lock-keywords-before-1930
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
632 verilog-font-lock-keywords-1 verilog-font-lock-keywords-before-1930
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
633 verilog-font-lock-keywords-2 verilog-font-lock-keywords-before-1930
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
634 verilog-font-lock-keywords-3 verilog-font-lock-keywords-before-1930
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
635 verilog-font-lock-keywords-4 verilog-font-lock-keywords-before-1930)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
636 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
637 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
638 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
639
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
640 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
641 ;;; Macros
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
642 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
643
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
644 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
645 "Like re-search-forward, but skips over matches in comments or strings"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
646 (set-match-data '(nil nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
647 (while (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
648 (re-search-forward REGEXP BOUND NOERROR)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
649 (and (verilog-skip-forward-comment-or-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
650 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
651 (store-match-data '(nil nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
652 (if BOUND
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
653 (< (point) BOUND)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
654 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
655 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
656 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
657 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
658 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
659 (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
660
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
661 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
662 "Like re-search-backward, but skips over matches in comments or strings"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
663 (set-match-data '(nil nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
664 (while (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
665 (re-search-backward REGEXP BOUND NOERROR)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
666 (verilog-skip-backward-comment-or-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
667 (not (set-match-data '(nil nil))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
668 ())
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
669 (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
670
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
671 (defsubst verilog-get-beg-of-line (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
672 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
673 (beginning-of-line arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
674 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
675
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
676 (defsubst verilog-get-end-of-line (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
677 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
678 (end-of-line arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
679 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
680
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
681 (defun verilog-declaration-end ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
682 (search-forward ";"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
683
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
684 (defun electric-verilog-backward-sexp ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
685 "Move backward over a sexp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
686 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
687 ;; before that see if we are in a comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
688 (verilog-backward-sexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
689 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
690 (defun electric-verilog-forward-sexp ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
691 "Move backward over a sexp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
692 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
693 ;; before that see if we are in a comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
694 (verilog-forward-sexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
695 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
696
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
697 (defun verilog-backward-sexp ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
698 (let ((reg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
699 (elsec 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
700 (found nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
701 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
702 (if (not (looking-at "\\<"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
703 (forward-word -1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
704 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
705 ((verilog-skip-backward-comment-or-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
706 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
707 ((looking-at "\\<else\\>")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
708 (setq reg (concat
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
709 verilog-end-block-re
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
710 "\\|\\(\\<else\\>\\)"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
711 "\\|\\(\\<if\\>\\)"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
712 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
713 (while (and (not found)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
714 (verilog-re-search-backward reg nil 'move))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
715 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
716 ((match-end 1) ; endblock
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
717 ; try to leap back to matching outward block by striding across
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
718 ; indent level changing tokens then immediately
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
719 ; previous line governs indentation.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
720 (verilog-leap-to-head)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
721 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
722 ((match-end 2) ; else, we're in deep
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
723 (setq elsec (1+ elsec))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
724 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
725 ((match-end 3) ; found it
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
726 (setq elsec (1- elsec))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
727 (if (= 0 elsec)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
728 ;; Now previous line describes syntax
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
729 (setq found 't)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
730 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
731 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
732 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
733 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
734 ((looking-at verilog-end-block-re)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
735 (verilog-leap-to-head)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
736 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
737 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
738 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
739 ((match-end 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
740 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
741 ((match-end 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
742 (verilog-re-search-backward "\\<primitive\\>" nil 'move))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
743 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
744 (backward-sexp 1))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
745 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
746 (backward-sexp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
747 ) ;; cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
748 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
749 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
750 (defun verilog-forward-sexp ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
751 (let ((reg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
752 (st (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
753 (if (not (looking-at "\\<"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
754 (forward-word -1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
755 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
756 ((verilog-skip-forward-comment-or-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
757 (verilog-forward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
758 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
759 ((looking-at verilog-beg-block-re-1);; begin|fork|case|table|specify
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
760 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
761 ((match-end 1) ; end
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
762 ;; Search forward for matching begin
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
763 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
764 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
765 ((match-end 2) ; endcase
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
766 ;; Search forward for matching case
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
767 (setq reg "\\(\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
768 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
769 ((match-end 3) ; join
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
770 ;; Search forward for matching fork
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
771 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
772 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
773 ((match-end 4) ; endtable
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
774 ;; Search forward for matching table
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
775 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
776 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
777 ((match-end 5) ; endspecify
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
778 ;; Search forward for matching specify
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
779 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
780 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
781 ((match-end 6) ; endfunction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
782 ;; Search forward for matching function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
783 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
784 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
785 ((match-end 7) ; endspecify
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
786 ;; Search forward for matching task
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
787 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
788 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
789 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
790 (if (forward-word 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
791 (catch 'skip
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
792 (let ((nest 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
793 (while (verilog-re-search-forward reg nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
794 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
795 ((match-end 2) ; end
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
796 (setq nest (1- nest))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
797 (if (= 0 nest)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
798 (throw 'skip 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
799 ((match-end 1) ; begin
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
800 (setq nest (1+ nest)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
801 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
802 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
803 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
804 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
805 ((looking-at "\\(\\<\\(macro\\)?module\\>\\)\\|\\(\\<primitive\\>\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
806 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
807 ((match-end 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
808 (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
809 ((match-end 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
810 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
811 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
812 (goto-char st)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
813 (if (= (following-char) ?\) )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
814 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
815 (forward-sexp 1)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
816 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
817 (goto-char st)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
818 (if (= (following-char) ?\) )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
819 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
820 (forward-sexp 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
821 ) ;; cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
822 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
823 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
824
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
825
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
826 (defun verilog-declaration-beg ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
827 (verilog-re-search-backward verilog-declaration-re (bobp) t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
828
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
829 (defsubst verilog-within-string ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
830 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
831 (nth 3 (parse-partial-sexp (verilog-get-beg-of-line) (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
832
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
833 (put 'verilog-mode 'font-lock-defaults
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
834 '((verilog-font-lock-keywords-after-1930 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
835 nil ;; nil means highlight strings & comments as well as keywords
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
836 nil ;; nil means keywords must match case
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
837 nil ;; syntax table handled elsewhere
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
838 verilog-beg-of-defun ;; function to move to beginning of reasonable region to highlight
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
839 ))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
840
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
841 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
842 (defun verilog-mode ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
843 "Major mode for editing Verilog code. \\<verilog-mode-map>
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
844 NEWLINE, TAB indents for Verilog code.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
845 Delete converts tabs to spaces as it moves back.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
846 Supports highlighting.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
847
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
848 Variables controlling indentation/edit style:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
849
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
850 verilog-indent-level (default 3)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
851 Indentation of Verilog statements with respect to containing block.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
852 verilog-indent-level-module (default 3)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
853 Absolute indentation of Module level Verilog statements.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
854 Set to 0 to get initial and always statements lined up
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
855 on the left side of your screen.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
856 verilog-indent-level-declaration (default 3)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
857 Indentation of declarations with respect to containing block.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
858 Set to 0 to get them list right under containing block.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
859 verilog-indent-level-behavorial (default 3)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
860 Indentation of first begin in a task or function block
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
861 Set to 0 to get such code to linedup underneath the task or function keyword
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
862 verilog-cexp-indent (default 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
863 Indentation of Verilog statements broken across lines.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
864 verilog-case-indent (default 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
865 Indentation for case statements.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
866 verilog-auto-newline (default nil)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
867 Non-nil means automatically newline after semicolons and the punctation
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
868 mark after an end.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
869 verilog-auto-indent-on-newline (default t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
870 Non-nil means automatically indent line after newline
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
871 verilog-tab-always-indent (default t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
872 Non-nil means TAB in Verilog mode should always reindent the current line,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
873 regardless of where in the line point is when the TAB command is used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
874 verilog-indent-begin-after-if (default t)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
875 Non-nil means to indent begin statements following a preceding
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
876 if, else, while, for and repeat statements, if any. otherwise,
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
877 the begin is lined up with the preceding token. If t, you get:
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
878 if (a)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
879 begin
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
880 otherwise you get:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
881 if (a)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
882 begin
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
883 verilog-auto-endcomments (default t)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
884 Non-nil means a comment /* ... */ is set after the ends which ends
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
885 cases, tasks, functions and modules.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
886 The type and name of the object will be set between the braces.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
887 verilog-minimum-comment-distance (default 40)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
888 Minimum distance between begin and end required before a comment
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
889 will be inserted. Setting this variable to zero results in every
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
890 end aquiring a comment; the default avoids too many redundanet
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
891 comments in tight quarters.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
892 verilog-auto-lineup (default `(all))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
893 List of contexts where auto lineup of :'s or ='s should be done.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
894
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
895 Turning on Verilog mode calls the value of the variable verilog-mode-hook with
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
896 no args, if that value is non-nil.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
897 Other useful functions are:
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
898 \\[verilog-complete-word]\t-complete word with appropriate possibilities
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
899 (functions, verilog keywords...)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
900 \\[verilog-comment-region]\t- Put marked area in a comment, fixing
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
901 nested comments.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
902 \\[verilog-uncomment-region]\t- Uncomment an area commented with \
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
903 \\[verilog-comment-region].
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
904 \\[verilog-insert-block]\t- insert begin ... end;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
905 \\[verilog-star-comment]\t- insert /* ... */
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
906 \\[verilog-mark-defun]\t- Mark function.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
907 \\[verilog-beg-of-defun]\t- Move to beginning of current function.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
908 \\[verilog-end-of-defun]\t- Move to end of current function.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
909 \\[verilog-label-be]\t- Label matching begin ... end, fork ... join
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
910 and case ... endcase statements;
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
911 "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
912 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
913 (kill-all-local-variables)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
914 (use-local-map verilog-mode-map)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
915 (setq major-mode 'verilog-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
916 (setq mode-name "Verilog")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
917 (setq local-abbrev-table verilog-mode-abbrev-table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
918 (set-syntax-table verilog-mode-syntax-table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
919 (make-local-variable 'indent-line-function)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
920 (setq indent-line-function 'verilog-indent-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
921 (setq comment-indent-function 'verilog-indent-comment)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
922 (make-local-variable 'parse-sexp-ignore-comments)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
923 (setq parse-sexp-ignore-comments nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
924 (make-local-variable 'comment-start)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
925 (make-local-variable 'comment-end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
926 (make-local-variable 'comment-multi-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
927 (make-local-variable 'comment-start-skip)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
928 (setq comment-start "// "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
929 comment-end ""
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
930 comment-start-skip "/\\*+ *\\|// *"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
931 comment-multi-line nil)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
932 ;; Setting up things for font-lock
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
933 (if (string-match "XEmacs" emacs-version)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
934 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
935 (if (and current-menubar
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
936 (not (assoc "Verilog" current-menubar)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
937 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
938 (set-buffer-menubar (copy-sequence current-menubar))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
939 (add-submenu nil verilog-xemacs-menu))) ))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
940 ;; Stuff for GNU emacs
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
941 (make-local-variable 'font-lock-defaults)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
942 (setq font-lock-defaults
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
943 '((verilog-font-lock-keywords verilog-font-lock-keywords-1
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
944 verilog-font-lock-keywords-2
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
945 verilog-font-lock-keywords-3
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
946 verilog-font-lock-keywords-4)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
947 nil t))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
948 ;; Tell imenu how to handle verilog.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
949 (make-local-variable 'imenu-generic-expression)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
950 (setq imenu-generic-expression verilog-imenu-generic-expression)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
951 ;; End GNU emacs stuff
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
952 (run-hooks 'verilog-mode-hook))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
953
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
954
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
955 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
956 ;;; Electric functions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
957 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
958 (defun electric-verilog-terminate-line (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
959 "Terminate line and indent next line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
960 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
961 ;; before that see if we are in a comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
962 (let ((state
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
963 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
964 (parse-partial-sexp (point-min) (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
965 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
966 ((nth 7 state) ; Inside // comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
967 (if (eolp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
968 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
969 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
970 (newline))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
971 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
972 (newline)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
973 (insert-string "// ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
974 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
975 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
976 (verilog-indent-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
977 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
978 ((nth 4 state) ; Inside any comment (hence /**/)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
979 (newline)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
980 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
981 (verilog-indent-comment t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
982 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
983 ((eolp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
984 ;; First, check if current line should be indented
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
985 (if (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
986 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
987 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
988 (skip-chars-forward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
989 (if (looking-at verilog-autoindent-lines-re)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
990 (let ((indent-str (verilog-indent-line)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
991 ;; Maybe we should set some endcomments
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
992 (if verilog-auto-endcomments
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
993 (verilog-set-auto-endcomments indent-str arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
994 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
995 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
996 (if arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
997 ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
998 (newline))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
999 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1000 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1001 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1002 (delete-horizontal-space)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1003 't
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1004 )))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1005 (newline)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1006 (forward-line 1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1007 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1008 ;; Indent next line
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1009 (if verilog-auto-indent-on-newline
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1010 (verilog-indent-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1011 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1012 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1013 (newline)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1014 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1015 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1016 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1017 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1018
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1019 (defun electric-verilog-semi ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1020 "Insert `;' character and reindent the line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1021 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1022 (insert last-command-char)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1023 (if (verilog-in-comment-or-string-p)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1024 ()
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1025 (save-excursion
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1026 (beginning-of-line)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1027 (verilog-indent-line))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1028 (if (and verilog-auto-newline
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1029 (= 0 (verilog-parenthesis-depth)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1030 (electric-verilog-terminate-line))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1031
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1032 (defun electric-verilog-colon ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1033 "Insert `:' and do all indentions except line indent on this line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1034 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1035 (insert last-command-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1036 ;; Do nothing if within string.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1037 (if (or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1038 (verilog-within-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1039 (not (verilog-in-case-region-p)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1040 ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1041 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1042 (let ((p (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1043 (lim (progn (verilog-beg-of-statement) (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1044 (goto-char p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1045 (verilog-backward-case-item lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1046 (verilog-indent-line)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1047 ;; (let ((verilog-tab-always-indent nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1048 ;; (verilog-indent-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1049 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1050 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1051
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1052 (defun electric-verilog-equal ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1053 "Insert `=', and do indention if within block."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1054 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1055 (insert last-command-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1056 ;; Could auto line up expressions, but not yet
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1057 ;; (if (eq (car (verilog-calculate-indent)) 'block)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1058 ;; (let ((verilog-tab-always-indent nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1059 ;; (verilog-indent-command)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1060 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1061
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1062
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1063 (defun electric-verilog-tick ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1064 "Insert back-tick, and indent to coulmn 0 if this is a CPP directive."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1065 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1066 (insert last-command-char)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1067 (if (save-excursion
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1068 (beginning-of-line)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1069 (looking-at
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1070 "^[ \t]*\`\\(\\<ifdef\\>\\|\\\<else\\>\\|\\<endif\\>\\|\\<define\\>\\)"))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1071 (save-excursion (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1072 (delete-horizontal-space))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1073
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1074 (defun electric-verilog-tab ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1075 "Function called when TAB is pressed in Verilog mode."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1076 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1077 ;; If verilog-tab-always-indent, indent the beginning of the line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1078 (if verilog-tab-always-indent
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1079 (let* (
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1080 (boi-point
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1081 (save-excursion
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1082 (beginning-of-line)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1083 (skip-chars-forward " \t")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1084 (let (type state )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1085 (setq type (verilog-indent-line))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1086 (setq state (car type))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1087 (cond
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1088 ((eq state 'block)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1089 (if (looking-at verilog-behavorial-block-beg-re )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1090 (error
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1091 (concat
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1092 "The reserved word \""
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1093 (buffer-substring (match-beginning 0) (match-end 0))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1094 "\" must be at the behavorial level!"))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1095 ))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1096 (back-to-indentation)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1097 (point))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1098 (if (< (point) boi-point)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1099 (back-to-indentation)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1100 (progn (insert "\t"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1101 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1102 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1103
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1104
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1105
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1106 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1107 ;;; Interactive functions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1108 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1109 (defun verilog-insert-block ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1110 "Insert Verilog begin ... end; block in the code with right indentation."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1111 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1112 (verilog-indent-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1113 (insert "begin")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1114 (electric-verilog-terminate-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1115 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1116 (electric-verilog-terminate-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1117 (insert "end")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1118 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1119 (verilog-indent-line)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1120
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1121 (defun verilog-star-comment ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1122 "Insert Verilog star comment at point."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1123 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1124 (verilog-indent-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1125 (insert "/*")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1126 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1127 (newline)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1128 (insert " */"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1129 (newline)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1130 (insert " * "))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1131
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1132 (defun verilog-mark-defun ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1133 "Mark the current verilog function (or procedure).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1134 This puts the mark at the end, and point at the beginning."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1135 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1136 (push-mark (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1137 (verilog-end-of-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1138 (push-mark (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1139 (verilog-beg-of-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1140 (if (fboundp 'zmacs-activate-region)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1141 (zmacs-activate-region)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1142
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1143 (defun verilog-comment-region (start end)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1144 "Put the region into a Verilog comment.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1145 The comments that are in this area are \"deformed\":
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1146 `*)' becomes `!(*' and `}' becomes `!{'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1147 These deformed comments are returned to normal if you use
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1148 \\[verilog-uncomment-region] to undo the commenting.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1149
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1150 The commented area starts with `verilog-exclude-str-start', and ends with
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1151 `verilog-include-str-end'. But if you change these variables,
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1152 \\[verilog-uncomment-region] won't recognize the comments."
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1153 (interactive "r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1154 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1155 ;; Insert start and endcomments
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1156 (goto-char end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1157 (if (and (save-excursion (skip-chars-forward " \t") (eolp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1158 (not (save-excursion (skip-chars-backward " \t") (bolp))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1159 (forward-line 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1160 (beginning-of-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1161 (insert verilog-exclude-str-end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1162 (setq end (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1163 (newline)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1164 (goto-char start)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1165 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1166 (insert verilog-exclude-str-start)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1167 (newline)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1168 ;; Replace end-comments within commented area
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1169 (goto-char end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1170 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1171 (while (re-search-backward "\\*/" start t)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1172 (replace-match "*-/" t t)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1173 (save-excursion
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1174 (let ((s+1 (1+ start)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1175 (while (re-search-backward "/\\*" s+1 t)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1176 (replace-match "/-*" t t))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1177 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1178 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1179
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1180 (defun verilog-uncomment-region ()
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1181 "Uncomment a commented area; change deformed comments back to normal.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1182 This command does nothing if the pointer is not in a commented
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1183 area. See also `verilog-comment-region'."
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1184 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1185 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1186 (let ((start (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1187 (end (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1188 ;; Find the boundaries of the comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1189 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1190 (setq start (progn (search-backward verilog-exclude-str-start nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1191 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1192 (setq end (progn (search-forward verilog-exclude-str-end nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1193 (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1194 ;; Check if we're really inside a comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1195 (if (or (equal start (point)) (<= end (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1196 (message "Not standing within commented area.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1197 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1198 ;; Remove endcomment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1199 (goto-char end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1200 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1201 (let ((pos (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1202 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1203 (delete-region pos (1+ (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1204 ;; Change comments back to normal
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1205 (save-excursion
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1206 (while (re-search-backward "\\*-/" start t)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1207 (replace-match "*/" t t)))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1208 (save-excursion
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1209 (while (re-search-backward "/-\\*" start t)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1210 (replace-match "/*" t t)))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1211 ;; Remove startcomment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1212 (goto-char start)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1213 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1214 (let ((pos (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1215 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1216 (delete-region pos (1+ (point)))))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1217
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1218 (defun verilog-beg-of-defun ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1219 "Move backward to the beginning of the current function or procedure."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1220 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1221 (verilog-re-search-backward verilog-defun-re nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1222 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1223 (defun verilog-end-of-defun ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1224 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1225 (verilog-re-search-forward verilog-end-defun-re nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1226 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1227
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1228 (defun verilog-label-be (&optional arg)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1229 "Label matching begin ... end, fork ... join and case ... endcase
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1230 statements in this module; With argument, first kill any existing
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1231 labels."
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1232 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1233 (let ((cnt 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1234 (oldpos (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1235 (b (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1236 (verilog-beg-of-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1237 (point-marker)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1238 (e (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1239 (verilog-end-of-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1240 (point-marker)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1241 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1242 (goto-char (marker-position b))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1243 (if (> (- e b) 200)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1244 (message "Relabeling module..."))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1245 (while (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1246 (> (marker-position e) (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1247 (verilog-re-search-forward
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1248 (concat
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1249 "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1250 "\\(primitive\\)\\|\\(case\\)\\)?\\>"
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1251 "\\|\\(`endif\\)\\|\\(`else\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1252 nil 'move))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1253 (goto-char (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1254 (let ((indent-str (verilog-indent-line)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1255 (verilog-set-auto-endcomments indent-str 't)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1256 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1257 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1258 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1259 (setq cnt (1+ cnt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1260 (if (= 9 (% cnt 10))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1261 (message "%d..." cnt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1262 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1263 (goto-char oldpos)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1264 (if (or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1265 (> (- e b) 200)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1266 (> cnt 20))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1267 (message "%d lines autocommented" cnt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1268 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1269 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1270 (defun verilog-beg-of-statement ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1271 "Move backward to beginning of statement"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1272 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1273 (while (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1274 (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1275 (not (looking-at verilog-complete-reg))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1276 (verilog-backward-syntactic-ws)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1277 (not (or (bolp) (= (preceding-char) ?\;)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1278 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1279 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1280 (skip-chars-backward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1281 (verilog-backward-token))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1282 (let ((last (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1283 (while (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1284 (setq last (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1285 (and (not (looking-at verilog-complete-reg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1286 (verilog-continued-line))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1287 (goto-char last)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1288 (verilog-forward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1289 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1290 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1291
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1292 (defun verilog-beg-of-statement-1 ()
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1293 "Move backward to beginning of statement"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1294 (interactive)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1295 (let ((pt (point)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1296
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1297 (while (and (not (looking-at verilog-complete-reg))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1298 (setq pt (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1299 (verilog-backward-token)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1300 (setq pt (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1301 (verilog-backward-syntactic-ws)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1302 (not (bolp))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1303 (not (= (preceding-char) ?\;)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1304 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1305 (goto-char pt)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1306 (while (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1307 (setq pt (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1308 (and (not (looking-at verilog-complete-reg))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1309 (not (= (preceding-char) ?\;))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1310 (verilog-continued-line))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1311 (goto-char pt)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1312 (verilog-forward-syntactic-ws)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1313 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1314 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1315 (defun verilog-end-of-statement ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1316 "Move forward to end of current statement."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1317 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1318 (let ((nest 0) pos)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1319 (or (looking-at verilog-beg-block-re)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1320 ;; Skip to end of statement
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1321 (setq pos (catch 'found
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1322 (while t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1323 (forward-sexp 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1324 (verilog-skip-forward-comment-or-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1325 (cond ((looking-at "[ \t]*;")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1326 (skip-chars-forward "^;")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1327 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1328 (throw 'found (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1329 ((save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1330 (forward-sexp -1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1331 (looking-at verilog-beg-block-re))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1332 (goto-char (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1333 (throw 'found nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1334 ((eobp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1335 (throw 'found (point))))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1336 (if (not pos)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1337 ;; Skip a whole block
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1338 (catch 'found
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1339 (while t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1340 (verilog-re-search-forward verilog-end-statement-re nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1341 (setq nest (if (match-end 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1342 (1+ nest)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1343 (1- nest)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1344 (cond ((eobp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1345 (throw 'found (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1346 ((= 0 nest)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1347 (throw 'found (verilog-end-of-statement))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1348 pos)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1349 (defun verilog-in-case-region-p ()
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1350 "Return TRUE if in a case region: more specifically, point @ in the
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1351 line foo : @ begin"
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1352 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1353 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1354 (if (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1355 (progn (verilog-forward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1356 (looking-at "\\<begin\\>"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1357 (progn (verilog-backward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1358 (= (preceding-char) ?\:)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1359 (catch 'found
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1360 (let ((nest 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1361 (while t
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1362 (verilog-re-search-backward
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1363 (concat "\\(\\<module\\>\\)\\|\\(\\<case[xz]?\\>[^:]\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1364 "\\(\\<endcase\\>\\)\\>")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1365 nil 'move)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1366 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1367 ((match-end 3)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1368 (setq nest (1+ nest)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1369 ((match-end 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1370 (if (= nest 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1371 (throw 'found 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1372 (setq nest (1- nest))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1373 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1374 ( t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1375 (throw 'found (= nest 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1376 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1377 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1378 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1379 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1380 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1381 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1382 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1383 (defun verilog-backward-case-item (lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1384 "Skip backward to nearest enclosing case item"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1385 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1386 (let (
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1387 (str 'nil)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1388 (lim1
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1389 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1390 (save-excursion
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1391 (verilog-re-search-backward verilog-endcomment-reason-re
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1392 lim 'move)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1393 (point)))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1394 ;; Try to find the real :
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1395 (if (save-excursion (search-backward ":" lim1 t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1396 (let ((colon 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1397 b e )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1398 (while
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1399 (and
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1400 (< colon 1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1401 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1402 lim1 'move))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1403 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1404 ((match-end 1) ;; [
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1405 (setq colon (1+ colon))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1406 (if (>= colon 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1407 (error "unbalanced [")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1408 ((match-end 2) ;; ]
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1409 (setq colon (1- colon)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1410
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1411 ((match-end 3) ;; :
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1412 (setq colon (1+ colon)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1413
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1414 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1415 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1416 ;; Skip back to begining of case item
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1417 (skip-chars-backward "\t ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1418 (verilog-skip-backward-comment-or-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1419 (setq e (point))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1420 (setq b
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1421 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1422 (if
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1423 (verilog-re-search-backward
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1424 "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1425 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1426 (cond
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1427 ((match-end 1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1428 (goto-char (match-end 1))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1429 (verilog-forward-ws&directives)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1430 (if (looking-at "(")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1431 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1432 (forward-sexp)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1433 (verilog-forward-ws&directives)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1434 ))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1435 (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1436 (t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1437 (goto-char (match-end 0))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1438 (verilog-forward-ws&directives)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1439 (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1440 ))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1441 (error "Malformed case item")
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1442 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1443 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1444 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1445 (setq str (buffer-substring b e))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1446 (if
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1447 (setq e
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1448 (string-match
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1449 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1450 (setq str (concat (substring str 0 e) "...")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1451 str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1452 'nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1453 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1454 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1455
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1456
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1457 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1458 ;;; Other functions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1459 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1460
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1461 (defun kill-existing-comment ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1462 "kill autocomment on this line"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1463 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1464 (let* (
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1465 (e (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1466 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1467 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1468 (b (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1469 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1470 (search-forward "//" e t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1471 (if b
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1472 (delete-region (- b 2) e))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1473 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1474 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1475 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1476
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1477 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1478 "Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1479 Insert `// case expr ' if this line ends a case block.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1480 Insert `// ifdef FOO ' if this line ends code conditional on FOO.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1481 Insert `// NAME ' if this line ends a module or primitive named NAME."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1482 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1483 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1484 (; Comment close preprocessor directives
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1485 (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1486 (looking-at "\\(`endif\\)\\|\\(`else\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1487 (or kill-existing-comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1488 (not (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1489 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1490 (search-backward "//" (verilog-get-beg-of-line) t)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1491 (let ( (reg "\\(`else\\)\\|\\(`ifdef\\)\\|\\(`endif\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1492 (nest 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1493 b e
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1494 (else (if (match-end 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1495 1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1496 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1497 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1498 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1499 (if kill-existing-comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1500 (kill-existing-comment))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1501 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1502 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1503 (backward-sexp 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1504 (while (and (/= nest 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1505 (verilog-re-search-backward reg nil 'move))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1506 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1507 ((match-end 1) ; `else
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1508 (if (= nest 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1509 (setq else 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1510 ((match-end 2) ; `ifdef
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1511 (setq nest (1- nest)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1512 ((match-end 3) ; `endif
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1513 (setq nest (1+ nest)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1514 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1515 (if (match-end 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1516 (setq b (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1517 (skip-chars-forward "^ \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1518 (verilog-forward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1519 (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1520 e (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1521 (skip-chars-forward "a-zA-Z0-9_")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1522 (point)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1523 ))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1524 (if b
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1525 (if (> (- (point) b) verilog-minimum-comment-distance)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1526 (insert (concat (if
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1527 (= else 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1528 " // ifdef "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1529 " // !ifdef ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1530 (buffer-substring b e))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1531 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1532 (insert " // unmatched `endif")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1533 (ding 't))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1534 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1535
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1536 (; Comment close case/function/task/module and named block
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1537 (and (looking-at "\\<end")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1538 (or kill-existing-comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1539 (not (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1540 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1541 (search-backward "//" (verilog-get-beg-of-line) t)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1542 (let ((type (car indent-str)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1543 (if (eq type 'declaration)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1544 ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1545 (if
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1546 (looking-at verilog-enders-re)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1547 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1548 (;- This is a case block; search back for the start of this case
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1549 (match-end 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1550
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1551 (let ((err 't)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1552 (str "UNMATCHED!!"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1553 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1554 (verilog-leap-to-head)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1555 (if (match-end 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1556 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1557 (goto-char (match-end 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1558 (setq str (concat (buffer-substring (match-beginning 1) (match-end 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1559 (verilog-get-expr)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1560 (setq err nil))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1561 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1562 (if kill-existing-comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1563 (kill-existing-comment))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1564 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1565 (insert (concat " // " str ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1566 (if err (ding 't))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1567 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1568
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1569 (;- This is a begin..end block
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1570 (match-end 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1571 (let ((str " // UNMATCHED !!")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1572 (err 't)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1573 (here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1574 there
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1575 cntx
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1576 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1577 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1578 (verilog-leap-to-head)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1579 (setq there (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1580 (if (not (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1581 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1582 (goto-char here)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1583 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1584 (if kill-existing-comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1585 (kill-existing-comment))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1586 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1587 (insert str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1588 (ding 't)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1589 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1590 (let ( sp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1591 (lim (save-excursion (verilog-beg-of-defun) (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1592 (here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1593 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1594 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1595 (;-- handle named block differently
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1596 (looking-at verilog-named-block-re)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1597 (search-forward ":")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1598 (setq there (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1599 (setq str (verilog-get-expr))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1600 (setq err nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1601 (setq str (concat " // block: " str )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1602
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1603 ((verilog-in-case-region-p) ;-- handle case item differently
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1604 (goto-char here)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1605 (setq str (verilog-backward-case-item lim))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1606 (setq there (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1607 (setq err nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1608 (setq str (concat " // case: " str ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1609 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1610 (;- try to find "reason" for this begin
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1611 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1612 (;
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1613 (eq here (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1614 (verilog-backward-token)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1615 (verilog-beg-of-statement)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1616 (point)))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1617 (setq err nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1618 (setq str ""))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1619 ((looking-at verilog-endcomment-reason-re)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1620 (setq there (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1621 (setq cntx (concat
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1622 (buffer-substring (match-beginning 0) (match-end 0)) " "))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1623 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1624 (;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1625 (match-end 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1626 (setq err nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1627 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1628 (goto-char sp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1629 (if (and (verilog-continued-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1630 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1631 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1632 (goto-char (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1633 (setq there (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1634 (setq str
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1635 (concat " // "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1636 (buffer-substring (match-beginning 0) (match-end 0)) " "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1637 (verilog-get-expr))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1638 (setq str "")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1639 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1640 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1641 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1642 (;- else
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1643 (match-end 4)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1644 (let ((nest 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1645 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1646 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1647 (catch 'skip
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1648 (while (verilog-re-search-backward reg nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1649 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1650 ((match-end 1) ; begin
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1651 (setq nest (1- nest)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1652 ((match-end 2) ; end
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1653 (setq nest (1+ nest)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1654 ((match-end 3)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1655 (if (= 0 nest)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1656 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1657 (goto-char (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1658 (setq there (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1659 (setq err nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1660 (setq str (verilog-get-expr))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1661 (setq str (concat " // else: !if" str ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1662 (throw 'skip 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1663 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1664 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1665 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1666 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1667 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1668 (;- end else
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1669 (match-end 5)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1670 (goto-char there)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1671 (let ((nest 0)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1672 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1673 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1674 (catch 'skip
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1675 (while (verilog-re-search-backward reg nil 'move)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1676 (cond
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1677 ((match-end 1) ; begin
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1678 (setq nest (1- nest)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1679 ((match-end 2) ; end
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1680 (setq nest (1+ nest)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1681 ((match-end 3)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1682 (if (= 0 nest)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1683 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1684 (goto-char (match-end 0))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1685 (setq there (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1686 (setq err nil)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1687 (setq str (verilog-get-expr))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1688 (setq str (concat " // else: !if" str ))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1689 (throw 'skip 1))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1690 )))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1691 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1692 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1693 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1694 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1695
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1696 (;- task/function/initial et cetera
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1697 t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1698 (match-end 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1699 (goto-char (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1700 (setq there (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1701 (setq err nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1702 (setq str (verilog-get-expr))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1703 (setq str (concat " // " cntx str )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1704
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1705 (;-- otherwise...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1706 (setq str " // auto-endcomment confused ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1707 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1708 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1709 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1710 ((and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1711 (verilog-in-case-region-p) ;-- handle case item differently
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1712 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1713 (setq there (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1714 (goto-char here)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1715 (setq str (verilog-backward-case-item lim))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1716 (setq err nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1717 (setq str (concat " // case: " str ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1718 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1719 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1720 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1721 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1722 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1723 (goto-char here)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1724 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1725 (if kill-existing-comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1726 (kill-existing-comment))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1727 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1728 (if (or err
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1729 (> (- here there) verilog-minimum-comment-distance))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1730 (insert str))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1731 (if err (ding 't))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1732 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1733 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1734 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1735 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1736
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1737
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1738 (;- this is end{function,task,module}
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1739 t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1740 (let (string reg (width nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1741 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1742 (if kill-existing-comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1743 (kill-existing-comment))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1744 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1745 (backward-sexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1746 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1747 ((match-end 5)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1748 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1749 (setq width "\\([ \t]*\\[[^]]*\\]\\)?")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1750 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1751 ((match-end 6)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1752 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1753 ((match-end 7)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1754 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1755 ((match-end 8)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1756 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|function\\|task\\|\\(macro\\)?module\\)\\>\\)"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1757 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1758 (let (b e)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1759 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1760 (verilog-re-search-backward reg nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1761 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1762 ((match-end 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1763 (setq b (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1764 (skip-chars-forward "^ \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1765 (verilog-forward-ws&directives)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1766 (if (and width (looking-at width))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1767 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1768 (goto-char (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1769 (verilog-forward-ws&directives)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1770 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1771 (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1772 e (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1773 (skip-chars-forward "a-zA-Z0-9_")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1774 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1775 (setq string (buffer-substring b e)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1776 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1777 (ding 't)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1778 (setq string "unmactched end(function|task|module|primitive)")))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1779 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1780 (insert (concat " // " string )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1781 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1782 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1783 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1784 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1785 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1786 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1787 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1788 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1789 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1790
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1791 (defun verilog-get-expr()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1792 "Grab expression at point, e.g, case ( a | b & (c ^d))"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1793 (let* ((b (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1794 (verilog-forward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1795 (skip-chars-forward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1796 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1797 (e (let ((par 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1798 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1799 ((looking-at "(")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1800 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1801 (while (and (/= par 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1802 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1803 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1804 ((match-end 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1805 (setq par (1+ par)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1806 ((match-end 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1807 (setq par (1- par)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1808 (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1809 ((looking-at "\\[")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1810 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1811 (while (and (/= par 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1812 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1813 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1814 ((match-end 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1815 (setq par (1+ par)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1816 ((match-end 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1817 (setq par (1- par)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1818 (verilog-forward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1819 (skip-chars-forward "^ \t\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1820 (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1821 ((looking-at "/[/\\*]")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1822 b)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1823 ('t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1824 (skip-chars-forward "^: \t\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1825 (point)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1826 ))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1827 (str (buffer-substring b e)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1828 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1829 (setq str (concat (substring str 0 e) "...")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1830 str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1831 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1832
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1833
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1834 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1835 ;;; Indentation
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1836 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1837 (defconst verilog-indent-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1838 '((block . (+ ind verilog-indent-level))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1839 (case . (+ ind verilog-case-indent))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1840 (cparenexp . (+ ind verilog-indent-level))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1841 (cexp . (+ ind verilog-indent-level))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1842 (defun . verilog-indent-level-module)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1843 (declaration . verilog-indent-level-declaration)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1844 (tf . verilog-indent-level)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1845 (behavorial . (+ verilog-indent-level-behavorial verilog-indent-level-module))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1846 (statement . ind)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1847 (cpp . 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1848 (comment . (verilog-indent-comment))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1849 (unknown . 3)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1850 (string . 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1851
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1852 (defun verilog-calculate-indent ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1853 "Calculate the indent of the current Verilog line, through examination
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1854 of previous lines. Once a line is found that is definitive as to the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1855 type of the current line, return that lines' indent level and it's
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1856 type. Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1857 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1858 (let* ((starting_position (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1859 (par 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1860 (begin (looking-at "[ \t]*begin\\>"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1861 (type (catch 'nesting
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1862 ;; Keep working backwards until we can figure out
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1863 ;; what type of statement this is.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1864 ;; Basically we need to figure out
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1865 ;; 1) if this is a continuation of the previous line;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1866 ;; 2) are we in a block scope (begin..end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1867
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1868 ;; if we are in a comment, done.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1869 (if (verilog-in-star-comment-p) (throw 'nesting 'comment))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1870
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1871 ;; if we are in a parenthesized list, done.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1872 (if (verilog-in-paren) (progn (setq par 1) (throw 'nesting 'block)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1873
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1874 ;; See if we are continuing a previous line
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1875 (while t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1876 ;; trap out if we crawl off the top of the buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1877 (if (bobp) (throw 'nesting 'cpp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1878
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1879 (if (verilog-continued-line-1)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1880 (let ((sp (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1881 (if (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1882 (not (looking-at verilog-complete-reg))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1883 (verilog-continued-line-1))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1884 (progn (goto-char sp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1885 (throw 'nesting 'cexp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1886 (goto-char sp))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1887
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1888 (if (and begin
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1889 (not verilog-indent-begin-after-if)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1890 (looking-at verilog-no-indent-begin-re))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1891 (throw 'nesting 'statement)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1892 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1893 (throw 'nesting 'cexp)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1894 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1895 ))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1896
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1897 ;; not a continued line
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1898 (goto-char starting_position))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1899
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1900 (if (looking-at "\\<else\\>")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1901 ;; search back for governing if, striding across begin..end pairs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1902 ;; appropriately
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1903 (let ((elsec 1))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1904 (while (verilog-re-search-backward verilog-ends-re nil 'move)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1905 (cond
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1906 ((match-end 1) ; else, we're in deep
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1907 (setq elsec (1+ elsec))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1908 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1909 ((match-end 2) ; found it
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1910 (setq elsec (1- elsec))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1911 (if (= 0 elsec)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1912 ;; Now previous line describes syntax
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1913 (throw 'nesting 'statement)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1914 ))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1915 (t ; endblock
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1916 ; try to leap back to matching outward block by striding across
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1917 ; indent level changing tokens then immediately
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1918 ; previous line governs indentation.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1919 (let ((reg)(nest 1))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1920 ;; (looking-at verilog-end-block-re-1);; end|join|endcase|endtable|endspecify
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1921 (cond
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1922 ((match-end 3) ; end
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1923 ;; Search back for matching begin
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1924 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1925 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1926 ((match-end 4) ; endcase
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1927 ;; Search back for matching case
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1928 (setq reg "\\(\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1929 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1930 ((match-end 5) ; join
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1931 ;; Search back for matching fork
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1932 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1933 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1934 ((match-end 6) ; endtable
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1935 ;; Search back for matching table
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1936 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1937 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1938 ((match-end 7) ; endspecify
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1939 ;; Search back for matching specify
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1940 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1941 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1942 ((match-end 8) ; endfunction
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1943 ;; Search back for matching function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1944 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1945 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1946 ((match-end 9) ; endtask
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1947 ;; Search back for matching task
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1948 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1949 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1950 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1951 (catch 'skip
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1952 (while (verilog-re-search-backward reg nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1953 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1954 ((match-end 1) ; begin
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1955 (setq nest (1- nest))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1956 (if (= 0 nest)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1957 (throw 'skip 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1958 ((match-end 2) ; end
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1959 (setq nest (1+ nest)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1960 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1961 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1962 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1963 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1964 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1965 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1966 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1967 (throw 'nesting (verilog-calc-1))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1968 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1969 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1970 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1971 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1972 ;; Return type of block and indent level.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1973 (if (not type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1974 (setq type 'cpp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1975 (if (> par 0) ; Unclosed Parenthesis
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1976 (list 'cparenexp par)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1977 (cond
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1978 ((eq type 'case)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1979 (list type (verilog-case-indent-level)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1980 ((eq type 'statement)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1981 (list type (current-column)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1982 ((eq type 'defun)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1983 (list type 0))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1984 (t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1985 (list type (verilog-indent-level)))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1986 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1987 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1988 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1989 (defun verilog-calc-1 ()
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1990 ""
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1991 (catch 'nesting
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1992 (while (verilog-re-search-backward verilog-indent-re nil 'move)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1993 (cond
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1994 ((looking-at verilog-beg-block-re-1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1995 (cond
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1996 ((match-end 2) (throw 'nesting 'case))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1997 (t (throw 'nesting 'block))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1998
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
1999 ((looking-at verilog-end-block-re)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2000 (verilog-leap-to-head)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2001 (if (verilog-in-case-region-p)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2002 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2003 (verilog-leap-to-case-head)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2004 (if (looking-at verilog-case-re)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2005 (throw 'nesting 'case))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2006 )))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2007
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2008 ((looking-at verilog-defun-level-re)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2009 (throw 'nesting 'defun))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2010
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2011 ((looking-at verilog-cpp-level-re)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2012 (throw 'nesting 'cpp))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2013
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2014 ((looking-at verilog-behavorial-level-re)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2015 (throw 'nesting 'behavorial))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2016
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2017 ((bobp)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2018 (throw 'nesting 'cpp))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2019 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2020 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2021 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2022 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2023
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2024 (defun verilog-leap-to-case-head () ""
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2025 (let ((nest 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2026 (while (/= 0 nest)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2027 (verilog-re-search-backward "\\(\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2028 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2029 ((match-end 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2030 (setq nest (1- nest)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2031 ((match-end 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2032 (setq nest (1+ nest)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2033 ((bobp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2034 (ding 't)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2035 (setq nest 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2036 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2037 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2038 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2039 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2040
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2041 (defun verilog-leap-to-head ()
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2042 "Move point to the head of this block; jump from end to matching begin,
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2043 from endcase to matching case, and so on."
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2044 (let (reg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2045 snest
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2046 (nest 1))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2047 (cond
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2048 ((looking-at "\\<end\\>")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2049 ;; Search back for matching begin
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2050 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2051 "\\(\\<endcase\\>\\)\\|\\(\\<join\\>\\)" )))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2052
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2053 ((looking-at "\\<endcase\\>")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2054 ;; Search back for matching case
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2055 (setq reg "\\(\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2056 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2057 ((looking-at "\\<join\\>")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2058 ;; Search back for matching fork
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2059 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\>\\)" )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2060 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2061 ((looking-at "\\<endtable\\>")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2062 ;; Search back for matching table
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2063 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2064 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2065 ((looking-at "\\<endspecify\\>")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2066 ;; Search back for matching specify
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2067 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2068 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2069 ((looking-at "\\<endfunction\\>")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2070 ;; Search back for matching function
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2071 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2072 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2073 ((looking-at "\\<endtask\\>")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2074 ;; Search back for matching task
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2075 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2076 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2077 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2078 (catch 'skip
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2079 (let (sreg)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2080 (while (verilog-re-search-backward reg nil 'move)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2081 (cond
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2082 ((match-end 1) ; begin
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2083 (setq nest (1- nest))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2084 (if (= 0 nest)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2085 ;; Now previous line describes syntax
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2086 (throw 'skip 1))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2087 (if (and snest
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2088 (= snest nest))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2089 (setq reg sreg))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2090 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2091 ((match-end 2) ; end
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2092 (setq nest (1+ nest))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2093 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2094 ((match-end 3)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2095 ;; endcase, jump to case
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2096 (setq snest nest)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2097 (setq nest (1+ nest))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2098 (setq sreg reg)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2099 (setq reg "\\(\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2100 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2101 ((match-end 4)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2102 ;; join, jump to fork
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2103 (setq snest nest)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2104 (setq nest (1+ nest))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2105 (setq sreg reg)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2106 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\>\\)" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2107 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2108 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2109 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2110 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2111 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2112 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2113 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2114
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2115 (defun verilog-continued-line-1 ()
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2116 "Return true if this is a continued line.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2117 Set point to where line starts"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2118 (let ((continued 't))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2119 (if (eq 0 (forward-line -1))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2120 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2121 (end-of-line)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2122 (verilog-backward-ws&directives)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2123 (if (bobp)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2124 (setq continued nil)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2125 (setq continued (verilog-backward-token))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2126 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2127 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2128 (setq continued nil)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2129 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2130 continued)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2131 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2132
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2133 (defun verilog-continued-line ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2134 "Return true if this is a continued line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2135 Set point to where line starts"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2136 (let ((continued 't))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2137 (if (eq 0 (forward-line -1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2138 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2139 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2140 (verilog-backward-ws&directives)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2141 (if (bobp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2142 (setq continued nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2143 (while (and continued
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2144 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2145 (skip-chars-backward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2146 (not (bolp))))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2147 (setq continued (verilog-backward-token))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2148 ) ;; while
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2149 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2150 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2151 (setq continued nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2152 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2153 continued)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2154 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2155
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2156 (defun verilog-backward-token ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2157 "step backward token, returning true if we are now at an end of line token"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2158 (verilog-backward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2159 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2160 ((bolp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2161 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2162 (;-- Anything ending in a ; is complete
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2163 (= (preceding-char) ?\;)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2164 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2165 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2166 (= (preceding-char) ?\))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2167 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2168 (backward-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2169 (backward-up-list 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2170 (verilog-backward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2171 (forward-word -1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2172 (not (looking-at "\\<case[xz]?\\>[^:]"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2173 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2174 t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2175 (forward-word -1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2176 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2177 (
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2178 (looking-at "\\(else\\)\\|\\(initial\\>\\)\\|\\(always\\>\\)")
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2179 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2180 (
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2181 (looking-at verilog-indent-reg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2182 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2183 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2184 (let
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2185 ((back (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2186 (verilog-backward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2187 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2188 ((= (preceding-char) ?\:)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2189 (backward-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2190 (verilog-backward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2191 (backward-sexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2192 (if (looking-at "begin")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2193 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2194 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2195 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2196 ((= (preceding-char) ?\#)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2197 (backward-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2198 t)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2199 ((= (preceding-char) ?\`)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2200 (backward-char)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2201 t)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2202
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2203 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2204 (goto-char back)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2205 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2206 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2207 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2208 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2209 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2210 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2211 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2212 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2213
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2214 (defun verilog-backward-syntactic-ws (&optional lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2215 ;; Backward skip over syntactic whitespace for Emacs 19.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2216 (save-restriction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2217 (let* ((lim (or lim (point-min)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2218 (here lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2219 bol
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2220 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2221 (if (< lim (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2222 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2223 (narrow-to-region lim (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2224 (while (/= here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2225 (setq here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2226 (forward-comment (-(buffer-size)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2227 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2228 (setq bol (progn (beginning-of-line) (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2229 (search-backward "//" bol t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2230 )))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2231 ))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2232 t)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2233
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2234 (defun verilog-forward-syntactic-ws (&optional lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2235 ;; forward skip over syntactic whitespace for Emacs 19.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2236 (save-restriction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2237 (let* ((lim (or lim (point-max)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2238 (here lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2239 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2240 (if (> lim (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2241 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2242 (narrow-to-region (point) lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2243 (while (/= here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2244 (setq here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2245 (forward-comment (buffer-size))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2246 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2247 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2248
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2249 (defun verilog-backward-ws&directives (&optional lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2250 ;; Backward skip over syntactic whitespace and compiler directives for Emacs 19.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2251 (save-restriction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2252 (let* ((lim (or lim (point-min)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2253 (here lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2254 jump
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2255 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2256 (if (< lim (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2257 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2258 (let ((state
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2259 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2260 (parse-partial-sexp (point-min) (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2261 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2262 ((nth 4 state) ;; in /* */ comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2263 (verilog-re-search-backward "/\*" nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2264 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2265 ((nth 7 state) ;; in // comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2266 (verilog-re-search-backward "//" nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2267 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2268 (narrow-to-region lim (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2269 (while (/= here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2270 (setq here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2271 (forward-comment (-(buffer-size)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2272 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2273 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2274 (if (looking-at "[ \t]*\\(`define\\)\\|\\(`ifdef\\)\\|\\(`else\\)\\|\\(`endif\\)\\|\\(`timescale\\)\\|\\(`include\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2275 (setq jump t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2276 (setq jump nil)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2277 (if jump
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2278 (beginning-of-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2279 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2280 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2281
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2282 (defun verilog-forward-ws&directives (&optional lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2283 ;; forward skip over syntactic whitespace and compiler directives for Emacs 19.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2284 (save-restriction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2285 (let* ((lim (or lim (point-max)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2286 (here lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2287 jump
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2288 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2289 (if (> lim (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2290 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2291 (let ((state
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2292 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2293 (parse-partial-sexp (point-min) (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2294 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2295 ((nth 4 state) ;; in /* */ comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2296 (verilog-re-search-forward "/\*" nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2297 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2298 ((nth 7 state) ;; in // comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2299 (verilog-re-search-forward "//" nil 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2300 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2301 (narrow-to-region (point) lim)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2302 (while (/= here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2303 (setq here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2304 (forward-comment (buffer-size))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2305 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2306 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2307 (if (looking-at "[ \t]*\\(`define\\)\\|\\(`ifdef\\)\\|\\(`else\\)\\|\\(`endif\\)\\|\\(`timescale\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2308 (setq jump t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2309 (if jump
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2310 (beginning-of-line 2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2311 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2312 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2313 (defun verilog-parenthesis-depth ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2314 "Return non zero if in parenthetical-expression"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2315 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2316 (car (parse-partial-sexp (point-min) (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2317
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2318 (defun verilog-in-comment-or-string-p ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2319 "Return true if in a string or comment"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2320 (let ((state
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2321 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2322 (parse-partial-sexp (point-min) (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2323 (or (nth 3 state) (nth 4 state) (nth 7 state))) ; Inside string or comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2324 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2325
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2326 (defun verilog-in-star-comment-p ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2327 "Return true if in a star comment"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2328 (let ((state
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2329 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2330 (parse-partial-sexp (point-min) (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2331 (nth 4 state))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2332 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2333
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2334 (defun verilog-in-paren ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2335 "Return true if in a parenthetical expression"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2336 (let ((state
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2337 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2338 (parse-partial-sexp (point-min) (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2339 (/= 0 (nth 0 state)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2340 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2341
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2342 (defun verilog-skip-forward-comment-or-string ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2343 "Return true if in a string or comment"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2344 (let ((state
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2345 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2346 (parse-partial-sexp (point-min) (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2347 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2348 ((nth 3 state) ;Inside string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2349 (goto-char (nth 3 state))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2350 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2351 ((nth 7 state) ;Inside // comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2352 (forward-line 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2353 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2354 ((nth 4 state) ;Inside any comment (hence /**/)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2355 (search-forward "*/"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2356 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2357 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2358 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2359 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2360 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2361
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2362 (defun verilog-skip-backward-comment-or-string ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2363 "Return true if in a string or comment"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2364 (let ((state
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2365 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2366 (parse-partial-sexp (point-min) (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2367 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2368 ((nth 3 state) ;Inside string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2369 (search-backward "\"")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2370 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2371 ((nth 7 state) ;Inside // comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2372 (search-backward "//")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2373 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2374 ((nth 4 state) ;Inside /* */ comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2375 (search-backward "/*")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2376 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2377 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2378 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2379 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2380 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2381 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2382
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2383 (defun verilog-skip-forward-comment-p ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2384 "If in comment, move to end and return true"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2385 (let (state)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2386 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2387 (setq state
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2388 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2389 (parse-partial-sexp (point-min) (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2390 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2391 ((nth 3 state)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2392 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2393 ((nth 7 state) ;Inside // comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2394 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2395 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2396 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2397 ((nth 4 state) ;Inside any comment
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2398 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2399 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2400 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2401 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2402 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2403 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2404 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2405
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2406 (defun verilog-indent-line-relative ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2407 "Cheap version of indent line that only looks at
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2408 a few lines to determine indent level"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2409 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2410 (let ((indent-str))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2411 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2412 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2413 (if (looking-at "^[ \t]*$")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2414 (cond ;- A blank line; No need to be too smart.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2415 ((bobp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2416 (setq indent-str (list 'cpp 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2417 ((verilog-continued-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2418 (let ((sp (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2419 (if (verilog-continued-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2420 (progn (goto-char sp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2421 (setq indent-str (list 'statement (verilog-indent-level))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2422 (goto-char sp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2423 (setq indent-str (list 'block (verilog-indent-level))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2424 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2425 (setq indent-str (verilog-calculate-indent))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2426 (setq indent-str (verilog-calculate-indent))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2427 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2428 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2429 (verilog-do-indent indent-str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2430 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2431 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2432 (defun verilog-indent-line ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2433 "Indent for special part of code."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2434 (if (looking-at verilog-directive-re)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2435 ;; We could nicely nest `ifdef's, but...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2436 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2437 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2438 (indent-to 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2439 (list 'cpp 0)) ; Return verilog-calculate-indent data
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2440 (verilog-do-indent (verilog-calculate-indent)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2441 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2442
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2443 (defun verilog-do-indent (indent-str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2444 ""
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2445 (let ((type (car indent-str))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2446 (ind (car (cdr indent-str))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2447 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2448 (cond
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2449 (; handle continued exp
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2450 (eq type 'cexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2451 (let ((here (point)))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2452 (verilog-backward-syntactic-ws)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2453 (cond
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2454 ((= (preceding-char) ?\,)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2455 (let* ( fst
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2456 (column
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2457 (save-excursion
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2458 (backward-char 1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2459 (verilog-beg-of-statement)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2460 (setq fst (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2461 (if (looking-at verilog-declaration-re)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2462 (progn ;; we have multiple words
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2463 (goto-char (match-end 0))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2464 (skip-chars-forward " \t")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2465 (if (= (following-char) ?\[)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2466 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2467 (forward-char 1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2468 (backward-up-list -1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2469 (skip-chars-forward " \t")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2470 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2471 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2472 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2473 (;; we have a single word
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2474 goto-char fst)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2475 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2476 (current-column)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2477 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2478 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2479 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2480 (goto-char here)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2481 (beginning-of-line)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2482 (delete-horizontal-space)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2483 (indent-to column))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2484 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2485 ((= (preceding-char) ?\) )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2486 (goto-char here)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2487 (indent-to (eval (cdr (assoc type verilog-indent-alist))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2488 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2489 (t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2490 (goto-char here)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2491 (let ((val))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2492 (verilog-beg-of-statement)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2493 (if (verilog-re-search-forward "=[ \\t]*" here 'move)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2494 (setq val (current-column))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2495 (setq val (eval (cdr (assoc type verilog-indent-alist)))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2496 (goto-char here)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2497 (indent-to val)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2498 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2499 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2500 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2501 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2502 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2503 (; handle inside parenthetical expressions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2504 (eq type 'cparenexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2505 (let ((column (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2506 (backward-up-list 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2507 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2508 (skip-chars-forward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2509 (current-column))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2510 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2511 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2512 (indent-to column)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2513
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2514 (;-- Handle the ends
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2515 (looking-at verilog-end-block-re )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2516 (if (eq type 'statement)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2517 (indent-to (- ind verilog-indent-level))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2518 (indent-to ind)))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2519 (;-- Case -- maybe line 'em up
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2520 (and (eq type 'case) (not (looking-at "^[ \t]*$")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2521 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2522 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2523 ((looking-at "\\<endcase\\>")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2524 (indent-to ind))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2525 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2526 (indent-to (eval (cdr (assoc type verilog-indent-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2527 ))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2528
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2529
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2530 (;-- defun
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2531 (and (eq type 'defun)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2532 (looking-at verilog-zero-indent-re))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2533 (indent-to 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2534
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2535 (;-- declaration
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2536 (and (or
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2537 (eq type 'defun)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2538 (eq type 'block))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2539 (looking-at verilog-declaration-re))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2540 (verilog-indent-declaration ind))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2541
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2542 (;-- Everything else
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2543 t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2544 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2545 (indent-to val)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2546 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2547 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2548 (if (looking-at "[ \t]+$")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2549 (skip-chars-forward " \t"))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2550 indent-str ; Return indent data
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2551 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2552 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2553
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2554 (defun verilog-indent-level ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2555 "Return the indent-level the current statement has."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2556 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2557 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2558 (skip-chars-forward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2559 (current-column)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2560
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2561
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2562 (defun verilog-case-indent-level ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2563 "Return the indent-level the current statement has.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2564 Do not count named blocks or case-statements."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2565 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2566 (skip-chars-forward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2567 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2568 ((looking-at verilog-named-block-re)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2569 (current-column))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2570 ((and (not (looking-at verilog-case-re))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2571 (looking-at "^[^:;]+[ \t]*:"))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2572 (search-forward ":" nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2573 (skip-chars-forward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2574 (current-column))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2575 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2576 (current-column)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2577
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2578 (defun verilog-indent-comment (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2579 "Indent current line as comment.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2580 If optional arg is non-nil, just return the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2581 column number the line should be indented to."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2582 (let* ((stcol
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2583 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2584 ((verilog-in-star-comment-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2585 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2586 (re-search-backward "/\\*" nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2587 (1+(current-column))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2588 ( comment-column
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2589 comment-column )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2590 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2591 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2592 (re-search-backward "//" nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2593 (current-column)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2594 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2595 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2596 (if arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2597 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2598 (delete-horizontal-space)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2599 (indent-to stcol))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2600 stcol
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2601 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2602 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2603 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2604
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2605 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2606
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2607 (defun verilog-pretty-declarations ()
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2608 "Line up declarations arround point"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2609 (interactive)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2610 (save-excursion
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2611 (if (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2612 (verilog-beg-of-statement-1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2613 (looking-at verilog-declaration-re))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2614 (let* ((m1 (make-marker))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2615 (e) (r)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2616 (here (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2617 (start
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2618 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2619 (verilog-beg-of-statement-1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2620 (while (looking-at verilog-declaration-re)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2621 (beginning-of-line)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2622 (setq e (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2623 (verilog-backward-syntactic-ws)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2624 (backward-char)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2625 (verilog-beg-of-statement-1))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2626 e))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2627 (end
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2628 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2629 (goto-char here)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2630 (verilog-end-of-statement)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2631 (setq e (point)) ;Might be on last line
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2632 (verilog-forward-syntactic-ws)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2633 (while (looking-at verilog-declaration-re)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2634 (beginning-of-line)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2635 (verilog-end-of-statement)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2636 (setq e (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2637 (verilog-forward-syntactic-ws)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2638 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2639 e))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2640 (edpos (set-marker (make-marker) end))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2641 (ind)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2642 (base-ind
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2643 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2644 (goto-char start)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2645 (verilog-do-indent (verilog-calculate-indent))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2646 (verilog-forward-ws&directives)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2647 (current-column)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2648 ))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2649 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2650 (goto-char end)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2651 (goto-char start)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2652 (if (> (- end start) 100)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2653 (message "Lining up declarations..(please stand by)"))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2654 ;; Get the begining of line indent first
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2655 (while (progn (setq e (marker-position edpos))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2656 (< (point) e))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2657 (delete-horizontal-space)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2658 (indent-to base-ind)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2659 (forward-line))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2660 ;; Now find biggest prefix
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2661 (setq ind (verilog-get-lineup-indent start edpos))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2662 ;; Now indent each line.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2663 (goto-char start)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2664 (while (progn (setq e (marker-position edpos))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2665 (setq r (- e (point)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2666 (> r 0))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2667 (setq e (point))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2668 (message "%d" r)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2669 (cond
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2670 ((looking-at verilog-declaration-re-1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2671 (let ((p (match-end 0)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2672 (set-marker m1 p)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2673 (if (verilog-re-search-forward "\\[" p 'move)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2674 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2675 (forward-char -1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2676 (just-one-space)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2677 (goto-char (marker-position m1))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2678 (just-one-space)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2679 (indent-to ind)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2680 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2681 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2682 (just-one-space)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2683 (indent-to ind))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2684 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2685 ))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2686 ((verilog-continued-line-1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2687 (goto-char e)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2688 (delete-horizontal-space)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2689 (indent-to ind))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2690 (t ; Must be comment or white space
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2691 (goto-char e)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2692 (verilog-forward-ws&directives)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2693 (forward-line -1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2694 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2695 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2696 (forward-line 1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2697 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2698 (message "")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2699 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2700 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2701 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2702 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2703 (defun verilog-indent-declaration (baseind)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2704 "Indent current lines as declaration, lining up the variable names
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2705 based on previous declaration's indentation."
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2706 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2707 (let ((pos (point-marker))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2708 (lim (save-excursion
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2709 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil 'move)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2710 (point)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2711 (ind)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2712 (m1 (make-marker))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2713 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2714 ;; Use previous declaration (in this module) as template.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2715 (if (verilog-re-search-backward verilog-declaration-re-1 lim t)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2716 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2717 (goto-char (match-end 0))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2718 (setq ind (current-column))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2719 (goto-char pos)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2720 (beginning-of-line)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2721 (indent-to (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2722 (if (looking-at verilog-declaration-re-2)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2723 (let ((p (match-end 0)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2724 (set-marker m1 p)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2725 (if (verilog-re-search-forward "\\[" p 'move)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2726 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2727 (forward-char -1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2728 (just-one-space)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2729 (goto-char (marker-position m1))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2730 (just-one-space)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2731 (indent-to ind)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2732 )
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2733 (progn
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2734 (just-one-space)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2735 (indent-to ind)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2736 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2737 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2738 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2739 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2740 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2741 (indent-to (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2742 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2743 (goto-char pos)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2744 )
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
2745 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2746
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2747 ; "Return the indent level that will line up several lines within the region
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2748 ;from b to e nicely. The lineup string is str."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2749 (defun verilog-get-lineup-indent (b edpos)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2750 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2751 (let ((ind 0) e)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2752 (goto-char b)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2753 ;; Get rightmost position
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2754 (while (progn (setq e (marker-position edpos))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2755 (< (point) e))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2756 (if (verilog-re-search-forward verilog-declaration-re-1 e 'move)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2757 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2758 (goto-char (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2759 (verilog-backward-syntactic-ws)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2760 (if (> (current-column) ind)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2761 (setq ind (current-column)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2762 (goto-char (match-end 0)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2763 (if (> ind 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2764 (1+ ind)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2765 ;; No lineup-string found
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2766 (goto-char b)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2767 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2768 (skip-chars-backward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2769 (1+ (current-column))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2770
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2771 ;; A useful mode debugging aide
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2772 (defun verilog-comment-depth (type val)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2773 ""
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2774 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2775 (let
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2776 ((b (prog2
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2777 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2778 (point-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2779 (end-of-line)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2780 (e (point-marker)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2781 (if (re-search-backward " /\\* \[#-\]# \[a-z\]+ \[0-9\]+ ## \\*/" b t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2782 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2783 (replace-match " /* -# ## */")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2784 (end-of-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2785 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2786 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2787 (insert " /* ## ## */"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2788 (backward-char 6)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2789 (insert
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2790 (format "%s %d" type val))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2791 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2792 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2793 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2794 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2795 ;;; Completion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2796 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2797 (defvar verilog-str nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2798 (defvar verilog-all nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2799 (defvar verilog-pred nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2800 (defvar verilog-buffer-to-use nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2801 (defvar verilog-flag nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2802 (defvar verilog-toggle-completions nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2803 "*Non-nil means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2804 Repeated use of \\[verilog-complete-word] will show you all of them.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2805 Normally, when there is more than one possible completion,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2806 it displays a list of all possible completions.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2807
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2808
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2809 (defvar verilog-type-keywords
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2810 '("buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2811 "integer" "nand" "nmos" "nor" "not" "notif0" "notif1" "or" "output" "parameter"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2812 "pmos" "pull0" "pull1" "pullup" "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2813 "rtranif0" "rtranif1" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2814 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor" )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2815 "*Keywords for types used when completing a word in a declaration or parmlist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2816 \(eg. integer, real, char.) The types defined within the Verilog program
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2817 will be completed runtime, and should not be added to this list.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2818
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2819 (defvar verilog-defun-keywords
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2820 '("begin" "function" "task" "initial" "always" "assign" "posedge" "negedge" "endmodule")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2821 "*Keywords to complete when standing at first word of a line in declarative scope.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2822 \(eg. initial, always, begin, assign.)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2823 The procedures and variables defined within the Verilog program
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2824 will be completed runtime and should not be added to this list.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2825
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2826 (defvar verilog-block-keywords
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2827 '("begin" "fork" "join" "case" "end" "if" "else" "for" "while" "repeat")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2828 "*Keywords to complete when standing at first word of a line in behavorial scope.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2829 \(eg. begin, if, then, else, for, fork.)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2830 The procedures and variables defined within the Verilog program
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2831 will be completed runtime and should not be added to this list.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2832
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2833 (defvar verilog-tf-keywords
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2834 '("begin" "fork" "join" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2835 "*Keywords to complete when standing at first word of a line in a task or function scope.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2836 \(eg. begin, if, then, else, for, fork.)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2837 The procedures and variables defined within the Verilog program
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2838 will be completed runtime and should not be added to this list.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2839
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2840 (defvar verilog-case-keywords
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2841 '("begin" "fork" "join" "case" "end" "endcase" "if" "else" "for" "repeat")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2842 "*Keywords to complete when standing at first word of a line in behavorial scope.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2843 \(eg. begin, if, then, else, for, fork.)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2844 The procedures and variables defined within the Verilog program
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2845 will be completed runtime and should not be added to this list.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2846
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2847 (defvar verilog-separator-keywords
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2848 '("else" "then" "begin")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2849 "*Keywords to complete when NOT standing at the first word of a statement.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2850 \(eg. else, then.)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2851 Variables and function names defined within the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2852 Verilog program are completed runtime and should not be added to this list.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2853
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2854 (defun verilog-string-diff (str1 str2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2855 "Return index of first letter where STR1 and STR2 differs."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2856 (catch 'done
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2857 (let ((diff 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2858 (while t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2859 (if (or (> (1+ diff) (length str1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2860 (> (1+ diff) (length str2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2861 (throw 'done diff))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2862 (or (equal (aref str1 diff) (aref str2 diff))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2863 (throw 'done diff))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2864 (setq diff (1+ diff))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2865
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2866 ;; Calculate all possible completions for functions if argument is `function',
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2867 ;; completions for procedures if argument is `procedure' or both functions and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2868 ;; procedures otherwise.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2869
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2870 (defun verilog-func-completion (type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2871 ;; Build regular expression for module/task/function names
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2872 (if (string= verilog-str "")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2873 (setq verilog-str "[a-zA-Z_]"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2874 (let ((verilog-str (concat (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2875 ((eq type 'module) "\\<\\(module\\)\\s +")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2876 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2877 (t "\\<\\(task\\|function\\|module\\)\\s +"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2878 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2879 match)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2880
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2881 (if (not (looking-at verilog-defun-re))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2882 (verilog-re-search-backward verilog-defun-re nil t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2883 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2884
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2885 ;; Search through all reachable functions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2886 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2887 (while (verilog-re-search-forward verilog-str (point-max) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2888 (progn (setq match (buffer-substring (match-beginning 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2889 (match-end 2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2890 (if (or (null verilog-pred)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2891 (funcall verilog-pred match))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2892 (setq verilog-all (cons match verilog-all)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2893 (if (match-beginning 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2894 (goto-char (match-beginning 0)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2895
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2896 (defun verilog-get-completion-decl ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2897 ;; Macro for searching through current declaration (var, type or const)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2898 ;; for matches of `str' and adding the occurence tp `all'
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2899 (let ((end (save-excursion (verilog-declaration-end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2900 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2901 match)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2902 ;; Traverse lines
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2903 (while (< (point) end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2904 (if (verilog-re-search-forward verilog-declaration-re-1 (verilog-get-end-of-line) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2905 ;; Traverse current line
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2906 (while (and (verilog-re-search-forward
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2907 (concat "\\((\\|\\<\\(var\\|type\\|const\\)\\>\\)\\|"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2908 verilog-symbol-re)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2909 (verilog-get-beg-of-line) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2910 (not (match-end 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2911 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2912 (if (string-match (concat "\\<" verilog-str) match)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2913 (if (or (null verilog-pred)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2914 (funcall verilog-pred match))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2915 (setq verilog-all (cons match verilog-all))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2916 (if (verilog-re-search-forward "\\<record\\>" (verilog-get-end-of-line) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2917 (verilog-declaration-end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2918 (forward-line 1)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2919
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2920 (defun verilog-type-completion ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2921 "Calculate all possible completions for types."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2922 (let ((start (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2923 goon)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2924 ;; Search for all reachable type declarations
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2925 (while (or (verilog-beg-of-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2926 (setq goon (not goon)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2927 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2928 (if (and (< start (prog1 (save-excursion (verilog-end-of-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2929 (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2930 (forward-char 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2931 (verilog-re-search-forward
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2932 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2933 start t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2934 (not (match-end 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2935 ;; Check current type declaration
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2936 (verilog-get-completion-decl))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2937
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2938 (defun verilog-var-completion ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2939 "Calculate all possible completions for variables (or constants)."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2940 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2941 ; Not done yet; in 1.99 perhaps
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2942 ; (let ((start (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2943 ; goon twice)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2944 ; ;; Search for all reachable var declarations
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2945 ; (while (or (verilog-beg-of-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2946 ; (setq goon (not goon)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2947 ; (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2948 ; (if (> start (prog1 (save-excursion (verilog-end-of-defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2949 ; (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2950 ; () ; Declarations not reacable
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2951 ; (cond ((and (verilog-re-search-forward verilog-declaration-re start t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2952 ; ;; Check var/const declarations
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2953 ; (verilog-get-completion-decl)))))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2954
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2955
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2956 (defun verilog-keyword-completion (keyword-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2957 "Give list of all possible completions of keywords in KEYWORD-LIST."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2958 (mapcar '(lambda (s)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2959 (if (string-match (concat "\\<" verilog-str) s)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2960 (if (or (null verilog-pred)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2961 (funcall verilog-pred s))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2962 (setq verilog-all (cons s verilog-all)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2963 keyword-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2964
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2965 ;; Function passed to completing-read, try-completion or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2966 ;; all-completions to get completion on STR. If predicate is non-nil,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2967 ;; it must be a function to be called for every match to check if this
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2968 ;; should really be a match. If flag is t, the function returns a list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2969 ;; of all possible completions. If it is nil it returns a string, the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2970 ;; longest possible completion, or t if STR is an exact match. If flag
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2971 ;; is 'lambda, the function returns t if STR is an exact match, nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2972 ;; otherwise.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2973
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2974 (defun verilog-completion (verilog-str verilog-pred verilog-flag)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2975 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2976 (let ((verilog-all nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2977 ;; Set buffer to use for searching labels. This should be set
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2978 ;; within functins which use verilog-completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2979 (set-buffer verilog-buffer-to-use)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2980
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2981 ;; Determine what should be completed
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2982 (let ((state (car (verilog-calculate-indent))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2983 (cond ((eq state 'defun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2984 (save-excursion (verilog-var-completion))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2985 (verilog-func-completion 'module)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2986 (verilog-keyword-completion verilog-defun-keywords))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2987
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2988 ((eq state 'block)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2989 (save-excursion (verilog-var-completion))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2990 (verilog-func-completion 'tf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2991 (verilog-keyword-completion verilog-block-keywords))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2992
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2993 ((eq state 'case)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2994 (save-excursion (verilog-var-completion))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2995 (verilog-func-completion 'tf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2996 (verilog-keyword-completion verilog-case-keywords))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2997
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2998 ((eq state 'tf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2999 (save-excursion (verilog-var-completion))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3000 (verilog-func-completion 'tf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3001 (verilog-keyword-completion verilog-tf-keywords))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3002
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3003 (t;--Anywhere else
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3004 (save-excursion (verilog-var-completion))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3005 (verilog-func-completion 'both)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3006 (verilog-keyword-completion verilog-separator-keywords))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3007
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3008 ;; Now we have built a list of all matches. Give response to caller
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3009 (verilog-completion-response))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3010
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3011 (defun verilog-completion-response ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3012 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3013 ;; This was not called by all-completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3014 (if (null verilog-all)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3015 ;; Return nil if there was no matching label
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3016 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3017 ;; Get longest string common in the labels
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3018 (let* ((elm (cdr verilog-all))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3019 (match (car verilog-all))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3020 (min (length match))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3021 tmp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3022 (if (string= match verilog-str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3023 ;; Return t if first match was an exact match
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3024 (setq match t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3025 (while (not (null elm))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3026 ;; Find longest common string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3027 (if (< (setq tmp (verilog-string-diff match (car elm))) min)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3028 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3029 (setq min tmp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3030 (setq match (substring match 0 min))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3031 ;; Terminate with match=t if this is an exact match
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3032 (if (string= (car elm) verilog-str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3033 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3034 (setq match t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3035 (setq elm nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3036 (setq elm (cdr elm)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3037 ;; If this is a test just for exact match, return nil ot t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3038 (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3039 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3040 match))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3041 ;; If flag is t, this was called by all-completions. Return
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3042 ;; list of all possible completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3043 (verilog-flag
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3044 verilog-all)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3045
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3046 (defvar verilog-last-word-numb 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3047 (defvar verilog-last-word-shown nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3048 (defvar verilog-last-completions nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3049
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3050 (defun verilog-complete-word ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3051 "Complete word at current point.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3052 \(See also `verilog-toggle-completions', `verilog-type-keywords',
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3053 `verilog-start-keywords' and `verilog-separator-keywords'.)"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3054 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3055 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3056 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3057 (verilog-str (buffer-substring b e))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3058 ;; The following variable is used in verilog-completion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3059 (verilog-buffer-to-use (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3060 (allcomp (if (and verilog-toggle-completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3061 (string= verilog-last-word-shown verilog-str))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3062 verilog-last-completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3063 (all-completions verilog-str 'verilog-completion)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3064 (match (if verilog-toggle-completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3065 "" (try-completion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3066 verilog-str (mapcar '(lambda (elm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3067 (cons elm 0)) allcomp)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3068 ;; Delete old string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3069 (delete-region b e)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3070
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3071 ;; Toggle-completions inserts whole labels
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3072 (if verilog-toggle-completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3073 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3074 ;; Update entry number in list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3075 (setq verilog-last-completions allcomp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3076 verilog-last-word-numb
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3077 (if (>= verilog-last-word-numb (1- (length allcomp)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3078 0
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3079 (1+ verilog-last-word-numb)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3080 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3081 ;; Display next match or same string if no match was found
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3082 (if (not (null allcomp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3083 (insert "" verilog-last-word-shown)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3084 (insert "" verilog-str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3085 (message "(No match)")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3086 ;; The other form of completion does not necessarly do that.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3087
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3088 ;; Insert match if found, or the original string if no match
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3089 (if (or (null match) (equal match 't))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3090 (progn (insert "" verilog-str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3091 (message "(No match)"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3092 (insert "" match))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3093 ;; Give message about current status of completion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3094 (cond ((equal match 't)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3095 (if (not (null (cdr allcomp)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3096 (message "(Complete but not unique)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3097 (message "(Sole completion)")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3098 ;; Display buffer if the current completion didn't help
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3099 ;; on completing the label.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3100 ((and (not (null (cdr allcomp))) (= (length verilog-str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3101 (length match)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3102 (with-output-to-temp-buffer "*Completions*"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3103 (display-completion-list allcomp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3104 ;; Wait for a keypress. Then delete *Completion* window
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3105 (momentary-string-display "" (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3106 (delete-window (get-buffer-window (get-buffer "*Completions*")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3107 )))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3108
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3109 (defun verilog-show-completions ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3110 "Show all possible completions at current point."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3111 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3112 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3113 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3114 (verilog-str (buffer-substring b e))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3115 ;; The following variable is used in verilog-completion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3116 (verilog-buffer-to-use (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3117 (allcomp (if (and verilog-toggle-completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3118 (string= verilog-last-word-shown verilog-str))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3119 verilog-last-completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3120 (all-completions verilog-str 'verilog-completion))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3121 ;; Show possible completions in a temporary buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3122 (with-output-to-temp-buffer "*Completions*"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3123 (display-completion-list allcomp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3124 ;; Wait for a keypress. Then delete *Completion* window
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3125 (momentary-string-display "" (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3126 (delete-window (get-buffer-window (get-buffer "*Completions*")))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3127
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3128
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3129 (defun verilog-get-default-symbol ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3130 "Return symbol around current point as a string."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3131 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3132 (buffer-substring (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3133 (skip-chars-backward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3134 (skip-chars-backward "a-zA-Z0-9_")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3135 (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3136 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3137 (skip-chars-forward "a-zA-Z0-9_")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3138 (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3139
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3140 (defun verilog-build-defun-re (str &optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3141 "Return function/task/module starting with STR as regular expression.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3142 With optional second arg non-nil, STR is the complete name of the instruction."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3143 (if arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3144 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3145 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3146
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3147 ;; Function passed to completing-read, try-completion or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3148 ;; all-completions to get completion on any function name. If
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3149 ;; predicate is non-nil, it must be a function to be called for every
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3150 ;; match to check if this should really be a match. If flag is t, the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3151 ;; function returns a list of all possible completions. If it is nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3152 ;; it returns a string, the longest possible completion, or t if STR
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3153 ;; is an exact match. If flag is 'lambda, the function returns t if
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3154 ;; STR is an exact match, nil otherwise.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3155
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3156 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3157 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3158 (let ((verilog-all nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3159 match)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3160
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3161 ;; Set buffer to use for searching labels. This should be set
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3162 ;; within functins which use verilog-completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3163 (set-buffer verilog-buffer-to-use)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3164
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3165 (let ((verilog-str verilog-str))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3166 ;; Build regular expression for functions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3167 (if (string= verilog-str "")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3168 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3169 (setq verilog-str (verilog-build-defun-re verilog-str)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3170 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3171
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3172 ;; Build a list of all possible completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3173 (while (verilog-re-search-forward verilog-str nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3174 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3175 (if (or (null verilog-pred)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3176 (funcall verilog-pred match))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3177 (setq verilog-all (cons match verilog-all)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3178
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3179 ;; Now we have built a list of all matches. Give response to caller
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3180 (verilog-completion-response))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3181
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3182 (defun verilog-goto-defun ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3183 "Move to specified Verilog module/task/function.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3184 The default is a name found in the buffer around point."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3185 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3186 (let* ((default (verilog-get-default-symbol))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3187 ;; The following variable is used in verilog-comp-function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3188 (verilog-buffer-to-use (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3189 (default (if (verilog-comp-defun default nil 'lambda)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3190 default ""))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3191 (label (if (not (string= default ""))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3192 ;; Do completion with default
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3193 (completing-read (concat "Label: (default " default ") ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3194 'verilog-comp-defun nil t "")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3195 ;; There is no default value. Complete without it
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3196 (completing-read "Label: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3197 'verilog-comp-defun nil t ""))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3198 ;; If there was no response on prompt, use default value
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3199 (if (string= label "")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3200 (setq label default))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3201 ;; Goto right place in buffer if label is not an empty string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3202 (or (string= label "")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3203 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3204 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3205 (re-search-forward (verilog-build-defun-re label t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3206 (beginning-of-line)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3207 (defun verilog-showscopes ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3208 "list all scopes in this module"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3209 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3210 (let (
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3211 (buffer (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3212 (linenum 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3213 (nlines 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3214 (first 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3215 (prevpos (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3216 (final-context-start (make-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3217 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3218 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3219 (with-output-to-temp-buffer "*Occur*"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3220 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3221 (message (format "Searching for %s ..." regexp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3222 ;; Find next match, but give up if prev match was at end of buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3223 (while (and (not (= prevpos (point-max)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3224 (verilog-re-search-forward regexp nil t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3225 (goto-char (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3226 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3227 (save-match-data
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3228 (setq linenum (+ linenum (count-lines prevpos (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3229 (setq prevpos (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3230 (goto-char (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3231 (let* ((start (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3232 (goto-char (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3233 (forward-line (if (< nlines 0) nlines (- nlines)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3234 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3235 (end (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3236 (goto-char (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3237 (if (> nlines 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3238 (forward-line (1+ nlines))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3239 (forward-line 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3240 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3241 (tag (format "%3d" linenum))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3242 (empty (make-string (length tag) ?\ ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3243 tem)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3244 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3245 (setq tem (make-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3246 (set-marker tem (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3247 (set-buffer standard-output)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3248 (setq occur-pos-list (cons tem occur-pos-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3249 (or first (zerop nlines)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3250 (insert "--------\n"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3251 (setq first nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3252 (insert-buffer-substring buffer start end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3253 (backward-char (- end start))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3254 (setq tem (if (< nlines 0) (- nlines) nlines))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3255 (while (> tem 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3256 (insert empty ?:)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3257 (forward-line 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3258 (setq tem (1- tem)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3259 (let ((this-linenum linenum))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3260 (set-marker final-context-start
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3261 (+ (point) (- (match-end 0) (match-beginning 0))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3262 (while (< (point) final-context-start)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3263 (if (null tag)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3264 (setq tag (format "%3d" this-linenum)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3265 (insert tag ?:)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3266 (set-buffer-modified-p nil))))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3267
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3268 (defun verilog-submit-bug-report ()
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3269 "Submit via mail a bug report on lazy-lock.el."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3270 (interactive)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3271 (let ((reporter-prompt-for-summary-p t))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3272 (reporter-submit-bug-report
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3273 "verilog-mode-bugs@silicon-sorcery.com"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3274 (concat "verilog-mode v" (substring verilog-mode-version 12 -3))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3275 '(verilog-indent-level
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3276 verilog-indent-level-module
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3277 verilog-indent-level-declaration
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3278 verilog-indent-level-behavorial
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3279 verilog-case-indent
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3280 verilog-auto-newline
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3281 verilog-auto-indent-on-newline
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3282 verilog-tab-always-indent
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3283 verilog-auto-endcomments
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3284 verilog-minimum-comment-distance
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3285 verilog-indent-begin-after-if
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3286 verilog-auto-lineup)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3287 nil nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3288 (concat "Hi Mac,
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3289
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3290 I want to report a bug. I've read the `Bugs' section of `Info' on
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3291 Emacs, so I know how to make a clear and unambiguous report. To get
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3292 to that Info section, I typed
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3293
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3294 M-x info RET m " invocation-name " RET m bugs RET
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3295
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3296 Before I go further, I want to say that Verilog mode has changed my life.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3297 I save so much time, my files are colored nicely, my co workers respect
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3298 my coding ability... until now. I'd really appreciate anything you
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3299 could do to help me out with this minor deficiency in the product.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3300
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3301 To reproduce the bug, start a fresh Emacs via " invocation-name "
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3302 -no-init-file -no-site-file'. In a new buffer, in verilog mode, type
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3303 the code included below.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3304
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3305 Given those lines, I expected [[Fill in here]] to happen;
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3306 but instead, [[Fill in here]] happens!.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3307
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3308 == The code: =="))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
3309
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3310 ;;; verilog.el ends here