Function: vhdl-backward-sexp
vhdl-backward-sexp is an interactive and byte-compiled function
defined in vhdl-mode.el.gz.
Signature
(vhdl-backward-sexp &optional COUNT LIM)
Documentation
Move backward across one balanced expression (sexp).
With COUNT, do it that many times. LIM bounds any required backward searches.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/vhdl-mode.el.gz
(defun vhdl-backward-sexp (&optional count lim)
"Move backward across one balanced expression (sexp).
With COUNT, do it that many times. LIM bounds any required backward
searches."
(interactive "p")
(let ((count (or count 1))
(case-fold-search t)
begin-vec target)
(save-excursion
(while (> count 0)
;; Perform the normal backward-sexp, unless we are looking at
;; "else" - an "else" keyword corresponds to both the opening brace
;; of the following sexp and the closing brace of the previous sexp.
(if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
(/= (preceding-char) ?_)
(not (vhdl-in-literal)))
nil
(backward-sexp)
(if (and (looking-at vhdl-begin-fwd-re)
(or (not (looking-at "\\<use\\>"))
(save-excursion
(back-to-indentation)
(looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
(/= (preceding-char) ?_)
(not (vhdl-in-literal))
(vhdl-begin-p lim))
(error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
;; If the current keyword is an "end" keyword, then find the
;; corresponding "begin" keyword.
(if (and (setq begin-vec (vhdl-corresponding-begin lim))
(/= (preceding-char) ?_))
(let (
;; begin-re is the statement keyword to search for
(begin-re
(concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
;; column is either the statement keyword target column
;; or nil
(column (aref begin-vec 1))
;; internal-p controls where the statement keyword can
;; be found.
(internal-p (aref begin-vec 3))
(last-backward (point)) ;; last-forward
foundp literal keyword)
;; Look for the statement keyword.
(while (and (not foundp)
(re-search-backward begin-re lim t)
(setq keyword
(buffer-substring (match-beginning 1)
(match-end 1))))
;; If we are in a literal or in the wrong column,
;; then try again.
(if (or (and column
(and (/= (current-indentation) column)
;; possibly accept current-column as
;; well as current-indentation.
(or (not internal-p)
(/= (current-column) column))))
(= (preceding-char) ?_)
(vhdl-in-literal))
(backward-char)
;; If there is a supplementary keyword, then
;; search forward for it.
(if (and (setq begin-re (aref begin-vec 2))
(or (not (listp begin-re))
;; If begin-re is an alist, then find the
;; element corresponding to the actual
;; keyword that we found.
(progn
(setq begin-re
(assoc keyword begin-re))
(and begin-re
(setq begin-re (cdr begin-re))))))
(and
(setq begin-re
(concat "\\b\\(" begin-re "\\)\\b[^_]"))
(save-excursion
;; (setq last-forward (point))
;; Look for the supplementary keyword
;; (bounded by the backward search start
;; point).
(while (and (not foundp)
(re-search-forward begin-re
last-backward t)
(goto-char (match-beginning 1)))
;; If we are in a literal, then try again.
(if (or (= (preceding-char) ?_)
(setq literal
(vhdl-in-literal)))
(if (eq literal 'comment)
(goto-char
(min (vhdl-point 'eol) last-backward))
(forward-char))
;; We have found the supplementary keyword.
;; Save the position of the keyword in foundp.
(setq foundp (point)))
)
foundp)
;; If the supplementary keyword was found, then
;; move point to the supplementary keyword.
(goto-char foundp))
;; If there was no supplementary keyword, then
;; point is already at the statement keyword.
(setq foundp t)))
) ; end of the search for the statement keyword
(if (not foundp)
(error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
))
(setq count (1- count))
)
(setq target (point)))
(goto-char target)
nil))