Function: vhdl-compose-new-component

vhdl-compose-new-component is an interactive and byte-compiled function defined in vhdl-mode.el.gz.

Signature

(vhdl-compose-new-component)

Documentation

Create entity and architecture for new component.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/vhdl-mode.el.gz
(defun vhdl-compose-new-component ()
  "Create entity and architecture for new component."
  (interactive)
  (let* ((case-fold-search t)
	 (ent-name (read-from-minibuffer "entity name: "
					 nil vhdl-minibuffer-local-map))
	 (arch-name
	  (if (equal (cdr vhdl-compose-architecture-name) "")
	      (read-from-minibuffer "architecture name: "
				    nil vhdl-minibuffer-local-map)
	    (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
	 ent-file-name arch-file-name ent-buffer arch-buffer end-pos) ;; project
    (message "Creating component \"%s(%s)\"..." ent-name arch-name)
    ;; open entity file
    (unless (eq vhdl-compose-create-files 'none)
      (setq ent-file-name
	    (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
		    "." (file-name-extension (buffer-file-name))))
      (when (and (file-exists-p ent-file-name)
		 (not (y-or-n-p (concat "File \"" ent-file-name
					"\" exists; overwrite? "))))
	(error "ERROR:  Creating component...aborted"))
      (find-file ent-file-name)
      (erase-buffer)
      (set-buffer-modified-p nil))
    ;; insert header
    (if vhdl-compose-include-header
	(progn (vhdl-template-header)
	       (setq end-pos (point))
	       (goto-char (point-max)))
      (vhdl-comment-display-line) (insert "\n\n"))
    ;; insert library clause
    (vhdl-template-package-std-logic-1164)
    (when vhdl-use-components-package
      (insert "\n")
      (vhdl-template-standard-package (vhdl-work-library)
				      (vhdl-get-components-package-name)))
    (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
    ;; insert entity declaration
    (vhdl-insert-keyword "ENTITY ") (insert ent-name)
    (vhdl-insert-keyword " IS\n")
    (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
    (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
    (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
    (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
    (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
    (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
    (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
    (vhdl-insert-keyword "END ")
    (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
    (insert ent-name ";\n\n")
    (vhdl-comment-display-line) (insert "\n")
    ;; open architecture file
    (if (not (eq vhdl-compose-create-files 'separate))
	(insert "\n")
      (goto-char (or end-pos (point-min)))
      (setq ent-buffer (current-buffer))
      (setq arch-file-name
	    (concat (vhdl-replace-string vhdl-architecture-file-name
					 (concat ent-name " " arch-name) t)
		    "." (file-name-extension (buffer-file-name))))
      (when (and (file-exists-p arch-file-name)
		 (not (y-or-n-p (concat "File \"" arch-file-name
					"\" exists; overwrite? "))))
	(error "ERROR:  Creating component...aborted"))
      (find-file arch-file-name)
      (erase-buffer)
      (set-buffer-modified-p nil)
      ;; insert header
      (if vhdl-compose-include-header
	  (progn (vhdl-template-header)
		 (goto-char (point-max)))
	(vhdl-comment-display-line) (insert "\n\n")))
    ;; insert architecture body
    (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
    (vhdl-insert-keyword " OF ") (insert ent-name)
    (vhdl-insert-keyword " IS\n\n")
    (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
    (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
    (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
    (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
      (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
      (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
      (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
    (vhdl-insert-keyword "BEGIN")
    (when vhdl-self-insert-comments
      (insert "  -- ")
      (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
      (insert arch-name))
    (insert "\n\n")
    (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
    (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
    (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
    (vhdl-insert-keyword "END ")
    (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
    (insert arch-name ";\n\n")
    ;; insert footer and save
    (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
	(vhdl-template-footer)
      (vhdl-comment-display-line) (insert "\n"))
    (goto-char (or end-pos (point-min)))
    (setq arch-buffer (current-buffer))
    (when ent-buffer (set-buffer ent-buffer) (save-buffer))
    (set-buffer arch-buffer) (save-buffer)
    (message "%s"
     (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
	     (and ent-file-name
		  (format "\n  File created: \"%s\"" ent-file-name))
	     (and arch-file-name
		  (format "\n  File created: \"%s\"" arch-file-name))))))