Change function org-list-end-re into a variable

* lisp/org-list.el (org-list-end-re): removed function and made it a
  variable. There's no need for the overhead of calling the function
  every at every line in a list. User will have to reload Org if he
  change value of either `org-list-end-regexp' or
  `org-empty-line-terminates-plain-lists'.
(org-in-item-p,org-list-struct,org-list-parse-list): apply change.
* lisp/org-exp.el (org-export-mark-list-end,
  org-export-mark-list-properties): apply change
* lisp/org-latex.el (org-export-latex-lists): apply change. Also
  prevent items with org-example property to be considered as real
  items.
This commit is contained in:
Nicolas Goaziou 2011-01-10 20:01:51 +01:00
parent 215d3fa030
commit 2c79244687
3 changed files with 49 additions and 58 deletions

View File

@ -1690,7 +1690,7 @@ These special cookies will later be interpreted by the backend."
(top-ind (org-list-get-ind top struct)))
(goto-char bottom)
(when (and (not (eq org-list-ending-method 'indent))
(looking-at (org-list-end-re)))
(looking-at org-list-end-re))
(replace-match ""))
(unless (bolp) (insert "\n"))
;; As org-list-end is inserted at column 0, it would end
@ -1748,7 +1748,7 @@ These special properties will later be interpreted by the backend."
(goto-char bottom)
(when (or (looking-at "^ORG-LIST-END\n")
(and (not (eq org-list-ending-method 'indent))
(looking-at (org-list-end-re))))
(looking-at org-list-end-re)))
(replace-match ""))
(unless (bolp) (insert "\n"))
(insert
@ -1759,13 +1759,13 @@ These special properties will later be interpreted by the backend."
(add-text-properties top (point) (list 'list-context ctxt)))))))
;; Mark lists except for backends not interpreting them.
(unless (eq backend 'ascii)
(mapc
(lambda (e)
(flet ((org-list-end-re nil "ORG-LIST-END"))
(let ((org-list-end-re "^ORG-LIST-END\n"))
(mapc
(lambda (e)
(goto-char (point-min))
(while (re-search-forward org-item-beginning-re nil t)
(when (eq (nth 2 (org-list-context)) e) (funcall mark-list e)))))
(cons nil org-list-export-context)))))
(when (eq (nth 2 (org-list-context)) e) (funcall mark-list e))))
(cons nil org-list-export-context))))))
(defun org-export-attach-captions-and-attributes (backend target-alist)
"Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.

View File

@ -2468,43 +2468,36 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
(let (res)
(goto-char (point-min))
(while (re-search-forward org-item-beginning-re nil t)
(org-if-unprotected
(when (eq (get-text-property (point) 'list-context) e)
(beginning-of-line)
(setq res
(org-list-to-latex
;; Narrowing is needed because we're converting
;; from inner functions to outer ones.
(save-restriction
(narrow-to-region (point) (point-max))
;; `org-list-end-re' output has changed since
;; preprocess from org-exp.el. Moreover, we now
;; only consider unprotected item as valid.
(flet ((org-list-end-re nil "^ORG-LIST-END\n")
(org-at-item-p
nil (save-excursion
(beginning-of-line)
(org-if-unprotected
(looking-at org-item-beginning-re)))))
(org-list-parse-list t)))
org-export-latex-list-parameters))
;; Replace any counter with its latex expression in output
;; string.
(while (string-match
"^\\(\\\\item[ \t]+\\)\\[@\\(?:start:\\)?\\([0-9]+\\)\\]"
res)
(setq res (replace-match
(concat (format "\\setcounter{enumi}{%d}"
(1- (string-to-number
(match-string 2 res))))
"\n"
(match-string 1 res))
t t res)))
;; Extend previous value of original-indentation to the whole
;; string
(insert (org-add-props res nil 'original-indentation
(org-find-text-property-in-string
'original-indentation res))))))))
(when (and (eq (get-text-property (point) 'list-context) e)
(not (get-text-property (point) 'org-example)))
(beginning-of-line)
(setq res
(org-list-to-latex
;; Narrowing is needed because we're converting
;; from inner functions to outer ones.
(save-restriction
(narrow-to-region (point) (point-max))
;; `org-list-end-re' output has changed since
;; preprocess from org-exp.el.
(let ((org-list-end-re "^ORG-LIST-END\n"))
(org-list-parse-list t)))
org-export-latex-list-parameters))
;; Replace any counter with its latex expression in string.
(while (string-match
"^\\(\\\\item[ \t]+\\)\\[@\\(?:start:\\)?\\([0-9]+\\)\\]"
res)
(setq res (replace-match
(concat (format "\\setcounter{enumi}{%d}"
(1- (string-to-number
(match-string 2 res))))
"\n"
(match-string 1 res))
t t res)))
;; Extend previous value of original-indentation to the
;; whole string
(insert (org-add-props res nil 'original-indentation
(org-find-text-property-in-string
'original-indentation res)))))))
(append org-list-export-context '(nil))))
(defconst org-latex-entities

View File

@ -313,12 +313,11 @@ specifically, type `block' is determined by the variable
;;; Internal functions
(defun org-list-end-re ()
"Return the regex corresponding to the end of a list.
It depends on `org-empty-line-terminates-plain-lists'."
(if org-empty-line-terminates-plain-lists
"^[ \t]*\n"
org-list-end-regexp))
(defconst org-list-end-re (if org-empty-line-terminates-plain-lists
"^[ \t]*\n"
org-list-end-regexp)
"Regex corresponding to the end of a list.
It depends on `org-empty-line-terminates-plain-lists'.")
(defun org-item-re (&optional general)
"Return the correct regular expression for plain lists.
@ -736,8 +735,8 @@ This checks `org-list-ending-method'."
(beginning-of-line)
(unless (or (let ((outline-regexp org-outline-regexp)) (org-at-heading-p))
(and (not (eq org-list-ending-method 'indent))
(looking-at (org-list-end-re))
(progn (forward-line -1) (looking-at (org-list-end-re)))))
(looking-at org-list-end-re)
(progn (forward-line -1) (looking-at org-list-end-re))))
(or (and (org-at-item-p) (point-at-bol))
(let* ((case-fold-search t)
(context (org-list-context))
@ -754,7 +753,7 @@ This checks `org-list-ending-method'."
((<= (point) lim-up)
(throw 'exit (and (org-at-item-p) (< ind ind-ref) (point))))
((and (not (eq org-list-ending-method 'indent))
(looking-at (org-list-end-re)))
(looking-at org-list-end-re))
(throw 'exit nil))
;; Skip blocks, drawers, inline-tasks, blank lines
((looking-at "^[ \t]*#\\+end_")
@ -779,8 +778,7 @@ This checks `org-list-ending-method'."
(defun org-at-item-p ()
"Is point in a line starting a hand-formatted item?"
(save-excursion
(beginning-of-line) (looking-at org-item-beginning-re)))
(save-excursion (beginning-of-line) (looking-at org-item-beginning-re)))
(defun org-at-item-bullet-p ()
"Is point at the bullet of a plain list item?"
@ -1109,7 +1107,7 @@ Assume point is at an item."
(setq beg-cell (cons (point) ind))
(cons (funcall assoc-at-point ind) itm-lst)))))
((and (not (eq org-list-ending-method 'indent))
(looking-at (org-list-end-re)))
(looking-at org-list-end-re))
;; Looking at a list ending regexp. Dismiss useless
;; data recorded above BEG-CELL. Jump to part 2.
(throw 'exit
@ -1176,7 +1174,7 @@ Assume point is at an item."
(throw 'exit
(push (cons 0 (funcall end-before-blank)) end-lst-2)))
((and (not (eq org-list-ending-method 'indent))
(looking-at (org-list-end-re)))
(looking-at org-list-end-re))
;; Looking at a list ending regexp. Save point as an
;; ending position and jump to part 3.
(throw 'exit (push (cons 0 (point-at-bol)) end-lst-2)))
@ -2472,7 +2470,7 @@ Point is left at list end."
(when delete
(delete-region top bottom)
(when (and (not (eq org-list-ending-method 'indent))
(looking-at (org-list-end-re)))
(looking-at org-list-end-re))
(replace-match "\n")))
out))