Function: org-list-context

org-list-context is a byte-compiled function defined in org-list.el.gz.

Signature

(org-list-context)

Documentation

Determine context, and its boundaries, around point.

Context will be a cell like (MIN MAX CONTEXT) where MIN and MAX are boundaries and CONTEXT is a symbol among drawer, block, invalid, inlinetask and nil.

Contexts block and invalid refer to org-list-forbidden-blocks.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-list.el.gz
;;; Structures and helper functions

(defun org-list-context ()
  "Determine context, and its boundaries, around point.

Context will be a cell like (MIN MAX CONTEXT) where MIN and MAX
are boundaries and CONTEXT is a symbol among `drawer', `block',
`invalid', `inlinetask' and nil.

Contexts `block' and `invalid' refer to `org-list-forbidden-blocks'."
  (save-match-data
    (save-excursion
      (org-with-limited-levels
       (beginning-of-line)
       (let ((case-fold-search t) (pos (point)) beg end context-type
	     ;; Get positions of surrounding headings.  This is the
	     ;; default context.
	     (lim-up (or (save-excursion (and (ignore-errors (org-back-to-heading t))
					      (point)))
			 (point-min)))
	     (lim-down (or (save-excursion (outline-next-heading)) (point-max))))
	 ;; Is point inside a drawer?
	 (let ((end-re "^[ \t]*:END:")
	       (beg-re org-drawer-regexp))
	   (when (save-excursion
		   (and (not (looking-at beg-re))
			(not (looking-at end-re))
			(setq beg (and (re-search-backward beg-re lim-up t)
                                       (1+ (line-end-position))))
			(setq end (or (and (re-search-forward end-re lim-down t)
					   (1- (match-beginning 0)))
				      lim-down))
			(>= end pos)))
	     (setq lim-up beg lim-down end context-type 'drawer)))
	 ;; Is point strictly in a block, and of which type?
	 (let ((block-re "^[ \t]*#\\+\\(begin\\|end\\)_") type)
	   (when (save-excursion
		   (and (not (looking-at block-re))
			(setq beg (and (re-search-backward block-re lim-up t)
                                       (1+ (line-end-position))))
			(looking-at "^[ \t]*#\\+begin_\\(\\S-+\\)")
			(setq type (downcase (match-string 1)))
			(goto-char beg)
			(setq end (or (and (re-search-forward block-re lim-down t)
                                           (1- (line-beginning-position)))
				      lim-down))
			(>= end pos)
			(equal (downcase (match-string 1)) "end")))
	     (setq lim-up beg lim-down end
		   context-type (if (member type org-list-forbidden-blocks)
				    'invalid 'block))))
	 ;; Is point in an inlinetask?
	 (when (and (featurep 'org-inlinetask)
		    (save-excursion
		      (let* ((beg-re (org-inlinetask-outline-regexp))
			     (end-re (concat beg-re "END[ \t]*$")))
			(and (not (looking-at "^\\*+"))
			     (setq beg (and (re-search-backward beg-re lim-up t)
                                            (1+ (line-end-position))))
			     (not (looking-at end-re))
			     (setq end (and (re-search-forward end-re lim-down t)
					    (1- (match-beginning 0))))
			     (> (point) pos)))))
	   (setq lim-up beg lim-down end context-type 'inlinetask))
	 ;; Return context boundaries and type.
	 (list lim-up lim-down context-type))))))