Function: hif-find-range

hif-find-range is a byte-compiled function defined in hideif.el.gz.

Signature

(hif-find-range)

Documentation

Return a Range structure describing the current #if region.

Point is left unchanged.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/hideif.el.gz
;; Find-Range
;; The workhorse, it delimits the #if region.  Reasonably simple:
;; Skip until an #else or #endif is found, remembering positions.  If
;; an #else was found, skip some more, looking for the true #endif.

(defun hif-find-range ()
  "Return a Range structure describing the current #if region.
Point is left unchanged."
  ;; (message "hif-find-range at %d" (point))
  (save-excursion
    (beginning-of-line)
    (let ((start (point))
          (elif nil)
          (else nil)
          (end nil))
      ;; Part one.  Look for either #elif, #else or #endif.
      ;; This loop-and-a-half dedicated to E. Dijkstra.
      (while (and (not else) (not end))
        (while (progn
                 (hif-find-next-relevant)
                 (hif-looking-at-ifX))            ; Skip nested ifdef
          (hif-ifdef-to-endif))
        ;; Found either a #else, #elif, or an #endif.
        (cond ((hif-looking-at-elif)
               (setq elif (nconc elif (list (point)))))
              ((hif-looking-at-else)
               (setq else (point)))
              (t
               (setq end (point)))))
      ;; If found #else, look for #endif.
      (when else
        (while (progn
                 (hif-find-next-relevant)
                 (hif-looking-at-ifX))  ; Skip nested ifdef
          (hif-ifdef-to-endif))
        (if (hif-looking-at-else)
            (error "Found two elses in a row?  Broken!"))
        (setq end (point)))            ; (line-end-position)
      (hif-make-range start end else elif))))