Next / Previous / Contents / Shipman's homepage

4.9. bracket-field: What field contains a given position?

Given a line-object and a position within that line, this function tries to find the field containing that position.

There are three cases:

This function just checks for the first case. If the position isn't before the tail, we call Section 4.10, “bracket-tail-field: What tail field contains the cursor?”.

ibp.el
;; - - -   b r a c k e t - f i e l d   - - -

(defun bracket-field (line p)
  "Find the field containing a position p within a line-object line

    [ if (line is a line-object for a line with a tail)
      and (p is a position within line) ->
        if p is in the head part of line ->
          return a field-object representing the head part, with nil filler
        else if p is in a tail field of line ->
          return a field-object representing that field
        else ->
          return nil ]
----------------------------------------------------------------"
  (if (< p (line-tail line))
      (field-object (line-beg line) (line-tail line) nil)
    (bracket-tail-field line)))