Next / Previous / Contents / Shipman's homepage

5.6. ibp-analyze-line: Where are the parts of the current line?

This function locates the major parts of a line, and returns a ibp-line-object describing those parts. It looks at the first character of the line to determine its format; for the interpretation of that character, see the specification's section on encounter lines.

;; - - -   i b p - a n a l y z e - l i n e   - - -

(defun ibp-analyze-line ()
  "Finds the type and cardinal points of the line containing point.

    [ return the ibp-line-object for the line containing point ]

Inside the scope of this let are four local variables:


A symbol describing what kind of line this is. For possible values, see Section 5.7, “ibp-classify-line: What kind of line is this?”.


Position of the beginning of the line.


Position of the end of the line.


Position of the beginning of the tail portion, if any, or nil if the line has no tail.

  (let (line-kind         ;; Line type code
        line-beg          ;; Line beginning position
        line-end          ;; Line end position
        tail-beg)         ;; Line tail beginning position, if any

First we find the beginning and end of the current line. The save-excursion function creates a section in which we can move the cursor around freely, but its original position is restored after that section. The beginning-of-line function moves the cursor to the beginning of the line, and then we use setq to store the cursor position in line-beg. A similar jump with the end-of-line function is used to set line-end to the end position.

    ;; [ line-beg  :=  starting position of the line containing point
    ;;   line-end  :=  end position of the line containing point ]
    (save-excursion           ;; Saves point while executing this block:
      (beginning-of-line)     ;; Move to start of line containing point
      (setq line-beg (point))
      (setq line-end (point)))

Next we call a function to look at the first character of the line and see what kind it is; see Section 5.7, “ibp-classify-line: What kind of line is this?”.

    ;; [ line-kind  :=  a symbol for the type of the line
    ;;       containing point ]
    (setq line-kind (ibp-classify-line line-beg line-end))

Now we have to set the value of tail-beg. If the current line isn't an encounter line, ibp-classify-line returns the symbol 'non-trans; in this case, we set tail-beg to nil to signify that the line has no tail. For encounter lines, we set tail-beg to line-beg (the position of the start of the line) plus the length of the head section for a line of this kind, which is computed by Section 5.8, “ibp-line-head-length: How long is the head of this line?”.

    ;; [ if line-kind is 'non-trans ->
    ;;     tail-beg  :=  nil
    ;;   else ->
    ;;     tail-beg  :=  line-beg + (head length for lines of
    ;;                   type line-kind) ]
    (setq tail-beg
          (if (eq line-kind 'non-trans)
            (+ line-beg (ibp-line-head-length line-kind))))

Now we have everything we need to build a ibp-line-object and return it to the caller.

    ;; [ return an ibp-line-object with .kind=line-kind, .beg=line-beg,
    ;;   .end=line-end, and .tail=tail-beg ]
    (ibp-line-object line-kind line-beg line-end tail-beg)))