Function: org-footnote--allow-reference-p

org-footnote--allow-reference-p is a byte-compiled function defined in org-footnote.el.gz.

Signature

(org-footnote--allow-reference-p)

Documentation

Non-nil when a footnote reference can be inserted at point.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-footnote.el.gz
;;;; Internal functions

(defun org-footnote--allow-reference-p ()
  "Non-nil when a footnote reference can be inserted at point."
  ;; XXX: This is similar to `org-footnote-in-valid-context-p' but
  ;; more accurate and usually faster, except in some corner cases.
  ;; It may replace it after doing proper benchmarks as it would be
  ;; used in fontification.
  (unless (bolp)
    (let* ((context (org-element-context))
	   (type (org-element-type context)))
      (cond
       ;; No footnote reference in attributes.
       ((let ((post (org-element-property :post-affiliated context)))
	  (and post (< (point) post)))
	nil)
       ;; Paragraphs and blank lines at top of document are fine.
       ((memq type '(nil paragraph)))
       ;; So are contents of verse blocks.
       ((eq type 'verse-block)
	(and (>= (point) (org-element-property :contents-begin context))
	     (< (point) (org-element-property :contents-end context))))
       ;; In an headline or inlinetask, point must be either on the
       ;; heading itself or on the blank lines below.
       ((memq type '(headline inlinetask))
	(or (not (org-at-heading-p))
	    (and (save-excursion
		   (forward-line 0)
		   (and (let ((case-fold-search t))
			  (not (looking-at-p "\\*+ END[ \t]*$")))
			(let ((case-fold-search nil))
			  (looking-at org-complex-heading-regexp))))
		 (match-beginning 4)
		 (>= (point) (match-beginning 4))
		 (or (not (match-beginning 5))
		     (< (point) (match-beginning 5))))))
       ;; White spaces after an object or blank lines after an element
       ;; are OK.
       ((>= (point)
	   (save-excursion (goto-char (org-element-property :end context))
			   (skip-chars-backward " \r\t\n")
			   (if (eq (org-element-class context) 'object) (point)
			     (line-beginning-position 2)))))
       ;; At the beginning of a footnote definition, right after the
       ;; label, is OK.
       ((eq type 'footnote-definition) (looking-at (rx space)))
       ;; Other elements are invalid.
       ((eq (org-element-class context) 'element) nil)
       ;; Just before object is fine.
       ((= (point) (org-element-property :begin context)))
       ;; Within recursive object too, but not in a link.
       ((eq type 'link) nil)
       ((eq type 'table-cell)
        ;; :contents-begin is not reliable on empty cells, so special
        ;; case it.
        (<= (save-excursion (skip-chars-backward " \t") (point))
           (org-element-property :contents-end context)))
       ((let ((cbeg (org-element-property :contents-begin context))
	      (cend (org-element-property :contents-end context)))
	  (and cbeg (>= (point) cbeg) (<= (point) cend))))))))