Function: verilog-calculate-indent-directive

verilog-calculate-indent-directive is a byte-compiled function defined in verilog-mode.el.gz.

Signature

(verilog-calculate-indent-directive)

Documentation

Return indentation level for directive.

For speed, the searcher looks at the last directive, not the indent of the appropriate enclosing block.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/verilog-mode.el.gz
(defun verilog-calculate-indent-directive ()
  "Return indentation level for directive.
For speed, the searcher looks at the last directive, not the indent
of the appropriate enclosing block."
  (let ((base -1)  ; Indent of the line that determines our indentation
        (ind 0))   ; Relative offset caused by other directives (like `endif on same line as `else)
    ;; Start at current location, scan back for another directive

    (save-excursion
      (beginning-of-line)
      (while (and (< base 0)
		  (verilog-re-search-backward verilog-directive-re nil t))
	(cond ((save-excursion (skip-chars-backward " \t") (bolp))
	       (setq base (current-indentation))))
        (cond ((and (looking-at verilog-directive-end) (< base 0))  ; Only matters when not at BOL
	       (setq ind (- ind verilog-indent-level-directive)))
              ((and (looking-at verilog-directive-middle) (>= base 0))  ; Only matters when at BOL
	       (setq ind (+ ind verilog-indent-level-directive)))
	      ((looking-at verilog-directive-begin)
	       (setq ind (+ ind verilog-indent-level-directive)))))
      ;; Adjust indent to starting indent of critical line
      (setq ind (max 0 (+ ind base))))

    (save-excursion
      (beginning-of-line)
      (skip-chars-forward " \t")
      (cond ((or (looking-at verilog-directive-middle)
		 (looking-at verilog-directive-end))
	     (setq ind (max 0 (- ind verilog-indent-level-directive))))))
    ind))