Function: vhdl-electric-tab

vhdl-electric-tab is an interactive and byte-compiled function defined in vhdl-mode.el.gz.

Signature

(vhdl-electric-tab &optional ARG)

Documentation

If preceding character is part of a word or a paren then hippie-expand, else if right of non whitespace on line then insert tab, else if last command was a tab or return then dedent one step or if a comment toggle between normal indent and inline comment indent, else indent correctly.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/vhdl-mode.el.gz
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Indentation commands

(defun vhdl-electric-tab (&optional arg)
  "If preceding character is part of a word or a paren then hippie-expand,
else if right of non whitespace on line then insert tab,
else if last command was a tab or return then dedent one step or if a comment
toggle between normal indent and inline comment indent,
else indent `correctly'."
  (interactive "*P")
  (vhdl-prepare-search-2
   (cond
    ;; indent region if region is active
    ((and (not (featurep 'xemacs)) (use-region-p))
     (indent-region (region-beginning) (region-end) nil))
    ;; expand word
    ((= (char-syntax (preceding-char)) ?w)
     (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
	   (case-replace nil)
	   (hippie-expand-only-buffers
	    (or (and (boundp 'hippie-expand-only-buffers)
		     hippie-expand-only-buffers)
		'(vhdl-mode))))
       (vhdl-expand-abbrev arg)))
    ;; expand parenthesis
    ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
     (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
	   (case-replace nil))
       (vhdl-expand-paren arg)))
    ;; insert tab
    ((> (current-column) (current-indentation))
     (insert-tab))
    ;; toggle comment indent
    ((and (looking-at "--")
	  (or (eq last-command 'vhdl-electric-tab)
	      (eq last-command 'vhdl-electric-return)))
     (cond ((= (current-indentation) 0) ; no indent
	    (indent-to 1)
	    (indent-according-to-mode))
	   ((< (current-indentation) comment-column) ; normal indent
	    (indent-to comment-column)
	    (indent-according-to-mode))
	   (t				; inline comment indent
	    (delete-region (line-beginning-position) (point)))))
    ;; dedent
    ((and (>= (current-indentation) vhdl-basic-offset)
	  (or (eq last-command 'vhdl-electric-tab)
	      (eq last-command 'vhdl-electric-return)))
     (backward-delete-char-untabify vhdl-basic-offset nil))
    ;; indent line
    (t (indent-according-to-mode)))
   (setq this-command 'vhdl-electric-tab)))