annotate lisp/modes/verilog-mode.el @ 161:28f395d8dc7a r20-3b7

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