Function: vhdl-port-paste-signals

vhdl-port-paste-signals is an interactive and byte-compiled function defined in vhdl-mode.el.gz.

Signature

(vhdl-port-paste-signals &optional INITIALIZE NO-INDENT)

Documentation

Paste ports as internal signals.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/vhdl-mode.el.gz
(defun vhdl-port-paste-signals (&optional initialize no-indent)
  "Paste ports as internal signals."
  (interactive)
  (if (not vhdl-port-list)
      (error "ERROR:  No port read")
    (message "Pasting port as signals...")
    (unless no-indent (indent-according-to-mode))
    (let ((margin (current-indentation))
	  start port names type generic-list port-name constant-name pos
	  (port-list (nth 2 vhdl-port-list)))
      (when port-list
	(setq start (point))
	(while port-list
	  (setq port (car port-list))
	  ;; paste group comment and spacing
	  (when (memq vhdl-include-group-comments '(decl always))
	    (vhdl-paste-group-comment (nth 5 port) margin))
	  ;; paste object
	  (if (nth 1 port)
	      (insert (nth 1 port) " ")
	    (vhdl-insert-keyword "SIGNAL "))
	  ;; paste actual port signals
	  (setq names (nth 0 port))
	  (while names
	    (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
	    (setq names (cdr names))
	    (when names (insert ", ")))
	  ;; paste type
	  (setq type (nth 3 port))
	  (setq generic-list (nth 1 vhdl-port-list))
	  (vhdl-prepare-search-1
	   (setq pos 0)
	   ;; replace formal by actual generics
	   (while generic-list
	     (setq port-name (car (nth 0 (car generic-list))))
	     (while (string-match (concat "\\<" port-name "\\>") type pos)
	       (setq constant-name
		     (save-match-data (vhdl-replace-string
				       vhdl-actual-generic-name port-name)))
	       (setq type (replace-match constant-name t nil type))
	       (setq pos (match-end 0)))
	     (setq generic-list (cdr generic-list))))
	  (insert " : " type)
	  ;; paste initialization (inputs only)
	  (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
	    (insert " := "
		    (cond ((string-match "integer" (nth 3 port)) "0")
			  ((string-match "natural" (nth 3 port)) "0")
			  ((string-match "positive" (nth 3 port)) "0")
			  ((string-match "real" (nth 3 port)) "0.0")
			  ((string-match "(.+)" (nth 3 port)) "(others => '0')")
			  (t "'0'"))))
	  (insert ";")
	  ;; paste comment
	  (when (or (and vhdl-include-direction-comments (nth 2 port))
		    (and vhdl-include-port-comments (nth 4 port)))
	    (vhdl-comment-insert-inline
	     (concat
	      (cond ((and vhdl-include-direction-comments (nth 2 port))
		     (format "%-6s" (concat "[" (nth 2 port) "] ")))
		    (vhdl-include-direction-comments "      "))
	      (when vhdl-include-port-comments (nth 4 port)))
	     t))
	  (setq port-list (cdr port-list))
	  (when port-list (insert "\n") (indent-to margin)))
	;; align signal list
	(when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
    (message "Pasting port as signals...done")))