Emacs VHDL editing mode (vhdl-mode.el version 2.71) 
Author Message
 Emacs VHDL editing mode (vhdl-mode.el version 2.71)

Here is the latest version of my VHDL editing mode for emacs.  There
are two distribution lists available that allow you to automatically
receive updates to vhdl-mode - see the file header for details.

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#

# Source directory was `/usr/local/lib/xemacs/site-lisp/vhdl-mode'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#  91988 -r--r--r-- vhdl-mode.el
#  46573 -r--r--r-- vhdl-mode.texi
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  echo 'WARNING: not restoring timestamps.  Consider getting and'
  echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
# ============= vhdl-mode.el ==============
if test -f 'vhdl-mode.el' && test X"$1" != X"-c"; then
  echo 'x - skipping vhdl-mode.el (file already exists)'
else
  echo 'x - extracting vhdl-mode.el (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'vhdl-mode.el' &&
;;; vhdl-mode.el --- major mode for editing VHDL code
X
;; Copyright (C) 1994, 1995 Rodney J. Whitby
;; Copyright (C) 1992, 1993, 1994 Barry A. Warsaw
;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
X


;; Created:       June 1994, adapted from cc-mode.el 4.29 by Barry A. Warsaw.
;; Version:       $Revision: 2.71 $
;; Last Modified: $Date: 1995/09/28 07:32:40 $
;; Keywords:      languages VHDL
X
;; NOTE: Read the commentary below for the right way to submit bug reports!
X
;; This file is not yet part of GNU Emacs.
X
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
X
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
X
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
X
;;; Commentary:
X
;; This package provides indentation support for VHDL code.
X
;; Details on VHDL-MODE are  now contained in an  accompanying texinfo
;; manual (vhdl-mode.texi).
X
;; To submit bug reports, hit "C-c C-b", and please try to include a
;; code sample so I can reproduce your problem.  If you have other
;; questions contact me at the address listed at the top of this file.
X
;; YOU CAN IGNORE ALL BYTE-COMPILER WARNINGS. They are the result of
;; the multi-Emacsen support. FSF Emacs 19 and XEmacs 19 (formerly
;; Lucid) do things differently and there's no way to shut the
;; byte-compiler up at the necessary granularity.  Let me say this
;; again: YOU CAN IGNORE ALL BYTE-COMPILER WARNINGS (you'd be
;; surprised at how many people don't follow this advice :-).
X
;; To use VHDL-MODE, add the following to your .emacs file.  This
;; assumes you will use .vhd extensions for your VHDL source:
;;
;; (autoload 'vhdl-mode   "vhdl-mode" "VHDL Editing Mode" t)
;; (setq auto-mode-alist
;;   (append '(("\\.vhd$"  . vhdl-mode)   ; to edit VHDL code
;;            ) auto-mode-alist))
;;
;; If you would like to join the `vhdl-mode-announce' announcements
;; list or the `vhdl-mode-victims' beta testers list, send add/drop
;; requests to the address listed at the top of this file.
;;
;; Many, many thanks go out to all the folks on the beta test list.
;; Without their patience, testing, insight, and code contributions,
;; and encouragement vhdl-mode.el would be a far inferior package.
X
;; LCD Archive Entry:

;; |Major mode for editing VHDL code
;; |$Date: 1995/09/28 07:32:40 $|$Revision: 2.71 $|
X
X
;;; Code:
X
;; user definable variables
;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
X
(defvar vhdl-inhibit-startup-warnings-p nil
X  "*If non-nil, inhibits start up compatibility warnings.")
(defvar vhdl-strict-syntax-p nil
X  "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
If the syntactic symbol for a particular line does not match a symbol
in the offsets alist, an error is generated, otherwise no error is
reported and the syntactic symbol is ignored.")
(defvar vhdl-echo-syntactic-information-p nil
X  "*If non-nil, syntactic info is echoed when the line is indented.")
(defvar vhdl-basic-offset 2
X  "*Amount of basic offset used by + and - symbols in `vhdl-offsets-alist'.")
X
(defconst vhdl-offsets-alist-default
X  '((string                . -1000)
X    (block-open            . 0)
X    (block-close           . 0)
X    (statement             . 0)
X    (statement-cont        . vhdl-lineup-statement-cont)
X    (statement-block-intro . +)
X    (statement-case-intro  . +)
X    (case-alternative      . +)
X    (comment               . vhdl-lineup-comment)
X    (arglist-intro         . vhdl-lineup-arglist-intro)
X    (arglist-cont          . 0)
X    (arglist-cont-nonempty . vhdl-lineup-arglist)
X    (arglist-close         . vhdl-lineup-arglist)
X    (entity                . 0)
X    (configuration         . 0)
X    (package               . 0)
X    (architecture          . 0)
X    (package-body          . 0)
X    )
X  "Default settings for offsets of syntactic elements.
Do not change this constant!  See the variable `vhdl-offsets-alist' for
more information.")
X
(defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
X  "*Association list of syntactic element symbols and indentation offsets.
As described below, each cons cell in this list has the form:
X
X    (SYNTACTIC-SYMBOL . OFFSET)
X
When a line is indented, vhdl-mode first determines the syntactic
context of the line by generating a list of symbols called syntactic
elements.  This list can contain more than one syntactic element and
the global variable `vhdl-syntactic-context' contains the context list
for the line being indented.  Each element in this list is actually a
cons cell of the syntactic symbol and a buffer position.  This buffer
position is call the relative indent point for the line.  Some
syntactic symbols may not have a relative indent point associated with
them.
X
After the syntactic context list for a line is generated, vhdl-mode
calculates the absolute indentation for the line by looking at each
syntactic element in the list.  First, it compares the syntactic
element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'.  When it
finds a match, it adds the OFFSET to the column of the relative indent
point.  The sum of this calculation for each element in the syntactic
list is the absolute offset for line being indented.
X
If the syntactic element does not match any in the `vhdl-offsets-alist',
an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
the element is ignored.
X
Actually, OFFSET can be an integer, a function, a variable, or one of
the following symbols: `+', `-', `++', or `--'.  These latter
designate positive or negative multiples of `vhdl-basic-offset',
respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
called with a single argument containing the cons of the syntactic
element symbol and the relative indent point.  The function should
return an integer offset.
X
Here is the current list of valid syntactic element symbols:
X
X string                 -- inside multi-line string
X block-open             -- statement block open
X block-close            -- statement block close
X statement              -- a VHDL statement
X statement-cont         -- a continuation of a VHDL statement
X statement-block-intro  -- the first line in a new statement block
X statement-case-intro   -- the first line in a case alternative block
X case-alternative       -- a case statement alternative clause
X comment                -- a line containing only a comment
X arglist-intro          -- the first line in an argument list
X arglist-cont           -- subsequent argument list lines when no
X                           arguments follow on the same line as the
X                           the arglist opening paren
X arglist-cont-nonempty  -- subsequent argument list lines when at
X                           least one argument follows on the same
X                           line as the arglist opening paren
X arglist-close          -- the solo close paren of an argument list
X entity                 -- inside an entity declaration
X configuration          -- inside a configuration declaration
X package                -- inside a package declaration
X architecture           -- inside an architecture body
X package-body           -- inside a package body
")
X
(defvar vhdl-tab-always-indent t
X  "*Controls the operation of the TAB key.
If t, hitting TAB always just indents the current line.  If nil,
hitting TAB indents the current line if point is at the left margin or
in the line's indentation, otherwise it insert a real tab character.
If other than nil or t, then tab is inserted only within literals
-- defined as comments and strings -- and inside preprocessor
directives, but line is always reindented.
X
Note that indentation of lines containing only comments is also
controlled by the `vhdl-comment-only-line-offset' variable.")
X
(defvar vhdl-comment-only-line-offset 0
X  "*Extra offset for line which contains only the start of a comment.
Can contain an integer or a cons cell of the form:
X
X (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
X
Where NON-ANCHORED-OFFSET is the amount of offset given to
non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
the amount of offset to give column-zero anchored comment-only lines.
Just an integer as value is equivalent to (<val> . 0)")
X
(defvar vhdl-special-indent-hook nil
X  "*Hook for user defined special indentation adjustments.
This hook gets called after a line is indented by the mode.")
X
(defvar vhdl-style-alist
X  '(("IEEE"
X     (vhdl-basic-offset . 4)
X     (vhdl-offsets-alist . ())
X     )
X    )
X  "Styles of Indentation.
Elements of this alist are of the form:
X
X  (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
X
where STYLE-STRING is a short descriptive string used to select a
style, VARIABLE is any vhdl-mode variable, and VALUE is the intended
value for that variable when using the selected style.
X
There is one special case when VARIABLE is `vhdl-offsets-alist'.  In this
case, the VALUE is a list containing elements of the form:
X
X  (SYNTACTIC-SYMBOL . VALUE)
X
as described in `vhdl-offsets-alist'.  These are passed directly to
`vhdl-set-offset' so there is no need to set every syntactic symbol in
your style, only those that are different from the default.")
X
;; dynamically append the default value of most variables
(or (assoc "Default" vhdl-style-alist)
X    (let* ((varlist '(vhdl-inhibit-startup-warnings-p
X                     vhdl-strict-syntax-p
X                     vhdl-echo-syntactic-information-p
X                     vhdl-basic-offset
X                     vhdl-offsets-alist
X                     vhdl-tab-always-indent
X                     vhdl-comment-only-line-offset))
X          (default (cons "Default"
X                         (mapcar
X                          (function
X                           (lambda (var)
X                             (cons var (symbol-value var))
X                             ))
X                          varlist))))
X      (setq vhdl-style-alist (cons default vhdl-style-alist))))
X
(defvar vhdl-mode-hook nil
X  "*Hook called by `vhdl-mode'.")
X
(defvar vhdl-mode-menu
X  '(["Comment Out Region"     comment-region (mark)]
X    ;; ["Indent Expression"      vhdl-indent-exp
X    ;; (memq (following-char) '(?\( ?\[ ?\{))]
X    ["Indent Line"            vhdl-indent-command t]
X    ["Backward Statement"     vhdl-beginning-of-statement t]
X    ;; ["Forward Statement"      vhdl-end-of-statement t]
X    )
X  "XEmacs 19 (formerly Lucid) menu for VHDL mode.")
X
;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT
X
X
;; Emacs variant handling, and standard mode variables and functions:
X
(defconst vhdl-emacs-features
X  (let ((major (and (boundp 'emacs-major-version)
X                   emacs-major-version))
X       (minor (and (boundp 'emacs-minor-version)
X                   emacs-minor-version))
X       flavor)
X    ;; figure out version numbers if not already discovered
X    (and (or (not major) (not minor))
X        (string-match "\\([0-9]+\\).\\([0-9]+\\)" emacs-version)
X        (setq major (string-to-int (substring emacs-version
X                                              (match-beginning 1)
X                                              (match-end 1)))
X              minor (string-to-int (substring emacs-version
X                                              (match-beginning 2)
X                                              (match-end 2)))))
X    (if (not (and major minor))
X       (error "Cannot figure out the major and minor version numbers."))
X    ;; calculate the major version
X    (cond
X     ((= major 18) (setq major 'v18))  ;Emacs 18
X     ((= major 4)  (setq major 'v18))  ;Epoch 4
X     ((= major 19) (setq major 'v19    ;Emacs 19
X                        flavor (cond
X                                ((string-match "Win-Emacs" emacs-version)
X                                 'Win-Emacs)
X                                ((or (string-match "Lucid" emacs-version)
X                                     (string-match "XEmacs" emacs-version))
X                                 'XEmacs)
X                                (t
X                                 'FSF))))
X     ;; I don't know
X     (t (error "Cannot recognize major version number: %s" major)))
X    ;; lets do some minimal sanity checking.
X    (if (and (or
X             ;; Emacs 18 is brain dead
X             (eq major 'v18)
X             ;; Lemacs before 19.6 had bugs
X             (and (eq major 'v19) (eq flavor 'XEmacs) (< minor 6))
X             ;; FSF 19 before 19.21 had bugs
X             (and (eq major 'v19) (eq flavor 'FSF) (< minor 21)))
X            (not vhdl-inhibit-startup-warnings-p))
X       (with-output-to-temp-buffer "*vhdl-mode warnings*"
X         (print (format
"The version of Emacs that you are running, %s,
has known bugs in its syntax.c parsing routines which will affect the
performance of vhdl-mode. You should strongly consider upgrading to the
latest available version.  vhdl-mode may continue to work, after a
fashion, but strange indentation errors could be encountered."
X                    emacs-version))))
X    (list major flavor))
X  "A list of features extant in the Emacs you are using.
There are many flavors of Emacs out there, each with different
features supporting those needed by vhdl-mode.  Here's the current
supported list, along with the values for this variable:
X
X Emacs 18/Epoch 4:           (v18)
X XEmacs (formerly Lucid) 19: (v19 XEmacs)
X Win-Emacs 1.35:             (V19 Win-Emacs)
X FSF Emacs 19:               (v19 FSF).")
X
(defvar vhdl-mode-abbrev-table nil
X  "Abbrev table in use in vhdl-mode buffers.")
(define-abbrev-table 'vhdl-mode-abbrev-table ())
X
(defvar vhdl-mode-map ()
X  "Keymap used in vhdl-mode buffers.")
(if vhdl-mode-map
X    ()
X  ;; TBD: should we even worry about naming this keymap. My vote: no,
X  ;; because FSF and XEmacs (formerly Lucid) do it differently.
X  (setq vhdl-mode-map (make-sparse-keymap))
X  ;; put standard keybindings into MAP
X  (define-key vhdl-mode-map "\M-a"   'vhdl-beginning-of-statement)
X  ;;(define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
X  (define-key vhdl-mode-map "\M-\C-f"   'vhdl-forward-sexp)
X  (define-key vhdl-mode-map "\M-\C-b"   'vhdl-backward-sexp)
X  (define-key vhdl-mode-map "\M-\C-u"        'vhdl-backward-up-list)
X  ;;(define-key vhdl-mode-map "\M-\C-d"      'vhdl-down-list)
X  (define-key vhdl-mode-map "\M-\C-a"        'vhdl-beginning-of-defun)
X  (define-key vhdl-mode-map "\M-\C-e"        'vhdl-end-of-defun)
X  (define-key vhdl-mode-map "\M-\C-h"        'vhdl-mark-defun)
X  (define-key vhdl-mode-map "\M-\C-q"        'vhdl-indent-sexp)
X  (define-key vhdl-mode-map "\t"        'vhdl-indent-command)
X  (define-key vhdl-mode-map "\177"      'backward-delete-char-untabify)
X  ;; these are new keybindings, with no counterpart to BOCM
X  (define-key vhdl-mode-map "\C-c\C-b"  'vhdl-submit-bug-report)
X  (define-key vhdl-mode-map "\C-c\C-c"  'comment-region)
X  (define-key vhdl-mode-map "\C-c\C-o"  'vhdl-set-offset)
X  (define-key vhdl-mode-map "\C-c\C-r"  'vhdl-regress-line)
X  (define-key vhdl-mode-map "\C-c\C-s"  'vhdl-show-syntactic-information)
X  (define-key vhdl-mode-map "\C-c\C-v"  'vhdl-version)
X  ;; in XEmacs (formerly Lucid) 19, we want the menu to popup when
X  ;; the 3rd button is hit.  In 19.10 and beyond this is done
X  ;; automatically if we put the menu on mode-popup-menu variable,
X  ;; see c-common-init. RMS decided that this feature should not be
X  ;; included for FSF's Emacs.
X  (if (and (boundp 'current-menubar)
X          (not (boundp 'mode-popup-menu)))
X      (define-key vhdl-mode-map 'button3 'vhdl-popup-menu))
X  )
X
(defvar vhdl-mode-syntax-table nil
X  "Syntax table used in vhdl-mode buffers.")
(if vhdl-mode-syntax-table
X    ()
X  (setq vhdl-mode-syntax-table (make-syntax-table))
X  ;; DO NOT TRY TO SET _ (UNDERSCORE) TO WORD CLASS!
X  (modify-syntax-entry ?\" "\""    vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\$ "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\% "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\& "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\' "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\( "()"    vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\) ")("    vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\* "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\+ "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\. "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\/ "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\: "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\; "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\< "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\= "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\> "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\[ "(]"    vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\\ "\\"    vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\] ")["    vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\{ "(}"    vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\| "."     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\} "){"    vhdl-mode-syntax-table)
X  ;; add comment syntax
X  (modify-syntax-entry ?\- ". 12"  vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\n ">"     vhdl-mode-syntax-table)
X  (modify-syntax-entry ?\^M ">"    vhdl-mode-syntax-table))
X
(defvar vhdl-syntactic-context nil
X  "Buffer local variable containing syntactic analysis list.")
(make-variable-buffer-local 'vhdl-syntactic-context)
X
;; Support for outline modes
X
(defconst vhdl-outline-regexp
X  (concat "\\(entity\\)\\|\\(package\\)\\|"
X         "\\( *procedure\\)\\|\\( *function\\)\\|"
X         "\\( *component\\)\\|\\(architecture\\)\\|"
X         "\\(package body\\)\\|\\( *[A-Za-z][A-Za-z0-9_]* : block\\)\\|"
X         "\\( *[A-Za-z][A-Za-z0-9_]* : process\\)\\|\\(configuration\\)"))
X
(defun vhdl-outline-level ()            ; was copied from c-outline-level
X  (save-excursion
X    (skip-chars-forward "\t ")
X    (current-column)))
X
;; Support for font-lock
X
(defconst vhdl-font-lock-keywords-1
X  (purecopy
X   (list
X    ;; Highlight names of common constructs
X    (list
X     (concat
X      "^[ \t]*\\(entity\\|architecture\\|configuration\\|function\\|"
X      "procedure\\|component\\|package[ \t]+body\\|package\\|"
X      "end[ \t]+\\(block\\|process\\|case\\|generate\\|loop\\)\\)[ \t]+"
X      "\\(\\(\\w\\|\\s_\\)+\\)")
X     3 'font-lock-function-name-face)
X    
X    ;; Highlight labels of common constructs
X    (list
X     (concat
X      "^[ \t]*\\(\\(\\w\\|\\s_\\)+\\)[ \t]*:[ \t\n]*\\(block\\|process\\|"
X      "if\\|for\\|case\\|exit\\|loop\\|next\\|null\\|with\\|"
X      "\\(\\w\\|\\s_\\)+[ \t\n]+port[ \t]+map\\)\\>[^_]")
X     1 'font-lock-function-name-face)
X    
X    ;; Highlight OF labels
X    (list
X     (concat
X      "^[ \t]*\\(configuration\\|architecture\\|attribute\\)[ \t]+"
X      "\\(\\(\\w\\|\\s_\\)+\\)[ \t]+of[ \t]+\\(\\(\\w\\|\\s_\\)+\\)")
X     4 'font-lock-function-name-face)
X    
X    ;; Fontify library useage clauses.
X    (list
X     (concat
X      "[^\\s_]\\<\\(library\\|use\\)[ \t\n]+\\(entity[ \t\n]+\\)?"
X      "\\(\\(\\w\\|\\s_\\|[\.()]\\)+\\)")
X     4 'font-lock-function-name-face)
X    ))
X  "For consideration as a value of `vhdl-font-lock-keywords'.
This does fairly subdued highlighting of function names.")
X
(defconst vhdl-font-lock-keywords-2
X  (purecopy
X   (append
X    vhdl-font-lock-keywords-1
X    (list
X     (list
X      (concat
X       "[^\\s_]\\<\\("
X       (mapconcat
X       'identity
X       '(
X         ;; the following is a list of all reserved words known in VHDL'93
X         "abs" "access" "after" "alias" "all" "and" "assert"
X         "architecture" "array" "attribute"
X         "begin" "block" "body" "buffer" "bus"
X         "case" "component" "configuration" "constant"
X         "disconnect" "downto"
X         "else" "elsif" "end" "entity" "exit"
X         "file" "for" "function"
X         "generate" "generic" "group" "guarded"
X         "if" "impure" "in" "inertial" "inout" "is"
X         "label" "library" "linkage" "literal" "loop"
X         "map" "mod"
X         "nand" "new" "next" "nor" "not" "null"
X         "of" "on" "open" "or" "others" "out"
X         "package" "port" "postponed" "procedure" "process" "pure"
X         "range" "record" "register" "reject" "rem" "report" "return"
X         "rol" "ror"
X         "select" "severity" "signal" "shared" "sla" "sll" "sra" "srl"
X         "subtype"
X         "then" "to" "transport" "type"
X         "unaffected" "units" "until" "use"
X         "variable" "wait" "when" "while" "with"
X         "xnor" "xor"
X         "note" "warning" "error" "failure"
X         ;; the following list contains predefined attributes
X         "base" "left" "right" "high" "low" "pos" "val" "succ"
X         "pred" "leftof" "rightof" "range" "reverse_range"
X         "length" "delayed" "stable" "quiet" "transaction"
X         "event" "active" "last_event" "last_active" "last_value"
X         "driving" "driving_value" "ascending" "value" "image"
X         "simple_name" "instance_name" "path_name"
X         "foreign"
X         ;; the following list contains standardized types
X         "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
X         "real" "time" "natural" "positive" "string" "text" "line"
X         "unsigned" "signed"
X         "std_logic" "std_logic_vector"
X         "std_ulogic" "std_ulogic_vector"
X         )
X       "\\|")
X       "\\)\\>[^\\s_]")
X      1 'font-lock-keyword-face)
X     )))
X  "For consideration as a value of `vhdl-font-lock-keywords'.
This does a lot more highlighting.")
X
;; The keywords in the preceding lists assume case-insensitivity.
(put 'vhdl-mode 'font-lock-keywords-case-fold-search t)
X
(defvar vhdl-font-lock-keywords vhdl-font-lock-keywords-1
X  "Additional expressions to highlight in VHDL mode.")
X
;; This should eventually be subsumed into the respective functions in
;; the source for "font-lock.el".
(if (featurep 'advice)
X    (progn
X      (defadvice font-lock-use-default-minimal-decoration
X       (before vhdl-mode activate)
X       "Do it for VHDL mode too."
X       (setq vhdl-font-lock-keywords vhdl-font-lock-keywords-1))
X      
X      (defadvice font-lock-use-default-maximal-decoration
X       (before vhdl-mode activate)
X       "Do it for VHDL mode too."
X       (setq vhdl-font-lock-keywords vhdl-font-lock-keywords-2))
X      ))
X
X
;; Main entry point for VHDL mode:
X
;;;###autoload
(defun vhdl-mode ()
X  "Major mode for editing VHDL code.
vhdl-mode $Revision: 2.71 $
To submit a problem report, enter `\\[vhdl-submit-bug-report]' from a
vhdl-mode buffer.  This automatically sets up a mail buffer with version
information already added.  You just need to add a description of the
problem, including a reproducable test case and send the message.
X
Note that the details of configuring vhdl-mode will soon be moved to the
accompanying texinfo manual.  Until then, please read the README file
that came with the vhdl-mode distribution.
X
The hook variable `vhdl-mode-hook' is run with no args, if that value is
bound and has a non-nil value.
X
Key bindings:
\\{vhdl-mode-map}"
X  (interactive)
X  (kill-all-local-variables)
X  (set-syntax-table vhdl-mode-syntax-table)
X  (setq major-mode 'vhdl-mode
X       mode-name "VHDL"
X       local-abbrev-table vhdl-mode-abbrev-table)
X  (use-local-map vhdl-mode-map)
X  ;; set local variable values
X  (set (make-local-variable 'paragraph-start) (concat "^$\\|" page-delimiter))
X  (set (make-local-variable 'paragraph-separate) paragraph-start)
X  (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
X  (set (make-local-variable 'require-final-newline) t)
X  (set (make-local-variable 'parse-sexp-ignore-comments) t)
X  (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
X  (set (make-local-variable 'comment-start) "-- ")
X  (set (make-local-variable 'comment-end) "")
X  (set (make-local-variable 'comment-column) 32)
X  (set (make-local-variable 'comment-start-skip) "--+ *")
X  (set (make-local-variable 'outline-regexp) vhdl-outline-regexp)
X  (set (make-local-variable 'outline-level) 'vhdl-outline-level)
X
X  ;; setup the comment indent variable in a Emacs version portable way
X  ;; ignore any byte compiler warnings you might get here
X  (if (boundp 'comment-indent-function)
X      (progn
X          (make-local-variable 'comment-indent-function)
X          (setq comment-indent-function 'vhdl-comment-indent))
X    (make-local-variable 'comment-indent-hook)
X    (setq comment-indent-hook 'vhdl-comment-indent))
X  ;; put VHDL menu into menubar and on popup menu for XEmacs (formerly
X  ;; Lucid) 19. I think this happens automatically for FSF Emacs 19.
X  (if (and (boundp 'current-menubar)
X          current-menubar
X          (not (assoc mode-name current-menubar)))
X      (progn
X       (set-buffer-menubar (copy-sequence current-menubar))
X       (add-menu nil mode-name vhdl-mode-menu)))
X  (if (boundp 'mode-popup-menu)
X      (setq mode-popup-menu
X           (cons (concat mode-name " Mode Commands") vhdl-mode-menu)))
X  (run-hooks 'vhdl-mode-hook))
X
;; menus for XEmacs (formerly Lucid)
X
(defun vhdl-popup-menu (e)
X  "Pops up the VHDL menu."

X  (popup-menu (cons (concat mode-name " Mode Commands") vhdl-mode-menu))
X  (vhdl-keep-region-active))
X
;; active regions
X
(defun vhdl-keep-region-active ()
X  ;; do whatever is necessary to keep the region active in XEmacs
X  ;; (formerly Lucid). ignore byte-compiler warnings you might see
X  (and (boundp 'zmacs-region-stays)
X       (setq zmacs-region-stays t)))
X
;; constant regular expressions for looking at various constructs
X
(defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
X  "Regexp describing a VHDL symbol.
We cannot use just `word' syntax class since `_' cannot be in word
class.  Putting underscore in word class breaks forward word movement
behavior that users are familiar with.")
X
(defconst vhdl-case-alternative-key "when[( \t\n][^;=>]+=>"
X  "Regexp describing a case statement alternative key.")
X
(defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
X  "Regexp describing a case statement header key.")
X
(defconst vhdl-label-key
X  (concat vhdl-symbol-key "\\s-*:")
X  "Regexp describing a VHDL label.")
X
X
;; Macro definitions:
X
(defmacro vhdl-point (position)
X  ;; Returns the value of point at certain commonly referenced POSITIONs.
X  ;; POSITION can be one of the following symbols:
X  ;;
X  ;; bol  -- beginning of line
X  ;; eol  -- end of line
X  ;; bod  -- beginning of defun
X  ;; boi  -- back to indentation
X  ;; eoi  -- last whitespace on line
X  ;; ionl -- indentation of next line
X  ;; iopl -- indentation of previous line
X  ;; bonl -- beginning of next line
X  ;; bopl -- beginning of previous line
X  ;;
X  ;; This function does not modify point or mark.
X  (or (and (eq 'quote (car-safe position))
X          (null (cdr (cdr position))))
X      (error "bad buffer position requested: %s" position))
X  (setq position (nth 1 position))
X  (` (let ((here (point)))

X           ((eq position 'bol)  '((beginning-of-line)))
X           ((eq position 'eol)  '((end-of-line)))
X           ((eq position 'bod)  '((save-match-data
X                                    (vhdl-beginning-of-defun))))
X           ((eq position 'boi)  '((back-to-indentation)))
X           ((eq position 'eoi)  '((end-of-line)(skip-chars-backward " \t")))
X           ((eq position 'bonl) '((forward-line 1)))
X           ((eq position 'bopl) '((forward-line -1)))
X           ((eq position 'iopl)
X            '((forward-line -1)
X              (back-to-indentation)))
X           ((eq position 'ionl)
X            '((forward-line 1)
X              (back-to-indentation)))
X           (t (error "unknown buffer position requested: %s" position))
X           ))
X       (prog1
X          (point)
X        (goto-char here))
X       ;; workaround for an Emacs18 bug -- blech! Well, at least it
X       ;; doesn't hurt for v19

X       )))
X
(defmacro vhdl-safe (&rest body)
X  ;; safely execute BODY, return nil if an error occurred
X  (` (condition-case nil

X       (error nil))))
X
(defmacro vhdl-add-syntax (symbol &optional relpos)
X  ;; a simple macro to append the syntax in symbol to the syntax list.
X  ;; try to increase performance by using this macro
X  (` (setq vhdl-syntactic-context
X          (cons (cons (, symbol) (, relpos)) vhdl-syntactic-context))))
X
(defmacro vhdl-has-syntax (symbol)
X  ;; a simple macro to return check the syntax list.
X  ;; try to increase performance by using this macro
X  (` (assoc (, symbol) vhdl-syntactic-context)))
X
X
;; Syntactic element offset manipulation:
X
(defun vhdl-read-offset (langelem)
X  ;; read new offset value for LANGELEM from minibuffer. return a
X  ;; legal value only
X  (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
X       (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
X       (prompt "Offset: ")
X       offset input interned)
X    (while (not offset)
X      (setq input (read-string prompt oldoff)
X           offset (cond ((string-equal "+" input) '+)
X                        ((string-equal "-" input) '-)
X                        ((string-equal "++" input) '++)
X                        ((string-equal "--" input) '--)
X                        ((string-match "^-?[0-9]+$" input)
X                         (string-to-int input))
X                        ((fboundp (setq interned (intern input)))
X                         interned)
X                        ((boundp interned) interned)
X                        ;; error, but don't signal one, keep trying
X                        ;; to read an input value
X                        (t (ding)
X                           (setq prompt errmsg)
X                           nil))))
X    offset))
X
(defun vhdl-set-offset (symbol offset &optional add-p)
X  "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
SYMBOL is the syntactic element symbol to change and OFFSET is the new
offset for that syntactic element.  Optional ADD says to add SYMBOL to
`vhdl-offsets-alist' if it doesn't already appear there."
X  (interactive
X   (let* ((langelem
X          (intern (completing-read
X                   (concat "Syntactic symbol to change"
X                           (if current-prefix-arg " or add" "")
X                           ": ")
X                   (mapcar
X                    (function
X                     (lambda (langelem)
X                       (cons (format "%s" (car langelem)) nil)))
X                    vhdl-offsets-alist)
X                   nil (not current-prefix-arg)
X                   ;; initial contents tries to be the last element
X                   ;; on the syntactic analysis list for the current
X                   ;; line
X                   (let* ((syntax (vhdl-get-syntactic-context))
X                          (len (length syntax))
X                          (ic (format "%s" (car (nth (1- len) syntax)))))
X                     (if (memq 'v19 vhdl-emacs-features)
X                         (cons ic 0)
X                       ic))
X                   )))
X         (offset (vhdl-read-offset langelem)))
X     (list langelem offset current-prefix-arg)))
X  ;; sanity check offset
X  (or (eq offset '+)
X      (eq offset '-)
X      (eq offset '++)
X      (eq offset '--)
X      (integerp offset)
X      (fboundp offset)
X      (boundp offset)
X      (error "Offset must be int, func, var, or one of +, -, ++, --: %s"
X            offset))
X  (let ((entry (assq symbol vhdl-offsets-alist)))
X    (if entry
X       (setcdr entry offset)
X      (if add-p
X         (setq vhdl-offsets-alist (cons (cons symbol offset) vhdl-offsets-alist))
X       (error "%s is not a valid syntactic symbol." symbol))))
X  (vhdl-keep-region-active))
X
(defun vhdl-set-style (style &optional local)
X  "Set vhdl-mode variables to use one of several different indentation styles.
STYLE is a string representing the desired style and optional LOCAL is
a flag which, if non-nil, means to make the style variables being
changed buffer local, instead of the default, which is to set the
global variables.  Interactively, the flag comes from the prefix
argument.  The styles are chosen from the `vhdl-style-alist' variable."
X  (interactive (list (completing-read "Use which VHDL indentation style? "
X                                      vhdl-style-alist nil t)
X                    current-prefix-arg))
X  (let ((vars (cdr (assoc style vhdl-style-alist))))
X    (or vars
X       (error "Invalid VHDL indentation style `%s'" style))
X    ;; set all the variables
X    (mapcar
X     (function
X      (lambda (varentry)
X       (let ((var (car varentry))
X             (val (cdr varentry)))
X         (and local
X              (make-local-variable var))
X         ;; special case for vhdl-offsets-alist
X         (if (not (eq var 'vhdl-offsets-alist))
X             (set var val)
X           ;; reset vhdl-offsets-alist to the default value first
X           (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
X           ;; now set the langelems that are different
X           (mapcar
X            (function
X             (lambda (langentry)
X               (let ((langelem (car langentry))
X                     (offset (cdr langentry)))
X                 (vhdl-set-offset langelem offset)
X                 )))
X            val))
X         )))
X     vars))
X  (vhdl-keep-region-active))
X
(defun vhdl-get-offset (langelem)
X  ;; Get offset from LANGELEM which is a cons cell of the form:
X  ;; (SYMBOL . RELPOS).  The symbol is matched against
X  ;; vhdl-offsets-alist and the offset found there is either returned,
X  ;; or added to the indentation at RELPOS.  If RELPOS is nil, then
X  ;; the offset is simply returned.
X  (let* ((symbol (car langelem))
X        (relpos (cdr langelem))
X        (match  (assq symbol vhdl-offsets-alist))
X        (offset (cdr-safe match)))
X    ;; offset can be a number, a function, a variable, or one of the
X    ;; symbols + or -
X    (cond
X     ((not match)
X      (if vhdl-strict-syntax-p
X         (error "don't know how to indent a %s" symbol)
X       (setq offset 0
X             relpos 0)))
X     ((eq offset '+)  (setq offset vhdl-basic-offset))
X     ((eq offset '-)  (setq offset (- vhdl-basic-offset)))
X     ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
X     ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
X     ((and (not (numberp offset))
X          (fboundp offset))
X      (setq offset (funcall offset langelem)))
X     ((not (numberp offset))
X      (setq offset (eval offset)))
X     )
X    (+ (if (and relpos
X               (< relpos (vhdl-point 'bol)))
X          (save-excursion
X            (goto-char relpos)
X            (current-column))
X        0)
X       offset)))
X
X
;; Syntactic support functions:
X
;; Returns `comment' if in a comment, `string' if in a string literal,
;; or nil if not in a literal at all.  Optional LIM is used as the
;; backward limit of the search.  If omitted, or nil, (point-min) is
;; used.
X
(defun vhdl-in-literal (&optional lim)
X  ;; Determine if point is in a VHDL literal.
X  (save-excursion
X    (let* ((lim (or lim (point-min)))
X          (state (parse-partial-sexp lim (point))))
X      (cond
X       ((nth 3 state) 'string)
X       ((nth 4 state) 'comment)
X       (t nil)))
X    ))
X
;; This is the best we can do in Win-Emacs.
(defun vhdl-win-il (&optional lim)
X  ;; Determine if point is in a VHDL literal
X  (save-excursion
X    (let* ((here (point))
X          (state nil)
X          (match nil)
X          (lim  (or lim (vhdl-point 'bod))))
X      (goto-char lim )
X      (while (< (point) here)
X       (setq match
X             (and (re-search-forward "--\\|[\"']"
X                                     here 'move)
X                  (buffer-substring (match-beginning 0) (match-end 0))))
X       (setq state
X             (cond
X              ;; no match
X              ((null match) nil)
X              ;; looking at the opening of a VHDL style comment
X              ((string= "--" match)
X               (if (<= here (progn (end-of-line) (point))) 'comment))
X              ;; looking at the opening of a double quote string
X              ((string= "\"" match)
X               (if (not (save-restriction
X                          ;; this seems to be necessary since the
X                          ;; re-search-forward will not work without it
X                          (narrow-to-region (point) here)
X                          (re-search-forward
X                           ;; this regexp matches a double quote
X                           ;; which is preceded by an even number
X                           ;; of backslashes, including zero
X                           "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
X                   'string))
X              ;; looking at the opening of a single quote string
X              ((string= "'" match)
X               (if (not (save-restriction
X                          ;; see comments from above
X                          (narrow-to-region (point) here)
X                          (re-search-forward
X                           ;; this matches a single quote which is
X                           ;; preceded by zero or two backslashes.
X                           "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
X                           here 'move)))
X                   'string))
X              (t nil)))
X       ) ; end-while
X      state)))
X
(and (memq 'Win-Emacs vhdl-emacs-features)
X     (fset 'vhdl-in-literal 'vhdl-win-il))
X
;; Skipping of "syntactic whitespace".  Syntactic whitespace is
;; defined as lexical whitespace or comments.  Search no farther back
;; or forward than optional LIM.  If LIM is omitted, (point-min) is
;; used for backward skipping, (point-max) is used for forward
;; skipping.
X
(defun vhdl-forward-syntactic-ws (&optional lim)
X  ;; Forward skip of syntactic whitespace.
X  (save-restriction
X    (let* ((lim (or lim (point-max)))
X          (here lim)
X          (hugenum (point-max)))
X      (narrow-to-region lim (point))
X      (while (/= here (point))
X       (setq here (point))
X       (forward-comment hugenum))
X      )))
X
;; This is the best we can do in Win-Emacs.
(defun vhdl-win-fsws (&optional lim)
X  ;; Forward skip syntactic whitespace for Win-Emacs.
X  (let ((lim (or lim (point-max)))
X       stop)
X    (while (not stop)
X      (skip-chars-forward " \t\n\r\f" lim)
X      (cond
X       ;; vhdl comment
X       ((looking-at "--") (end-of-line))
X       ;; none of the above
X       (t (setq stop t))
X       ))))
X
(and (memq 'Win-Emacs vhdl-emacs-features)
X     (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
X
(defun vhdl-backward-syntactic-ws (&optional lim)
X  ;; Backward skip over syntactic whitespace.
X  (save-restriction
X    (let* ((lim (or lim (point-min)))
X          (here lim)
X          (hugenum (- (point-max))))
X      (if (< lim (point))
X         (progn
X           (narrow-to-region lim (point))
X           (while (/= here (point))
X             (setq here (point))
X             (forward-comment hugenum)
X             )))
X      )))
X
;; This is the best we can do in Win-Emacs.
(defun vhdl-win-bsws (&optional lim)
X  ;; Backward skip syntactic whitespace for Win-Emacs.
X  (let ((lim (or lim (vhdl-point 'bod)))
X       stop)
X    (while (not stop)
X      (skip-chars-backward " \t\n\r\f" lim)
X      (cond
X       ;; vhdl comment
X       ((eq (vhdl-in-literal lim) 'comment)
X       (skip-chars-backward "^-" lim)
X       (skip-chars-backward "-" lim)
X       (while (not (or (and (= (following-char) ?-)
X                            (= (char-after (1+ (point))) ?-))
X                       (<= (point) lim)))
X         (skip-chars-backward "^-" lim)
X         (skip-chars-backward "-" lim)))
X       ;; none of the above
X       (t (setq stop t))
X       ))))
X
(and (memq 'Win-Emacs vhdl-emacs-features)
X    (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
X
;; Functions to help finding the correct indentation column:
X
(defun vhdl-first-word (point)
X  "If the keyword at POINT is at boi, then return (current-column) at
that point, else nil."
X  (save-excursion
X    (and (goto-char point)
X        (eq (point) (vhdl-point 'boi))
X        (current-column))))
X
(defun vhdl-last-word (point)
X  "If the keyword at POINT is at eoi, then return (current-column) at
that point, else nil."
X  (save-excursion
X    (and (goto-char point)
X        (save-excursion (or (eq (progn (forward-sexp) (point))
X                                (vhdl-point 'eoi))
X                            (looking-at "\\s-*\\(--\\)?")))
X        (current-column))))
X
X
;; Core syntactic evaluation functions:
X
(defconst vhdl-libunit-re
X  "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
X
(defun vhdl-libunit-p ()
X  (and
X   (save-excursion
X     (forward-sexp)
X     (skip-chars-forward " \t\n")
X     (not (looking-at "is\\b[^_]")))
X   (save-excursion
X     (backward-sexp)
X     (not (looking-at "use\\b[^_]")))))
X
(defconst vhdl-defun-re
X  "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedure\\|function\\)\\b[^_]")
X
(defun vhdl-defun-p ()
X  (save-excursion
X    (if (looking-at "block\\|process")
X       ;; "block", "process":
X       (save-excursion
X         (backward-sexp)
X         (not (looking-at "end\\s-+\\w")))
X      ;; "architecture", "configuration", "entity",
X      ;; "package", "procedure", "function":
X      t)))
X  
(defun vhdl-corresponding-defun ()
X  "If the word at the current position corresponds to a \"defun\"
keyword, then return a string that can be used to find the
corresponding \"begin\" keyword, else return nil."
X  (save-excursion
X    (and (looking-at vhdl-defun-re)
X        (vhdl-defun-p)
X        (if (looking-at "block\\|process")
X            ;; "block", "process":
X            (buffer-substring (match-beginning 0) (match-end 0))
X          ;; "architecture", "configuration", "entity", "package",
X          ;; "procedure", "function":
X          "is"))))
X
(defconst vhdl-begin-fwd-re
X  "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
X  "A regular expression for searching forward that matches all known
\"begin\" keywords.")
X
(defconst vhdl-begin-bwd-re
X  "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|units\\|record\\|for\\)\\b"
X  "A regular expression for searching backward that matches all known
\"begin\" keywords.")
X
(defun vhdl-begin-p (&optional lim)
X  "Return t if we are looking at a real \"begin\" keyword.
Assumes that the caller will make sure that we are looking at
vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
the middle of an identifier that just happens to contain a \"begin\"
keyword."
X  (cond
X   ;; "[architecture|case|configuration|entity|package|
X   ;;   procedure|function] ... is":
X   ((and (looking-at "i")
X        (save-excursion
X          ;; Skip backward over first sexp (needed to skip over a
X          ;; procedure interface list, and is harmless in other
X          ;; situations).  Note that we need "return" in the
X          ;; following search list so that we don't run into
X          ;; semicolons in the function interface list.
X          (backward-sexp)
X          (let (foundp)
X            (while (and (not foundp)
X                        (re-search-backward
X                         ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|block\\)\\b[^_]"
X                         lim 'move))
X              (if (or (= (preceding-char) ?_)
X                      (vhdl-in-literal lim))
X                  (backward-char)
X                (setq foundp t))))
X          (and (/= (following-char) ?\;)
X               (not (looking-at "is\\|begin\\|process\\|block")))))
X    t)
X   ;; "begin", "then":
X   ((looking-at "be\\|t")
X    t)
X   ;; "else":
X   ((and (looking-at "e")
X        ;; make sure that the "else" isn't inside a
X        ;; conditional signal assignment.
X        (save-excursion
X          (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
X          (or (eq (following-char) ?\;)
X              (eq (point) lim))))
X    t)
X   ;; "block", "component", "generate", "loop", "process",
X   ;; "units", "record":
X   ((and (looking-at "bl\\|[cglpur]")
X        (save-excursion
X          (backward-sexp)
X          (not (looking-at "end\\s-+\\w"))))
X    t)
X   ;; "for" (inside configuration declaration):
X   ((and (looking-at "f")
X        (save-excursion
X          (backward-sexp)
X          (not (looking-at "end\\s-+\\w")))
X        (vhdl-has-syntax 'configuration))
X    t)
X   ))
X  
(defun vhdl-corresponding-mid (&optional lim)
X  (cond
X   ((looking-at "is\\|block\\|process")
X    "begin")
X   ((looking-at "then")
X    "<else>")
X   (t
X    "end")))
X
(defun vhdl-corresponding-end (&optional lim)
X  "If the word at the current position corresponds to a \"begin\"
keyword, then return a vector containing enough information to find
the corresponding \"end\" keyword, else return nil.  The keyword to
search forward for is aref 0.  The column in which the keyword must
appear is aref 1 or nil if any column is suitable.
Assumes that the caller will make sure that we are not in the middle
of an identifier that just happens to contain a \"begin\" keyword."
X  (save-excursion
X    (and (looking-at vhdl-begin-fwd-re)
X        (/= (preceding-char) ?_)
X        (not (vhdl-in-literal lim))
X        (vhdl-begin-p lim)
X        (cond
X         ;; "is", "generate", "loop":
X         ((looking-at "[igl]")
X          (vector "end"
X                  (and (vhdl-last-word (point))
X                       (or (vhdl-first-word (point))
X                           (save-excursion
X                             (vhdl-beginning-of-statement-1 lim)
X                             (vhdl-backward-skip-label lim)
X                             (vhdl-first-word (point)))))))
X         ;; "begin", "else", "for":
X         ((looking-at "be\\|[ef]")
X          (vector "end"
X                  (and (vhdl-last-word (point))
X                       (or (vhdl-first-word (point))
X                           (save-excursion
X                             (vhdl-beginning-of-statement-1 lim)
X                             (vhdl-backward-skip-label lim)
X                             (vhdl-first-word (point)))))))
X         ;; "component", "units", "record":
X         ((looking-at "[cur]")
X          ;; The first end found will close the block
X          (vector "end" nil))
X         ;; "block", "process":
X         ((looking-at "bl\\|p")
X          (vector "end"
X                  (or (vhdl-first-word (point))
X                      (save-excursion
X                        (vhdl-beginning-of-statement-1 lim)
X                        (vhdl-backward-skip-label lim)
X                        (vhdl-first-word (point))))))
X         ;; "then":
X         ((looking-at "t")
X          (vector "elsif\\|else\\|end"
X                  (and (vhdl-last-word (point))
X                       (or (vhdl-first-word (point))
X                           (save-excursion
X                             (vhdl-beginning-of-statement-1 lim)
X                             (vhdl-backward-skip-label lim)
X                             (vhdl-first-word (point)))))))
X         ))))
X
(defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
X
(defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b")
X
(defun vhdl-end-p (&optional lim)
X  "Return t if we are looking at a real \"end\" keyword.
Assumes that the caller will make sure that we are looking at
vhdl-end-fwd-re, and are not inside a literal, and that we are not in
the middle of an identifier that just happens to contain an \"end\"
keyword."
X  (or (not (looking-at "else"))
X      ;; make sure that the "else" isn't inside a conditional signal
X      ;; assignment.
X      (save-excursion
X       (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
X       (or (eq (following-char) ?\;)
X           (eq (point) lim)))))
X
(defun vhdl-corresponding-begin (&optional lim)
X  "If the word at the current position corresponds to an \"end\"
keyword, then return a vector containing enough information to find
the corresponding \"begin\" keyword, else return nil.  The keyword to
search backward for is aref 0.  The column in which the keyword must
appear is aref 1 or nil if any column is suitable.  The supplementary
keyword to search forward for is aref 2 or nil if this is not
required.  If aref 3 is t, then the \"begin\" keyword may be found in
the middle of a statement.
Assumes that the caller will make sure that we are not in the middle
of an identifier that just happens to contain an \"end\" keyword."
X  (save-excursion
X    (let (pos)
X      (if (and (looking-at vhdl-end-fwd-re)
X              (not (vhdl-in-literal lim))
X              (vhdl-end-p lim))
X         (if (looking-at "el")
X             ;; "else", "elsif":
X             (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
X           ;; "end ...":
X           (setq pos (point))
X           (forward-sexp)
X           (skip-chars-forward " \t\n")
X           (cond
X            ;; "end if":
X            ((looking-at "if\\b[^_]")
X             (vector "else\\|elsif\\|if"
X                     (vhdl-first-word pos)
X                     "else\\|then" nil))
X            ;; "end component":
X            ((looking-at "component\\b[^_]")
X             (vector (buffer-substring (match-beginning 1)
X                                       (match-end 1))
X                     (vhdl-first-word pos)
X                     nil nil))
X            ;; "end units", "end record":
X            ((looking-at "\\(units\\|record\\)\\b[^_]")
X             (vector (buffer-substring (match-beginning 1)
X                                       (match-end 1))
X                     (vhdl-first-word pos)
X                     nil t))
X            ;; "end block", "end process":
X            ((looking-at "\\(block\\|process\\)\\b[^_]")
X             (vector "begin" (vhdl-first-word pos) nil nil))
X            ;; "end case":
X            ((looking-at "case\\b[^_]")
X             (vector "case" (vhdl-first-word pos) "is" nil))
X            ;; "end generate":
X            ((looking-at "generate\\b[^_]")
X             (vector "generate\\|for\\|if"
X                     (vhdl-first-word pos)
X                     "generate" nil))
X            ;; "end loop":
X            ((looking-at "loop\\b[^_]")
X             (vector "loop\\|while\\|for"
X                     (vhdl-first-word pos)
X                     "loop" nil))
X            ;; "end for" (inside configuration declaration):
X            ((looking-at "for\\b[^_]")
X             (vector "for" (vhdl-first-word pos) nil nil))
X            ;; "end [id]":
X            (t
X             (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
X                     (vhdl-first-word pos)
X                     ;; return an alist of (statement . keyword) mappings
X                     '(
X                       ;; "begin ... end [id]":
X                       ("begin"          . nil)
X                       ;; "architecture ... is ... begin ... end [id]":
X                       ("architecture"   . "is")
X                       ;; "configuration ... is ... end [id]":
X                       ("configuration"  . "is")
X                       ;; "entity ... is ... end [id]":
X                       ("entity"         . "is")
X                       ;; "package ... is ... end [id]":
X                       ("package"        . "is")
X                       ;; "procedure ... is ... begin ... end [id]":
X                       ("procedure"      . "is")
X                       ;; "function ... is ... begin ... end [id]":
X                       ("function"       . "is")
X                       )
X                     nil))
X            ))) ; "end ..."
X      )))
X
(defconst vhdl-leader-re
X  "\\b\\(block\\|component\\|process\\|for\\)\\b[^_]")
X
(defun vhdl-end-of-leader ()
X  (save-excursion
X    (cond ((looking-at "block\\|process")
X          (if (save-excursion
X                (forward-sexp)
X                (skip-chars-forward " \t\n")
X                (= (following-char) ?\())
X              (forward-sexp 2)
X            (forward-sexp))
X          (point))
X         ((looking-at "component")
X          (forward-sexp 2)
X          (point))
X         ((looking-at "for")
X          (forward-sexp 2)
X          (skip-chars-forward " \t\n")
X          (while (looking-at "[,:(]")
X            (forward-sexp)
X            (skip-chars-forward " \t\n"))
X          (point))
X         (t nil)
X         )))
X
(defconst vhdl-trailer-re
X  "\\b\\(is\\|then\\|generate\\|loop\\)\\b[^_]")
X
(defconst vhdl-statement-fwd-re
X  "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
X  "A regular expression for searching forward that matches all known
\"statement\" keywords.")
X
(defconst vhdl-statement-bwd-re
X  "\\b\\(if\\|for\\|while\\)\\b"
X  "A regular expression for searching backward that matches all known
\"statement\" keywords.")
X
(defun vhdl-statement-p (&optional lim)
X  "Return t if we are looking at a real \"statement\" keyword.
Assumes that the caller will make sure that we are looking at
vhdl-statement-fwd-re, and are not inside a literal, and that we are not in
the middle of an identifier that just happens to contain a \"statement\"
keyword."
X  (cond
X   ;; "for" ... "generate":
X   ((and (looking-at "f")
X        ;; Make sure it's the start of a parameter specification.
X        (save-excursion
X          (forward-sexp 2)
X          (skip-chars-forward " \t\n")
X          (looking-at "in\\b[^_]"))
X        ;; Make sure it's not an "end for".
X        (save-excursion
X          (backward-sexp)
X          (not (looking-at "end\\s-+\\w"))))
X    t)
X   ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
X   ((and (looking-at "i")
X        ;; Make sure it's not an "end if".
X        (save-excursion
X          (backward-sexp)
X          (not (looking-at "end\\s-+\\w"))))
X    t)
X   ;; "while" ... "loop":
X   ((looking-at "w")
X    t)
X   ))
X  
X
;; Core syntactic movement functions:
X
(defconst vhdl-b-t-b-re
X  (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
X
(defun vhdl-backward-to-block (&optional lim)
X  "Move backward to the previous \"begin\" or \"end\" keyword."
X  (let (foundp)
X    (while (and (not foundp)
X               (re-search-backward vhdl-b-t-b-re lim 'move))
X      (if (or (= (preceding-char) ?_)
X             (vhdl-in-literal lim))
X         (backward-char)
X       (cond
X        ;; "begin" keyword:
X        ((and (looking-at vhdl-begin-fwd-re)
X              (/= (preceding-char) ?_)
X              (vhdl-begin-p lim))
X         (setq foundp 'begin))
X        ;; "end" keyword:
X        ((and (looking-at vhdl-end-fwd-re)
X              (/= (preceding-char) ?_)
X              (vhdl-end-p lim))
X         (setq foundp 'end))
X        ))
X      )
X    foundp
X    ))
X
(defun vhdl-forward-sexp (&optional count lim)
X  "Move forward across one balanced expression (sexp).
With COUNT, do it that many times."
X  (interactive "p")
X  (let ((count (or count 1))
X       (case-fold-search t)
X       end-vec target)
X    (save-excursion
X      (while (> count 0)
X       ;; skip whitespace
X       (skip-chars-forward " \t\n")
X       ;; Check for an unbalanced "end" keyword
X       (if (and (looking-at vhdl-end-fwd-re)
X                (/= (preceding-char) ?_)
X                (not (vhdl-in-literal lim))
X                (vhdl-end-p lim)
X                (not (looking-at "else")))
X           (error
X            "Containing expression ends prematurely in vhdl-forward-sexp"))
X       ;; If the current keyword is a "begin" keyword, then find the
X       ;; corresponding "end" keyword.
X       (if (setq end-vec (vhdl-corresponding-end lim))
X           (let (
X                 ;; end-re is the statement keyword to search for
X                 (end-re
X                  (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
X                 ;; column is either the statement keyword target column
X                 ;; or nil
X                 (column (aref end-vec 1))
X                 (eol (vhdl-point 'eol))
X                 foundp literal placeholder)
X             ;; Look for the statement keyword.
X             (while (and (not foundp)
X                         (re-search-forward end-re nil t)
X                         (setq placeholder (match-end 1))
X                         (goto-char (match-beginning 0)))
X               ;; If we are in a literal, or not in the right target
X               ;; column and not on the same line as the begin, then
X               ;; try again.
X               (if (or (and column
X                            (/= (current-indentation) column)
X                            (> (point) eol))
X                       (= (preceding-char) ?_)
X                       (setq literal (vhdl-in-literal lim)))
X                   (if (eq literal 'comment)
X                       (end-of-line)
X                     (forward-char))
X                 ;; An "else" keyword corresponds to both the opening brace
X                 ;; of the following sexp and the closing brace of the
X                 ;; previous sexp.
X                 (if (not (looking-at "else"))
X                     (goto-char placeholder))
X                 (setq foundp t))
X               )
X             (if (not foundp)
X                 (error "Unbalanced keywords in vhdl-forward-sexp"))
X             )
X         ;; If the current keyword is not a "begin" keyword, then just
X         ;; perform the normal forward-sexp.
X         (forward-sexp)
X         )
X       (setq count (1- count))
X       )
X      (setq target (point)))
X    (goto-char target)
X    nil))
X
(defun vhdl-backward-sexp (&optional count lim)
X  "Move backward across one balanced expression (sexp).
With COUNT, do it that many times.  LIM bounds any required backward
searches."
X  (interactive "p")
X  (let ((count (or count 1))
X       (case-fold-search t)
X       begin-vec target)
X    (save-excursion
X      (while (> count 0)
X       ;; Perform the normal backward-sexp, unless we are looking at
X       ;; "else" - an "else" keyword corresponds to both the opening brace
X       ;; of the following sexp and the closing brace of the previous sexp.
X       (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
X                (/= (preceding-char) ?_)
X                (not (vhdl-in-literal lim)))
X           nil
X         (backward-sexp)
X         (if (and (looking-at vhdl-begin-fwd-re)
X                  (/= (preceding-char) ?_)
X                  (not (vhdl-in-literal lim))
X                  (vhdl-begin-p lim))
X             (error "Containing expression ends prematurely in vhdl-backward-sexp")))
X       ;; If the current keyword is an "end" keyword, then find the
X       ;; corresponding "begin" keyword.
X       (if (and (setq begin-vec (vhdl-corresponding-begin lim))
X                (/= (preceding-char) ?_))
X           (let (
X                 ;; begin-re is the statement keyword to search for
X                 (begin-re
X                  (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
X                 ;; column is either the statement keyword target column
X                 ;; or nil
X                 (column (aref begin-vec 1))
X                 ;; internal-p controls where the statement keyword can
X                 ;; be found.
X                 (internal-p (aref begin-vec 3))
X                 (last-backward (point)) last-forward
X                 foundp literal keyword)
X             ;; Look for the statement keyword.
X             (while (and (not foundp)
X                         (re-search-backward begin-re lim t)
X                         (setq keyword
X                               (buffer-substring (match-beginning 1)
X                                                 (match-end 1))))
X               ;; If we are in a literal or in the wrong column,
X               ;; then try again.
X               (if (or (and column
X                            (and (/= (current-indentation) column)
X                                 ;; possibly accept current-column as
X                                 ;; well as current-indentation.
X                                 (or (not internal-p)
X                                     (/= (current-column) column))))
X                       (= (preceding-char) ?_)
X                       (vhdl-in-literal lim))
X                   (backward-char)
X                 ;; If there is a supplementary keyword, then
X                 ;; search forward for it.
X                 (if (and (setq begin-re (aref begin-vec 2))
X                          (or (not (listp begin-re))
X                              ;; If begin-re is an alist, then find the
X                              ;; element corresponding to the actual
X                              ;; keyword that we found.
X                              (progn
X                                (setq begin-re
X                                      (assoc keyword begin-re))
X                                (and begin-re
X                                     (setq begin-re (cdr begin-re))))))
X                     (and
X                      (setq begin-re
X                            (concat "\\b\\(" begin-re "\\)\\b[^_]"))
X                      (save-excursion
X                        (setq last-forward (point))
X                        ;; Look for the supplementary keyword
X                        ;; (bounded by the backward search start
X                        ;; point).
X                        (while (and (not foundp)
X                                    (re-search-forward begin-re
X                                                       last-backward t)
X                                    (goto-char (match-beginning 1)))
X                          ;; If we are in a literal, then try again.
X                          (if (or (= (preceding-char) ?_)
X                                  (setq literal
X                                        (vhdl-in-literal last-forward)))
X                              (if (eq literal 'comment)
X                                  (goto-char
X                                   (min (vhdl-point 'eol) last-backward))
X                                (forward-char))
X                            ;; We have found the supplementary keyword.
X                            ;; Save the position of the keyword in foundp.
X                            (setq foundp (point)))
X                          )
X                        foundp)
X                      ;; If the supplementary keyword was found, then
X                      ;; move point to the supplementary keyword.
X                      (goto-char foundp))
X                   ;; If there was no supplementary keyword, then
X                   ;; point is already at the statement keyword.
X                   (setq foundp t)))
X               ) ; end of the search for the statement keyword
X             (if (not foundp)
X                 (error "Unbalanced keywords in vhdl-backward-sexp"))
X             ))
X       (setq count (1- count))
X       )
X      (setq target (point)))
X    (goto-char target)
X    nil))
X
(defun vhdl-backward-up-list (&optional count limit)
X  "Move backward out of one level of blocks.
With argument, do this that many times."
X  (interactive "p")
X  (let ((count (or count 1))
X       target)
X    (save-excursion
X      (while (> count 0)
X       (if (looking-at vhdl-defun-re)
X           (error "Unbalanced blocks"))
X       (vhdl-backward-to-block limit)
X       (setq count (1- count)))
X      (setq target (point)))
X    (goto-char target)))
X
(defun vhdl-end-of-defun (&optional count)
X  "Move forward to the end of a VHDL defun."
X  (interactive)
X  (let ((case-fold-search t))
X    (vhdl-beginning-of-defun)
X    (if (not (looking-at "block\\|process"))
X       (re-search-forward "\\bis\\b"))
X    (vhdl-forward-sexp)))
X    
(defun vhdl-mark-defun ()
X  "Put mark at end of this \"defun\", point at beginning."
X  (interactive)
X  (let ((case-fold-search t))
X    (push-mark)
X    (vhdl-beginning-of-defun)
X    (push-mark)
X    (if (not (looking-at "block\\|process"))
X       (re-search-forward "\\bis\\b"))
X    (vhdl-forward-sexp)
X    (exchange-point-and-mark)))
X
(defun vhdl-beginning-of-libunit ()
X  "Move backward to the beginning of a VHDL library unit.
Returns the location of the corresponding begin keyword, unless search
stops due to beginning or end of buffer."
X  ;; Note that if point is between the "libunit" keyword and the
X  ;; corresponding "begin" keyword, then that libunit will not be
X  ;; recognised, and the search will continue backwards.  If point is
X  ;; at the "begin" keyword, then the defun will be recognised.  The
X  ;; returned point is at the first character of the "libunit" keyword.
X  (let ((last-forward (point))
X       (last-backward
X        ;; Just in case we are actually sitting on the "begin"
X        ;; keyword, allow for the keyword and an extra character,
X        ;; as this will be used when looking forward for the
X        ;; "begin" keyword.
X        (save-excursion (forward-word 1) (1+ (point))))
X       foundp literal placeholder)
X    ;; Find the "libunit" keyword.
X    (while (and (not foundp)
X               (re-search-backward vhdl-libunit-re nil 'move))
X      ;; If we are in a literal, or not at a real libunit, then try again.
X      (if (or (= (preceding-char) ?_)
X             (vhdl-in-literal (point-min))
X             (not (vhdl-libunit-p)))
X         (backward-char)
X       ;; Find the corresponding "begin" keyword.
X       (setq last-forward (point))
X       (while (and (not foundp)
X                   (re-search-forward "\\bis\\b[^_]" last-backward t)
X                   (setq placeholder (match-beginning 0)))
X         (if (or (= (preceding-char) ?_)
X                 (setq literal (vhdl-in-literal last-forward)))
X             ;; It wasn't a real keyword, so keep searching.
X             (if (eq literal 'comment)
X                 (goto-char
X                  (min (vhdl-point 'eol) last-backward))
X               (forward-char))
X           ;; We have found the begin keyword, loop will exit.
X           (setq foundp placeholder)))
X       ;; Go back to the libunit keyword
X       (goto-char last-forward)))
X    foundp))
X    
(defun vhdl-beginning-of-defun (&optional count)
X  "Move backward to the beginning of a VHDL defun.
With argument, do it that many times.
Returns the location of the corresponding begin keyword, unless search
stops due to beginning or end of buffer."
X  ;; Note that if point is between the "defun" keyword and the
X  ;; corresponding "begin" keyword, then that defun will not be
X  ;; recognised, and the search will continue backwards.  If point is
X  ;; at the "begin" keyword, then the defun will be recognised.  The
X  ;; returned point is at the first character of the "defun" keyword.
X  (interactive "p")
X  (let ((count (or count 1))
X       (case-fold-search t)
X       (last-forward (point))
X       foundp)
X    (while (> count 0)
X      (setq foundp nil)
X      (goto-char last-forward)
X      (let ((last-backward
X            ;; Just in case we are actually sitting on the "begin"
X            ;; keyword, allow for the keyword and an extra character,
X            ;; as this will be used when looking forward for the
X            ;; "begin" keyword.
X            (save-excursion (forward-word 1) (1+ (point))))
X           begin-string literal)
X       (while (and (not foundp)
X                   (re-search-backward vhdl-defun-re nil 'move))
X         ;; If we are in a literal, then try again.
X         (if (or (= (preceding-char) ?_)
X                 (vhdl-in-literal (point-min)))
X             (backward-char)
X           (if (setq begin-string (vhdl-corresponding-defun))
X               ;; This is a real defun keyword.
X               ;; Find the corresponding "begin" keyword.
X               ;; Look for the begin keyword.
X               (progn
X                 ;; Save the search start point.
X                 (setq last-forward (point))
X                 (while (and (not foundp)
X                             (search-forward begin-string last-backward t))
X                   (if (or (= (preceding-char) ?_)
X                           (save-match-data
X                             (setq literal (vhdl-in-literal last-forward))))
X                       ;; It wasn't a real keyword, so keep searching.
X                       (if (eq literal 'comment)
X                           (goto-char
X                            (min (vhdl-point 'eol) last-backward))
X                         (forward-char))
X                     ;; We have found the begin keyword, loop will exit.
X                     (setq foundp (match-beginning 0)))
X                   )
X                 ;; Go back to the defun keyword
X                 (goto-char last-forward)) ; end search for begin keyword
X             ))
X         ) ; end of the search for the defun keyword
X       )
X      (setq count (1- count))
X      )
X    (vhdl-keep-region-active)
X    foundp))
X    
(defun vhdl-beginning-of-statement (&optional count lim)
X  "Go to the beginning of the innermost VHDL statement.
With prefix arg, go back N - 1 statements.  If already at the
beginning of a statement then go to the beginning of the preceding
one.  If within a string or comment, or next to a comment (only
whitespace between), move by sentences instead of statements.
X
When called from a program, this function takes 2 optional args: the
prefix arg, and a buffer position limit which is the farthest back to
search."
X  (interactive "p")
X  (let ((count (or count 1))
X       (case-fold-search t)
X       (lim (or lim (point-min)))
X       (here (point))
X       state)
X    (save-excursion
X      (goto-char lim)
X      (setq state (parse-partial-sexp (point) here nil nil)))
X    (if (and (interactive-p)
X            (or (nth 3 state)
X                (nth 4 state)
X                (looking-at (concat "[ \t]*" comment-start-skip))))
X       (forward-sentence (- count))
X      (while (> count 0)
X       (vhdl-beginning-of-statement-1 lim)
X       (setq count (1- count))))
X    ;; its possible we've been left up-buf of lim
X    (goto-char (max (point) lim))
X    )
X  (vhdl-keep-region-active))
X
(defconst vhdl-b-o-s-re
X  (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
X         vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
X
(defun vhdl-beginning-of-statement-1 (&optional lim)
X  ;; move to the start of the current statement, or the previous
X  ;; statement if already at the beginning of one.
X  (let ((lim (or lim (point-min)))
X       (here (point))
X       (pos (point))
X       donep)
X    ;; go backwards one balanced expression, but be careful of
X    ;; unbalanced paren being reached
X    (if (not (vhdl-safe (progn (backward-sexp) t)))
X       (progn
X         (backward-up-list 1)
X         (forward-char)
X         (vhdl-forward-syntactic-ws here)
X         (setq donep t)))
X    (while (and (not donep)
X               (not (bobp))
X               ;; look backwards for a statement boundary
X               (re-search-backward vhdl-b-o-s-re lim 'move))
X      (if (or (= (preceding-char) ?_)
X             (vhdl-in-literal lim))
X         (backward-char)
X       (cond
X        ;; If we are looking at an open paren, then stop after it
X        ((eq (following-char) ?\()
X         (forward-char)
X         (vhdl-forward-syntactic-ws here)
X         (setq donep t))
X        ;; If we are looking at a close paren, then skip it
X        ((eq (following-char) ?\))
X         (forward-char)
X         (setq pos (point))
X         (backward-sexp)
X         (if (< (point) lim)
X             (progn (goto-char pos)
X                    (vhdl-forward-syntactic-ws here)
X                    (setq donep t))))
X        ;; If we are looking at a semicolon, then stop
X        ((eq (following-char) ?\;)
X         (progn
X           (forward-char)
X           (vhdl-forward-syntactic-ws here)
X           (setq donep t)))
X        ;; If we are looking at a "begin", then stop
X        ((and (looking-at vhdl-begin-fwd-re)
X              (/= (preceding-char) ?_)
X              (vhdl-begin-p nil))
X         ;; If it's a leader "begin", then find the
X         ;; right place
X         (if (looking-at vhdl-leader-re)
X             (save-excursion
X               ;; set a default stop point at the begin
X               (setq pos (point))
X               ;; is the start point inside the leader area ?
X               (goto-char (vhdl-end-of-leader))
X               (vhdl-forward-syntactic-ws here)
X               (if (< (point) here)
X                   ;; start point was not inside leader area
X                   ;; set stop point at word after leader
X                   (setq pos (point))))
X           (forward-word 1)
X           (vhdl-forward-syntactic-ws here)
X           (setq pos (point)))
X         (goto-char pos)
X         (setq donep t))
X        ;; If we are looking at a "statement", then stop
X        ((and (looking-at vhdl-statement-fwd-re)
X              (/= (preceding-char) ?_)
X              (vhdl-statement-p nil))
X         (setq donep t))
X        ;; If we are looking at a case alternative key, then stop
X        ((looking-at vhdl-case-alternative-key)
X         (save-excursion
X           ;; set a default stop point at the when
X           (setq pos (point))
X           ;; is the start point inside the case alternative key ?
X           (goto-char (match-end 0))
X           (vhdl-forward-syntactic-ws here)
X           (if (< (point) here)
X               ;; start point was not inside the case alternative key
X               ;; set stop point at word after case alternative keyleader
X               (setq pos (point))))
X         (goto-char pos)
X         (setq donep t))
X        ;; Bogus find, continue
X        (t
X         (backward-char)))))
X    ))
X
X
;; Defuns for calculating the current syntactic state:
X
(defun vhdl-get-library-unit (bod placeholder)
X  ;; If there is an enclosing library unit at bod, with it's \"begin\"
X  ;; keyword at placeholder, then return the library unit type.
X  (let ((here (vhdl-point 'bol)))
X    (if (save-excursion
X         (goto-char placeholder)
X         (vhdl-safe (vhdl-forward-sexp 1 bod))
X         (<= here (point)))
X       (save-excursion
X         (goto-char bod)
X         (cond
X          ((looking-at "e") 'entity)
X          ((looking-at "a") 'architecture)
X          ((looking-at "c") 'configuration)
X          ((looking-at "p")
X           (save-excursion
X             (goto-char bod)
X             (forward-sexp)
X             (vhdl-forward-syntactic-ws here)
X             (if (looking-at "body\\b[^_]")
X                 'package-body 'package))))))
X    ))
X
(defun vhdl-get-block-state (&optional lim)
X  ;; Finds and records all the closest opens.
X  ;; lim is the furthest back we need to search (it should be the
X  ;; previous libunit keyword).
X  (let ((here (point))
X       (lim (or lim (point-min)))
X       keyword sexp-start sexp-mid sexp-end
X       preceding-sexp containing-sexp
X       containing-begin containing-mid containing-paren)
X    (save-excursion
X      ;; Find the containing-paren, and use that as the limit
X      (if (setq containing-paren
X               (save-restriction
X                 (narrow-to-region lim (point))
X                 (vhdl-safe (scan-lists (point) -1 1))))
X         (setq lim containing-paren))
X      ;; Look backwards for "begin" and "end" keywords.
X      (while (and (> (point) lim)
X                 (not containing-sexp))
X       (setq keyword (vhdl-backward-to-block lim))
X       (cond
X        ((eq keyword 'begin)
X         ;; Found a "begin" keyword
X         (setq sexp-start (point))
X         (setq sexp-mid (vhdl-corresponding-mid lim))
X         (setq sexp-end (vhdl-safe
X                         (save-excursion
X                           (vhdl-forward-sexp 1 lim) (point))))
X         (if (and sexp-end (<= sexp-end here))
X             ;; we want to record this sexp, but we only want to
X             ;; record the last-most of any of them before here
X             (or preceding-sexp
X                 (setq preceding-sexp sexp-start))
X           ;; we're contained in this sexp so put sexp-start on
X           ;; front of list
X           (setq containing-sexp sexp-start)
X           (setq containing-mid sexp-mid)
X           (setq containing-begin t)))
X        ((eq keyword 'end)
X         ;; Found an "end" keyword
X         (forward-sexp)
X         (setq sexp-end (point))
X         (setq sexp-mid nil)
X         (setq sexp-start
X               (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
X                   (progn (backward-sexp) (point))))
X         ;; we want to record this sexp, but we only want to
X         ;; record the last-most of any of them before here
X         (or preceding-sexp
X             (setq preceding-sexp sexp-start)))
X        )))
X    ;; Check if the containing-paren should be the containing-sexp
X    (if (and containing-paren
X            (or (null containing-sexp)
X                (< containing-sexp containing-paren)))
X       (setq containing-sexp containing-paren
X             preceding-sexp nil
X             containing-begin nil
X             containing-mid nil))
X    (vector containing-sexp preceding-sexp containing-begin containing-mid)
X    ))
X            
X
(defconst vhdl-s-c-a-re
X  (concat vhdl-case-alternative-key "\\|" vhdl-case-header-key))
X
(defun vhdl-skip-case-alternative (&optional lim)
X  ;; skip forward over case/when bodies, with optional maximal
X  ;; limit. if no next case alternative is found, nil is returned and point
X  ;; is not moved
X  (let ((lim (or lim (point-max)))
X       (here (point))
X       donep foundp)
X    (while (and (< (point) lim)
X               (not donep))
X      (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
X              (save-match-data
X                (not (vhdl-in-literal)))
X              (/= (match-beginning 0) here))
X         (progn
X           (goto-char (match-beginning 0))
X           (cond
X            ((and (looking-at "case")
X                  (re-search-forward "\\bis[^_]" lim t))
X             (backward-sexp)
X             (vhdl-forward-sexp))
X            (t
X             (setq donep t
X                   foundp t))))))
X    (if (not foundp)
X       (goto-char here))
X    foundp))
X
(defun vhdl-backward-skip-label (&optional lim)
X  ;; skip backward over a label, with optional maximal
X  ;; limit. if label is found, nil is returned and point
X  ;; is not moved
X  (let ((lim (or lim (point-min)))
X       placeholder)
X    (if (save-excursion
X         (vhdl-backward-syntactic-ws lim)
X         (and (eq (preceding-char) ?:)
X              (progn
X                (backward-sexp)
X                (setq placeholder (point))
X                (looking-at vhdl-label-key))))
X       (goto-char placeholder))
X    ))
X
(defun vhdl-get-syntactic-context ()
X  ;; guess the syntactic description of the current line of VHDL code.
X  (save-excursion
X    (save-restriction
X      (beginning-of-line)
X      (let* ((indent-point (point))
X            (case-fold-search t)
X            vec literal containing-sexp preceding-sexp
X            containing-begin containing-mid containing-leader
X            char-before-ip char-after-ip begin-after-ip end-after-ip
X            placeholder lim library-unit
X           )
X
X       ;; Reset the syntactic context
X       (setq vhdl-syntactic-context nil)
X
X       (save-excursion
X         ;; Move to the start of the previous library unit, and
X         ;; record the position of the "begin" keyword.
X         (setq placeholder (vhdl-beginning-of-libunit))
X         ;; The position of the "libunit" keyword gives us a gross
X         ;; limit point.
X         (setq lim (point))
X         )
X
X       ;; If there is a previous library unit, and we are enclosed by
X       ;; it, then set the syntax accordingly.
X       (and placeholder
X            (setq library-unit (vhdl-get-library-unit lim placeholder))
X            (vhdl-add-syntax library-unit lim))
X          
X       ;; Find the surrounding state.
X       (if (setq vec (vhdl-get-block-state lim))
X           (progn
X             (setq containing-sexp (aref vec 0))
X             (setq preceding-sexp (aref vec 1))
X             (setq containing-begin (aref vec 2))
X             (setq containing-mid (aref vec 3))
X             ))
X
X       ;; set the limit on the farthest back we need to search
X       (setq lim (if containing-sexp
X                     (save-excursion
X                       (goto-char containing-sexp)
X                       ;; set containing-leader if required
X                       (if (looking-at vhdl-leader-re)
X                           (setq containing-leader (vhdl-end-of-leader)))
X                       (vhdl-point 'bol))
X                   (point-min)))
X
X       ;; cache char before and after indent point, and move point to
X       ;; the most likely position to perform the majority of tests
X       (goto-char indent-point)
X       (skip-chars-forward " \t")
X       (setq literal (vhdl-in-literal lim))
X       (setq char-after-ip (following-char))
X       (setq begin-after-ip (and
X                             (not literal)
X                             (looking-at vhdl-begin-fwd-re)
X                             (vhdl-begin-p)))
X       (setq end-after-ip (and
X                           (not literal)
X                           (looking-at vhdl-end-fwd-re)
X                           (vhdl-end-p)))
X       (vhdl-backward-syntactic-ws lim)
X       (setq char-before-ip (preceding-char))
X       (goto-char indent-point)
X       (skip-chars-forward " \t")
X
X       ;; now figure out syntactic qualities of the current line
X       (cond
X        ;; CASE 1: in a string or comment.
X        ((memq literal '(string comment))
X         (vhdl-add-syntax literal (vhdl-point 'bopl)))
X        ;; CASE 2: Line is at top level.
X        ((null containing-sexp)
X         ;; Find the point to which indentation will be relative
X         (save-excursion
X           (if (null preceding-sexp)
X               ;; CASE 2X.1
X               ;; no preceding-sexp -> use the preceding statement
X               (vhdl-beginning-of-statement-1 lim)
X             ;; CASE 2X.2
X             ;; if there is a preceding-sexp then indent relative to it
X             (goto-char preceding-sexp)
X             ;; if not at boi, then the block-opening keyword is
X             ;; probably following a label, so we need a different
X             ;; relpos
X             (if (/= (point) (vhdl-point 'boi))
X                 ;; CASE 2X.3
X                 (vhdl-beginning-of-statement-1 lim)))
X           ;; v-b-o-s could have left us at point-min
X           (and (bobp)
X                ;; CASE 2X.4
X                (vhdl-forward-syntactic-ws indent-point))
X           (setq placeholder (point)))
X         (cond
X          ;; CASE 2A : we are looking at a block-open
X          (begin-after-ip
X           (vhdl-add-syntax 'block-open placeholder))
X          ;; CASE 2B: we are looking at a block-close
X          (end-after-ip
X           (vhdl-add-syntax 'block-close placeholder))
X          ;; CASE 2C: we are looking at a top-level statement
X          ((progn
X             (vhdl-backward-syntactic-ws lim)
X             (or (bobp)
X                 (= (preceding-char) ?\;)))
X           (vhdl-add-syntax 'statement placeholder))
X          ;; CASE 2D: we are looking at a top-level statement-cont
X          (t
X           (vhdl-beginning-of-statement-1 lim)
X           ;; v-b-o-s could have left us at point-min
X           (and (bobp)
X                ;; CASE 2D.1
X                (vhdl-forward-syntactic-ws indent-point))
X           (vhdl-add-syntax 'statement-cont (point)))
X          )) ; end CASE 2
X        ;; CASE 3: line is inside parentheses.  Most likely we are
X        ;; either in a subprogram argument (interface) list, or a
X        ;; continued expression containing parentheses.
X        ((null containing-begin)
X         (vhdl-backward-syntactic-ws containing-sexp)
X         (cond
X          ;; CASE 3A: we are looking at the arglist closing paren
X          ((eq char-after-ip ?\))
X           (goto-char containing-sexp)
X           (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
X          ;; CASE 3B: we are looking at the first argument in an empty
X          ;; argument list.
X          ((eq char-before-ip ?\()
X           (goto-char containing-sexp)
X           (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
X          ;; CASE 3C: we are looking at an arglist continuation line,
X          ;; but the preceding argument is on the same line as the
X          ;; opening paren.  This case includes multi-line
X          ;; expression paren groupings.
X          ((and (save-excursion
X                  (goto-char (1+ containing-sexp))
X                  (skip-chars-forward " \t")
X                  (not (eolp))
X                  (not (looking-at "--")))
X                (save-excursion
X                  (vhdl-beginning-of-statement-1 containing-sexp)
X                  (skip-chars-backward " \t(")
X                  (<= (point) containing-sexp)))
X           (goto-char containing-sexp)
X           (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
X          ;; CASE 3D: we are looking at just a normal arglist
X          ;; continuation line
X          (t (vhdl-beginning-of-statement-1 containing-sexp)
X             (vhdl-forward-syntactic-ws indent-point)
X             (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
X          ))
X        ;; CASE 4: A block mid open
X        ((and begin-after-ip
X              (looking-at containing-mid))
X         (goto-char containing-sexp)
X         ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
X         (if (looking-at vhdl-trailer-re)
X             ;; CASE 4.1
X             (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
X         (vhdl-backward-skip-label (vhdl-point 'boi))
X         (vhdl-add-syntax 'block-open (point)))
X        ;; CASE 5: block close brace
X        (end-after-ip
X         (goto-char containing-sexp)
X         ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
X         (if (looking-at vhdl-trailer-re)
X             ;; CASE 5.1
X             (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
X         (vhdl-backward-skip-label (vhdl-point 'boi))
X         (vhdl-add-syntax 'block-close (point)))
X        ;; CASE 6: A continued statement
X        ((and (/= char-before-ip ?\;)
X              ;; check it's not a trailer begin keyword, or a begin
X              ;; keyword immediately following a label.
X              (not (and begin-after-ip
X                        (or (looking-at vhdl-trailer-re)
X                            (save-excursion
X                              (vhdl-backward-skip-label containing-sexp)))))
X              ;; check it's not a statement keyword
X              (not (and (looking-at vhdl-statement-fwd-re)
X                        (vhdl-statement-p)))
X              ;; see if the b-o-s is before the indent point
X              (> indent-point
X                 (save-excursion
X                   (vhdl-beginning-of-statement-1 containing-sexp)
X                   ;; If we ended up after a leader, then this will
X                   ;; move us forward to the start of the first
X                   ;; statement.  Note that a containing sexp here is
X                   ;; always a keyword, not a paren, so this will
X                   ;; have no effect if we hit the containing-sexp.
X                   (vhdl-forward-syntactic-ws indent-point)
X                   (setq placeholder (point))))
X              ;; check it's not a block-intro
X              (/= placeholder containing-sexp)
X              ;; check it's not a case block-intro
X              (save-excursion
X                (goto-char placeholder)
X                (or (not (looking-at vhdl-case-alternative-key))
X                    (> (match-end 0) indent-point))))
X         (vhdl-add-syntax 'statement-cont placeholder)
X         (if begin-after-ip
X             (vhdl-add-syntax 'block-open)))
X        ;; Statement. But what kind?
X        ;; CASE 7: A case alternative key
X        ((looking-at vhdl-case-alternative-key)
X         ;; for a case alternative key, we set relpos to the first
X         ;; non-whitespace char on the line containing the "case"
X         ;; keyword.
X         (goto-char containing-sexp)
X         ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
X         (if (looking-at vhdl-trailer-re)
X             (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
X         (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
X        ;; CASE 8: statement catchall
X        (t
X         ;; we know its a statement, but we need to find out if it is
X         ;; the first statement in a block
X         (if containing-leader
X             (goto-char containing-leader)
X           (goto-char containing-sexp)
X           ;; Note that a containing sexp here is always a keyword,
X           ;; not a paren, so skip over the keyword.
X           (forward-sexp))
X         ;; move to the start of the first statement
X         (vhdl-forward-syntactic-ws indent-point)
X         (setq placeholder (point))
X         ;; we want to ignore case alternatives keys when skipping forward
X         (let (incase-p)
X           (while (looking-at vhdl-case-alternative-key)
X             (setq incase-p (point))
X             ;; we also want to skip over the body of the
X             ;; case/when statement if that doesn't put us at
X             ;; after the indent-point
X             (while (vhdl-skip-case-alternative indent-point))
X             ;; set up the match end
X             (looking-at vhdl-case-alternative-key)
X             (goto-char (match-end 0))
X             ;; move to the start of the first case alternative statement
X             (vhdl-forward-syntactic-ws indent-point)
X             (setq placeholder (point)))
X           (cond
X            ;; CASE 8A: we saw a case/when statement so we must be
X            ;; in a switch statement.  find out if we are at the
X            ;; statement just after a case alternative key
X            ((and incase-p
X                  (= (point) indent-point))
X             ;; relpos is the "when" keyword
X             (vhdl-add-syntax 'statement-case-intro incase-p))
X            ;; CASE 8B: any old statement
X            ((< (point) indent-point)
X             ;; relpos is the first statement of the block
X             (vhdl-add-syntax 'statement placeholder)
X             (if begin-after-ip
X                 (vhdl-add-syntax 'block-open)))
X            ;; CASE 8C: first statement in a block
X            (t
X             (goto-char containing-sexp)
X             ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
X             (if (looking-at vhdl-trailer-re)
X                 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
X             (vhdl-backward-skip-label (vhdl-point 'boi))
X             (vhdl-add-syntax 'statement-block-intro (point))
X             (if begin-after-ip
X                 (vhdl-add-syntax 'block-open)))
X            )))
X        )
X
X       ;; now we need to look at any modifiers
X       (goto-char indent-point)
X       (skip-chars-forward " \t")
X       (if (looking-at "--")
X           (vhdl-add-syntax 'comment))
X       ;; return the syntax
X       vhdl-syntactic-context))))
X
X
;; Standard indentation line-ups:
X
(defun vhdl-lineup-arglist (langelem)
X  ;; lineup the current arglist line with the arglist appearing just
X  ;; after the containing paren which starts the arglist.
X  (save-excursion
X    (let* ((containing-sexp
X           (save-excursion
X             ;; arglist-cont-nonempty gives relpos ==
X             ;; to boi of containing-sexp paren. This
X             ;; is good when offset is +, but bad
X             ;; when it is vhdl-lineup-arglist, so we
X             ;; have to special case a kludge here.
X             (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
X                 (progn
X                   (beginning-of-line)
X                   (backward-up-list 1)
X                   (skip-chars-forward " \t" (vhdl-point 'eol)))
X               (goto-char (cdr langelem)))
X             (point)))
X          (cs-curcol (save-excursion
X                       (goto-char (cdr langelem))
X                       (current-column))))
X      (if (save-excursion
X           (beginning-of-line)
X           (looking-at "[ \t]*)"))
X         (progn (goto-char (match-end 0))
X                (backward-sexp)
X                (forward-char)
X                (vhdl-forward-syntactic-ws)
X                (- (current-column) cs-curcol))
X       (goto-char containing-sexp)
X       (or (eolp)
X           (let ((eol (vhdl-point 'eol))
X                 (here (progn
X                         (forward-char)
X                         (skip-chars-forward " \t")
X                         (point))))
X             (vhdl-forward-syntactic-ws)
X             (if (< (point) eol)
X                 (goto-char here))))
X       (- (current-column) cs-curcol)
X       ))))
X
(defun vhdl-lineup-arglist-intro (langelem)
X  ;; lineup an arglist-intro line to just after the open paren
X  (save-excursion
X    (let ((cs-curcol (save-excursion
X                      (goto-char (cdr langelem))
X                      (current-column)))
X         (ce-curcol (save-excursion
X                      (beginning-of-line)
X                      (backward-up-list 1)
X                      (skip-chars-forward " \t" (vhdl-point 'eol))
X                      (current-column))))
X      (- ce-curcol cs-curcol -1))))
X
(defun vhdl-lineup-comment (langelem)
X  ;; support old behavior for comment indentation. we look at
X  ;; vhdl-comment-only-line-offset to decide how to indent comment
X  ;; only-lines
X  (save-excursion
X    (back-to-indentation)
X    ;; at or to the right of comment-column
X    (if (>= (current-column) comment-column)
X       (vhdl-comment-indent)
X      ;; otherwise, indent as specified by vhdl-comment-only-line-offset
X      (if (not (bolp))
X         (or (car-safe vhdl-comment-only-line-offset)
X             vhdl-comment-only-line-offset)
X       (or (cdr-safe vhdl-comment-only-line-offset)
X           (car-safe vhdl-comment-only-line-offset)
X           -1000                       ;jam it against the left side
X           )))))
X
(defun vhdl-lineup-statement-cont (langelem)
X  ;; line up statement-cont after the assignment operator
X  (save-excursion
X    (let* ((relpos (cdr langelem))
X          (assignp (save-excursion
X                    (goto-char (vhdl-point 'boi))
X                    (and (re-search-forward "\\(<\\|:\\)="
X                                            (vhdl-point 'eol) t)
X                         (- (point) (vhdl-point 'boi)))))
X          (curcol (progn
X                    (goto-char relpos)
X                    (current-column)))
X          foundp)
X      (while (and (not foundp)
X                 (< (point) (vhdl-point 'eol)))
X       (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
X       (if (vhdl-in-literal (cdr langelem))
X           (forward-char)
X         (if (= (preceding-char) ?\()
X             ;; skip over any parenthesized expressions
X             (goto-char (min (vhdl-point 'eol)
X                             (scan-lists (point) 1 1)))
X           ;; found an assignment operator (not at eol)
X           (setq foundp (not (looking-at "\\s-*$"))))))
X      (if (not foundp)
X         ;; there's no assignment operator on the line
X         vhdl-basic-offset
X       ;; calculate indentation column after assign and ws, unless
X       ;; our line contains an assignment operator
X       (if (not assignp)
X           (progn
X             (forward-char)
X             (skip-chars-forward " \t")
X             (setq assignp 0)))
X       (- (current-column) assignp curcol))
X      )))
X
X
;; Indentation commands:
X
;; This is used by indent-for-comment to decide how much to indent a
;; comment in VHDL code based on its context.
(defun vhdl-comment-indent ()
X  (if (looking-at (concat "^--"))
X      0                                ;Existing comment at bol stays there.
X    (let ((opoint (point))
X         placeholder)
X      (save-excursion
X       (beginning-of-line)
X       (cond
X        ;; CASE 1: use comment-column if previous line is a
X        ;; comment-only line indented to the left of comment-column
X        ((save-excursion
X           (beginning-of-line)
X           (and (not (bobp))
X                (forward-line -1))
X           (skip-chars-forward " \t")
X           (prog1
X               (looking-at "--")
X             (setq placeholder (point))))
X         (goto-char placeholder)
X         (if (< (current-column) comment-column)
X             comment-column
X           (current-column)))
X        ;; CASE 2: If comment-column is 0, and nothing but space
X        ;; before the comment, align it at 0 rather than 1.
X        ((progn
X           (goto-char opoint)
X           (skip-chars-backward " \t")
X           (and (= comment-column 0) (bolp)))
X         0)
X        ;; CASE 3: indent at comment column except leave at least one
X        ;; space.
X        (t (max (1+ (current-column))
X                comment-column))
X        )))))
X
(defun vhdl-indent-line ()
X  ;; indent the current line as VHDL code. Returns the amount of
X  ;; indentation change
X  (let* ((syntax (vhdl-get-syntactic-context))
X        (pos (- (point-max) (point)))
X        (indent (apply '+ (mapcar 'vhdl-get-offset syntax)))
X        (shift-amt  (- (current-indentation) indent)))
X    (and vhdl-echo-syntactic-information-p
X        (message "syntax: %s, indent= %d" syntax indent))
X    (if (zerop shift-amt)
X       nil
X      (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
X      (beginning-of-line)
X      (indent-to indent))
X    (if (< (point) (vhdl-point 'boi))
X       (back-to-indentation)
X      ;; If initial point was within line's indentation, position after
X      ;; the indentation.  Else stay at same point in text.
X      (if (> (- (point-max) pos) (point))
X         (goto-char (- (point-max) pos)))
X      )
X    (run-hooks 'vhdl-special-indent-hook)
X    shift-amt))
X
(defun vhdl-indent-command (&optional whole-exp)
X  "Indent current line as VHDL code, or in some cases insert a tab character.
X
If `vhdl-tab-always-indent' is t, always just indent the current line.
If nil, indent the current line only if point is at the left margin or
in the line's indentation; otherwise insert a tab.  If other than nil
or t, then tab is inserted only within literals (comments and strings)
and inside preprocessor directives, but line is always reindented.
X
A numeric argument, regardless of its value, means indent rigidly all
the lines of the expression starting after point so that this line
becomes properly indented.  The relative indentation among the lines
of the expression are preserved."
X  (interactive "P")
X  (if whole-exp
X      ;; If arg, always indent this line as VHDL
X      ;; and shift remaining lines of expression the same amount.
X      (let ((shift-amt (vhdl-indent-line))
X           beg end)
X       (save-excursion
X         (if (eq vhdl-tab-always-indent t)
X             (beginning-of-line))
X         (setq beg (point))
X         (forward-sexp)
X         (setq end (point))
X         (goto-char beg)
X         (forward-line 1)
X         (setq beg (point)))
X       (if (> end beg)
X           (indent-code-rigidly beg end (- shift-amt))))
X    ;; No arg supplied, use vhdl-tab-always-indent to determine
X    ;; behavior
X    (cond
X     ;; CASE 1: indent when at column zero or in lines indentation,
X     ;; otherwise insert a tab
X     ((not vhdl-tab-always-indent)
X      (if (save-excursion
X           (skip-chars-backward " \t")
X           (not (bolp)))
X         (insert-tab)
X       (vhdl-indent-line)))
X     ;; CASE 2: just indent the line
X     ((eq vhdl-tab-always-indent t)
X      (vhdl-indent-line))
X     ;; CASE 3: if in a literal, insert a tab, but always indent the
X     ;; line
X     (t
X      (if (vhdl-in-literal (vhdl-point 'bod))
X         (insert-tab))
X      (vhdl-indent-line)
X      ))))
X
(defun vhdl-indent-sexp (&optional endpos)
X  "Indent each line of the list starting just after point.
If optional arg ENDPOS is given, indent each line, stopping when
ENDPOS is encountered.  (interactive)"
X  (interactive)
X  (save-excursion
X    (let ((beg (point))
X         (end (progn
X                (vhdl-forward-sexp nil endpos)
X                (point))))
X      (indent-region beg end nil))))
X
(defun vhdl-show-syntactic-information ()
X  "Show syntactic information for current line."
X  (interactive)
X  (message "syntactic analysis: %s" (vhdl-get-syntactic-context))
X  (vhdl-keep-region-active))
X
X
;; Verification and regression functions:
X
(defun vhdl-regress-line (&optional arg)
X  "Check syntactic information for current line."
X  (interactive "P")
X  (let ((expected (save-excursion
X                   (end-of-line)
X                   (if (search-backward " -- ((" (vhdl-point 'bol) t)
X                       (progn
X                         (forward-char 4)
X                         (read (current-buffer))))))
X       (actual (vhdl-get-syntactic-context))
X       (expurgated))
X    ;; remove the library unit symbols
X    (mapcar
X     (function
X      (lambda (elt)
X       (if (memq (car elt) '(entity configuration package
X                                    package-body architecture))
X           nil
X         (setq expurgated (append expurgated (list elt))))))
X     actual)
X    (if (and (not arg) expected (listp expected))
X       (if (not (equal expected expurgated))
X           (error "Should be: %s, is: %s" expected expurgated))
X      (save-excursion
X       (beginning-of-line)
X       (if (not (looking-at "^\\s-*\\(--.*\\)?$"))
X           (progn
X             (end-of-line)
X             (if (search-backward " -- ((" (vhdl-point 'bol) t)
X                 (kill-line))
X             (insert " -- ")
X             (insert (format "%s" expurgated)))))))
X  (vhdl-keep-region-active))
X
(defun test-vhdl-get-block-state ()
X  (interactive)
X  (let ((case-fold-search t)
X       here vec (delay 0.5))
X    (setq here (point))
X    (message "%s" (prin1-to-string (setq vec (vhdl-get-block-state))))
X    (and (aref vec 0)
X        (goto-char (aref vec 0))
X        (sit-for delay))
X    (and (aref vec 1)
X        (goto-char (aref vec 1))
X        (sit-for delay))
X    (goto-char here)
X    ))
X
;; Support for Barry Warsaw's elp (emacs lisp profiler) package:
X
(setq elp-all-instrumented-list nil)
(setq elp-function-list
X      '(
X       vhdl-indent-command
X       vhdl-indent-line
X       vhdl-comment-indent
X       vhdl-lineup-statement-cont
X       vhdl-lineup-comment
X       vhdl-lineup-arglist-intro
X       vhdl-lineup-arglist
X       vhdl-get-syntactic-context
X       vhdl-skip-case-alternative
X       vhdl-get-block-state
X       vhdl-get-library-unit
X       vhdl-beginning-of-statement
X       vhdl-beginning-of-statement-1
X       vhdl-beginning-of-defun
X       vhdl-beginning-of-libunit
X       vhdl-backward-sexp
X       vhdl-forward-sexp
X       vhdl-backward-to-block
X       vhdl-statement-p
X       vhdl-end-of-leader
X       vhdl-corresponding-begin
X       vhdl-end-p
X       vhdl-corresponding-end
X       vhdl-corresponding-mid
X       vhdl-begin-p
X       vhdl-corresponding-defun
X       vhdl-defun-p
X       vhdl-libunit-p
X       vhdl-last-word
X       vhdl-first-word
X       vhdl-backward-syntactic-ws
X       vhdl-forward-syntactic-ws
X       vhdl-in-literal
X       vhdl-keep-region-active
X       ))
X
;; (elp-instrument-list elp-function-list)
X
(defun vhdl-trace-all-functions ()
X  (interactive)
X  (let ((list elp-function-list))
X    (while list
X      (trace-function-background (car list))
X      (setq list (cdr list)))))
X
X
;; Defuns for submitting bug reports:
X
(defconst vhdl-version "$Revision: 2.71 $"
X  "vhdl-mode version number.")

X  "Address accepting submission of bug reports.")
X
(defun vhdl-version ()
X  "Echo the current version of vhdl-mode in the minibuffer."
X  (interactive)
X  (message "Using vhdl-mode %s" vhdl-version)
X  (vhdl-keep-region-active))
X
;; get reporter-submit-bug-report when byte-compiling
(and (fboundp 'eval-when-compile)
X     (eval-when-compile
X      (require 'reporter)))
X
(defun vhdl-submit-bug-report ()
X  "Submit via mail a bug report on vhdl-mode."
X  (interactive)
X  ;; load in reporter
X  (and
X   (y-or-n-p "Do you want to submit a report on vhdl-mode? ")
X   (require 'reporter)
X   (reporter-submit-bug-report
X    vhdl-mode-help-address
X    (concat "vhdl-mode " vhdl-version)
X    (list
X     ;; report only the vars that affect indentation
X     'vhdl-basic-offset
X     'vhdl-offsets-alist
X     'vhdl-comment-only-line-offset
X     'vhdl-tab-always-indent
X     'tab-width
X     )
X    (function
X     (lambda ()
X       (insert
X       (if vhdl-special-indent-hook

X                   "vhdl-special-indent-hook is set to '"
X                   (format "%s" vhdl-special-indent-hook)
X                   ".\nPerhaps this is your problem?\n"

X         "\n")
X       (format "vhdl-emacs-features: %s\n" vhdl-emacs-features)
X       )))
X    nil
X    "Dear Rod,"
X    )))
X
(provide 'vhdl-mode)
;;; vhdl-mode.el ends here
SHAR_EOF
  $shar_touch -am 0928170095 'vhdl-mode.el' &&
  chmod 0444 'vhdl-mode.el' ||
  echo 'restore of vhdl-mode.el failed'
  shar_count="`wc -c < 'vhdl-mode.el'`"
  test 91988 -eq "$shar_count" ||
    echo "vhdl-mode.el: original size 91988, current size $shar_count"
fi
# ============= vhdl-mode.texi ==============
if test -f 'vhdl-mode.texi' && test X"$1" != X"-c"; then
  echo 'x - skipping vhdl-mode.texi (file already exists)'
else
  echo 'x - extracting vhdl-mode.texi (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'vhdl-mode.texi' &&




X

X





X


X



X


X


* Introduction::                
* Getting Connected::          
* New Indentation Engine::
* Customizing Indentation::
* Syntactic Symbols::
* Indentation Commands::
* Frequently Asked Questions::
* Getting the latest vhdl-mode release::
* Sample .emacs File::
* Requirements::                
* Limitations and Known Bugs::  
* Mailing Lists and Submitting Bug Reports::  
* Concept Index::              
* Command Index::               Command Index
* Key Index::                   Key Index



X

editing files containing VHDL code.  
X
This manual will describe the following:
X ...

read more »



Mon, 16 Mar 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Emacs VHDL editing mode (vhdl-mode.el version 2.74)

2. Emacs VHDL editing mode (vhdl-mode.el version 2.56.1.1)

3. Emacs VHDL editing mode (vhdl-mode.el version 2.56.1.1)

4. VHDL mode for Emacs (vhdl-mode.el version 2.50)

5. Free VHDL Editor: Emacs VHDL Mode 3.28

6. VHDL-AMS support in Emacs VHDL Mode

7. VHDL mode for emacs (Really: Structural VHDL code...)

8. Xemacs VHDL mode (vhdl.zip file, 83 Kbytes) - vhdl.zip (1/1)

9. Much improved version of GNU Emacs Eiffel editing mode

10. vhdl-mode.el Homepage...

11. vhdl-mode.el for GNUemacs

12. New EMACS mode for VHDL/Verilog

 

 
Powered by phpBB® Forum Software