contrib/lisp/org-element: Hygienize org-element-map

* contrib/lisp/org-element.el (org-element-map): Change name of local
  variables to prevent variable name collisions with the function
  around org-element-map.
This commit is contained in:
Nicolas Goaziou 2011-12-24 14:07:47 +01:00
parent 9164b48f69
commit b78800f05a
1 changed files with 68 additions and 68 deletions

View File

@ -2775,7 +2775,7 @@ the current buffer."
(insert string) (insert string)
(org-element-parse-objects (point-min) (point-max) nil restriction))) (org-element-parse-objects (point-min) (point-max) nil restriction)))
(defun org-element-map (data types fun &optional options first-match) (defun org-element-map (data types fun &optional info first-match)
"Map a function on selected elements or objects. "Map a function on selected elements or objects.
DATA is the parsed tree, as returned by, i.e, DATA is the parsed tree, as returned by, i.e,
@ -2785,7 +2785,7 @@ matching element or object. It must accept two arguments: the
element or object itself and a plist holding contextual element or object itself and a plist holding contextual
information. information.
When optional argument OPTIONS is non-nil, it should be a plist When optional argument INFO is non-nil, it should be a plist
holding export options. In that case, parts of the parse tree holding export options. In that case, parts of the parse tree
not exportable according to that property list will be skipped not exportable according to that property list will be skipped
and files included through a keyword will be visited. and files included through a keyword will be visited.
@ -2796,9 +2796,8 @@ match for which FUN doesn't return nil, and return that value.
Nil values returned from FUN are ignored in the result." Nil values returned from FUN are ignored in the result."
;; Ensure TYPES is a list, even of one element. ;; Ensure TYPES is a list, even of one element.
(unless (listp types) (setq types (list types))) (unless (listp types) (setq types (list types)))
;; Recursion depth is determined by TYPE-CATEGORY, to avoid ;; Recursion depth is determined by --CATEGORY.
;; unnecessary steps. (let* ((--category
(let* ((type-category
(cond (cond
((loop for type in types ((loop for type in types
always (memq type org-element-greater-elements)) always (memq type org-element-greater-elements))
@ -2808,96 +2807,97 @@ Nil values returned from FUN are ignored in the result."
'elements) 'elements)
(t 'objects))) (t 'objects)))
walk-tree ; For byte-compiler walk-tree ; For byte-compiler
acc ; Accumulate results into ACC. --acc
(accumulate-maybe (accumulate-maybe
(function (function
;; Check if TYPE is matching among TYPES. If so, apply FUN (lambda (--type types fun --blob --local)
;; to BLOB and accumulate return value into ACC. INFO is ;; Check if TYPE is matching among TYPES. If so, apply
;; the communication channel. ;; FUN to --BLOB and accumulate return value
(lambda (type types fun blob info) ;; into --ACC. --LOCAL is the communication channel.
(when (memq type types) (when (memq --type types)
(let ((result (funcall fun blob info))) (let ((result (funcall fun --blob --local)))
(cond (cond ((not result))
((not result))
(first-match (throw 'first-match result)) (first-match (throw 'first-match result))
(t (push result acc)))))))) (t (push result --acc))))))))
(walk-tree (walk-tree
(function (function
;; Recursively walk DATA. INFO, if non-nil, is a plist (lambda (--data --local)
;; holding contextual information. ;; Recursively walk DATA. --LOCAL, if non-nil, is
(lambda (data info) ;; a plist holding contextual information.
(mapc (mapc
(lambda (blob) (lambda (--blob)
(let ((type (if (stringp blob) 'plain-text (car blob)))) (let ((--type (if (stringp --blob) 'plain-text (car --blob))))
;; Determine if a recursion into BLOB is possible ;; Determine if a recursion into --BLOB is
;; and allowed. ;; possible and allowed.
(cond (cond
;; Element or object not exportable. ;; Element or object not exportable.
((and info (org-export-skip-p blob info))) ((and info (org-export-skip-p --blob info)))
;; Archived headline: skip it. ;; Archived headline: Maybe apply fun on it, but
;; skip contents.
((and info ((and info
(eq type 'headline) (eq --type 'headline)
(and (eq (plist-get info :with-archived-trees) (eq (plist-get info :with-archived-trees) 'headline)
'headline) (org-element-get-property :archivedp --blob))
(org-element-get-property :archivedp blob))) (funcall accumulate-maybe --type types fun --blob --local))
(funcall accumulate-maybe type types fun blob info))
;; At an include keyword: apply mapping to its ;; At an include keyword: apply mapping to its
;; contents. ;; contents.
((and info ((and --local
(eq type 'keyword) (eq --type 'keyword)
(string= (string=
(downcase (org-element-get-property :key blob)) (downcase (org-element-get-property :key --blob))
"include")) "include"))
(funcall accumulate-maybe type types fun blob info) (funcall accumulate-maybe --type types fun --blob --local)
(let* ((data (org-export-parse-included-file blob info)) (let* ((--data
(value (org-element-get-property :value blob)) (org-export-parse-included-file --blob --local))
(file (and (string-match "^\"\\(\\S-+\\)\"" value) (--value (org-element-get-property :value --blob))
(match-string 1 value)))) (--file
(and (string-match "^\"\\(\\S-+\\)\"" --value)
(match-string 1 --value))))
(funcall (funcall
walk-tree walk-tree --data
data
(org-combine-plists (org-combine-plists
info --local
;; Store full path of already included files ;; Store full path of already included files
;; to avoid recursive file inclusion. ;; to avoid recursive file inclusion.
`(:included-files `(:included-files
,(cons (expand-file-name file) ,(cons (expand-file-name --file)
(plist-get info :included-files)) (plist-get --local :included-files))
;; Ensure that a top-level headline in the ;; Ensure that a top-level headline in the
;; included file becomes a direct child of ;; included file becomes a direct child of
;; the current headline in the buffer. ;; the current headline in the buffer.
:headline-offset :headline-offset
,(- (+ (plist-get ,(- (+ (plist-get
(plist-get info :inherited-properties) :level) (plist-get --local :inherited-properties)
(or (plist-get info :headline-offset) 0)) :level)
(1- (org-export-get-min-level data info)))))))) (or (plist-get --local :headline-offset) 0))
;; Limiting recursion to greater elements, and BLOB (1- (org-export-get-min-level
--data --local))))))))
;; Limiting recursion to greater elements, and --BLOB
;; isn't one. ;; isn't one.
((and (eq type-category 'greater-elements) ((and (eq --category 'greater-elements)
(not (memq type org-element-greater-elements))) (not (memq --type org-element-greater-elements)))
(funcall accumulate-maybe type types fun blob info)) (funcall accumulate-maybe --type types fun --blob --local))
;; Limiting recursion to elements, and BLOB only ;; Limiting recursion to elements, and --BLOB only
;; contains objects. ;; contains objects.
((and (eq type-category 'elements) (eq type 'paragraph))) ((and (eq --category 'elements) (eq --type 'paragraph)))
;; No limitation on recursion, but BLOB hasn't got ;; No limitation on recursion, but --BLOB hasn't
;; a recursive type. ;; got a recursive type.
((and (eq type-category 'objects) ((and (eq --category 'objects)
(not (or (eq type 'paragraph) (not (or (eq --type 'paragraph)
(memq type org-element-greater-elements) (memq --type org-element-greater-elements)
(memq type org-element-recursive-objects)))) (memq --type org-element-recursive-objects))))
(funcall accumulate-maybe type types fun blob info)) (funcall accumulate-maybe --type types fun --blob --local))
;; Recursion is possible and allowed: Update local ;; Recursion is possible and allowed: Update local
;; informations and move into BLOB. ;; information and move into --BLOB.
(t (funcall accumulate-maybe type types fun blob info) (t (funcall accumulate-maybe --type types fun --blob --local)
(funcall (funcall
walk-tree walk-tree --blob
blob (and info (org-export-update-info --blob --local t)))))))
(and options (org-export-update-info blob info t))))))) (org-element-get-contents --data))))))
(org-element-get-contents data))))))
(catch 'first-match (catch 'first-match
(funcall walk-tree data options) (funcall walk-tree data info)
;; Return value in a proper order. ;; Return value in a proper order.
(reverse acc)))) (reverse --acc))))
;; The following functions are internal parts of the parser. The ;; The following functions are internal parts of the parser. The
;; first one, `org-element-parse-elements' acts at the element's ;; first one, `org-element-parse-elements' acts at the element's