Function: vhdl-fixup-whitespace-region

vhdl-fixup-whitespace-region is an interactive and byte-compiled function defined in vhdl-mode.el.gz.

Signature

(vhdl-fixup-whitespace-region BEG END &optional NO-MESSAGE)

Documentation

Fixup whitespace in region.

Surround operator symbols by one space, eliminate multiple spaces (except at beginning of line), eliminate spaces at end of line, do nothing in comments and strings.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/vhdl-mode.el.gz
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Fixup whitespace

(defun vhdl-fixup-whitespace-region (beg end &optional no-message)
  "Fixup whitespace in region.
Surround operator symbols by one space, eliminate multiple
spaces (except at beginning of line), eliminate spaces at end of
line, do nothing in comments and strings."
  (interactive "r")
  (unless no-message (message "Fixing up whitespace..."))
  (save-excursion
    (goto-char end)
    (setq end (point-marker))
    ;; have no space before and one space after `,' and ';'
    (goto-char beg)
    (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
      (if (match-string 1)
	  (goto-char (match-end 1))
	(replace-match "\\3 " nil nil nil 2)))
    ;; have no space after `('
    (goto-char beg)
    (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
      (if (match-string 1)
	  (goto-char (match-end 1))
	(replace-match "\\2")))
    ;; have no space before `)'
    (goto-char beg)
    (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
      (if (match-string 1)
	  (goto-char (match-end 1))
	(replace-match "\\2")))
    ;; surround operator symbols by one space
    (goto-char beg)
    (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
      (if (or (match-string 1)
	      (<= (match-beginning 0)  ; not if at boi
		 (save-excursion (back-to-indentation) (point))))
	  (goto-char (match-end 0))
	(replace-match "\\3 \\4 \\5")
	(goto-char (match-end 2))))
    ;; eliminate multiple spaces and spaces at end of line
    (goto-char beg)
    (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
	       (and (looking-at "--.*") (re-search-forward "--.*" end t))
	       (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
	       (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
		    (progn (replace-match "" nil nil) t))
	       (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
		    (progn (replace-match ";" nil nil) t))
	       (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
	       (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
		    (progn (replace-match "  " nil nil) t))
	       (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
		    (progn (replace-match " " nil nil) t))
	       (and (looking-at "-") (re-search-forward "-" end t))
	       (re-search-forward "[^ \t\"-]+" end t))))
  (unless no-message (message "Fixing up whitespace...done")))