From 47191f9e5155fc55c3b1257f7eb366e6c361381a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20A=2E=20Gomes?= Date: Thu, 7 Oct 2021 22:04:06 +0300 Subject: [PATCH 76/76] Unfinished work. The goal is to pass all tests without changing its internals. This would guarantee that 'healine an 'heading would both be valid. --- lisp/oc.el | 2 +- lisp/org-element.el | 58 +++++++++++++++++++++++++++++++------------- lisp/org-footnote.el | 2 +- lisp/org.el | 24 ++++++++++++------ lisp/ox-html.el | 4 +-- lisp/ox-odt.el | 2 +- lisp/ox.el | 16 ++++++------ 7 files changed, 71 insertions(+), 37 deletions(-) diff --git a/lisp/oc.el b/lisp/oc.el index e186df6de..a0e03a5bd 100644 --- a/lisp/oc.el +++ b/lisp/oc.el @@ -1427,7 +1427,7 @@ CONTEXT is the element or object at point, as returned by `org-element-context'. (< (point) (org-element-property :contents-end context)))) ;; In an heading or inlinetask, point must be either on the ;; heading itself or on the blank lines below. - ((memq type '(headline inlinetask)) + ((memq type '(heading inlinetask)) (or (not (org-at-heading-p)) (and (save-excursion (beginning-of-line) diff --git a/lisp/org-element.el b/lisp/org-element.el index 54be90ba9..5215005fe 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -236,16 +236,20 @@ specially in `org-element--object-lex'.") (defconst org-element-all-elements '(babel-call center-block clock comment comment-block diary-sexp drawer dynamic-block example-block export-block fixed-width - footnote-definition headline horizontal-rule inlinetask item + footnote-definition heading horizontal-rule inlinetask item keyword latex-environment node-property paragraph plain-list planning property-drawer quote-block section - special-block src-block table table-row verse-block) + special-block src-block table table-row verse-block + ;; to be deprecated + headline) "Complete list of element types.") (defconst org-element-greater-elements - '(center-block drawer dynamic-block footnote-definition headline inlinetask + '(center-block drawer dynamic-block footnote-definition heading inlinetask item plain-list property-drawer quote-block section - special-block table) + special-block table + ;; to be deprecated + headline) "List of recursive element types aka Greater Elements.") (defconst org-element-all-objects @@ -353,6 +357,8 @@ Don't modify it, set `org-element-affiliated-keywords' instead.") (citation citation-reference) (citation-reference ,@minimal-set) (footnote-reference ,@standard-set) + (heading ,@standard-set-no-line-break) + ;; to be deprecated (headline ,@standard-set-no-line-break) (inlinetask ,@standard-set-no-line-break) (italic ,@standard-set) @@ -384,11 +390,13 @@ a list of types that can be contained within an element or object of such type. This alist also applies to secondary string. For example, an -`headline' type element doesn't directly contain objects, but +`heading' type element doesn't directly contain objects, but still has an entry since one of its properties (`:title') does.") (defconst org-element-secondary-value-alist '((citation :prefix :suffix) + (heading :title) + ;; to be deprecated (headline :title) (inlinetask :title) (item :tag) @@ -682,7 +690,7 @@ is cleared and contents are removed in the process." ;; Similarly, interpreting functions must follow the naming ;; convention: org-element-TYPE-interpreter. ;; -;; With the exception of `headline' and `item' types, greater elements +;; With the exception of `heading' and `item' types, greater elements ;; cannot contain other greater elements of their own type. ;; ;; Beside implementing a parser and an interpreter, adding a new @@ -1049,7 +1057,11 @@ Assume point is at beginning of the heading." (skip-chars-backward " \r\t\n") (line-beginning-position 2))))) (let ((heading - (list 'headline + (list + ;; what can be done here?? + ;; 'heading + ;; to be deprecated + 'headline (nconc (list :raw-value raw-value :begin begin @@ -1085,7 +1097,9 @@ Assume point is at beginning of the heading." (skip-chars-backward " \t") (point)) nil - (org-element-restriction 'headline) + (or (org-element-restriction 'heading) + ;; to be deprecated + (org-element-restriction 'headline)) heading))))))) (defun org-element-heading-interpreter (heading contents) @@ -3973,7 +3987,7 @@ Possible types are defined in `org-element-all-elements'. LIMIT bounds the search. Optional argument GRANULARITY determines the depth of the -recursion. Allowed values are `headline', `greater-element', +recursion. Allowed values are `heading', `greater-element', `element', `object' or nil. When it is broader than `object' (or nil), secondary values will not be parsed, since they only contain objects. @@ -4239,7 +4253,7 @@ buffer. Optional argument GRANULARITY determines the depth of the recursion. It can be set to the following symbols: -`headline' Only parse headings. +`heading' Only parse headings. `greater-element' Don't recurse into greater elements except headings and sections. Thus, elements parsed are the top-level ones. @@ -4356,7 +4370,7 @@ and `example-block' elements in it: The following snippet will find the first heading with a level of 1 and a \"phone\" tag, and will return its beginning position: - (org-element-map tree \\='headline + (org-element-map tree \\='heading (lambda (hl) (and (= (org-element-property :level hl) 1) (member \"phone\" (org-element-property :tags hl)) @@ -4495,6 +4509,8 @@ If PARENT? is non-nil, assume the next element or object will be located inside the current one." (if parent? (pcase type + (`heading 'section) + ;; to be deprecated (`headline 'section) ((and (guard (eq mode 'first-section)) `section) 'top-comment) (`inlinetask 'planning) @@ -4530,7 +4546,10 @@ Elements are accumulated into ACC." (save-excursion (goto-char beg) ;; When parsing only headings, skip any text before first one. - (when (and (eq granularity 'headline) (not (org-at-heading-p))) + (when (and (or (eq granularity 'heading) + ;; to be deprecated + (eq granularity 'headline)) + (not (org-at-heading-p))) (org-with-limited-levels (outline-next-heading))) (let (elements) (while (< (point) end) @@ -4558,7 +4577,9 @@ Elements are accumulated into ACC." (or (memq granularity '(element object nil)) (and (eq granularity 'greater-element) (eq type 'section)) - (eq type 'headline))) + (or (eq type 'heading) + ;; to be deprecated + (eq type 'headline)))) (org-element--parse-elements cbeg (org-element-property :contents-end element) ;; Possibly switch to a special mode. @@ -5758,7 +5779,7 @@ section, possibly making cache invalid.") (defvar org-element--cache-change-warning nil "Non-nil when a sensitive line is about to be changed. -It is a symbol among nil, t and `headline'.") +It is a symbol among nil, t and `heading'.") (defun org-element--cache-before-change (beg end) "Request extension of area going to be modified if needed. @@ -5773,7 +5794,7 @@ text. See `before-change-functions' for more information." (save-match-data (if (and (org-with-limited-levels (org-at-heading-p)) (= (line-end-position) bottom)) - 'headline + 'heading (let ((case-fold-search t)) (re-search-forward org-element--cache-sensitive-re bottom t))))))))) @@ -5796,7 +5817,7 @@ that range. See `after-change-functions' for more information." ;; not removed, do not extend. (when (pcase org-element--cache-change-warning (`t t) - (`headline + (`heading (not (and (org-with-limited-levels (org-at-heading-p)) (= (line-end-position) bottom)))) (_ @@ -6082,7 +6103,10 @@ Providing it allows for quicker computation." (narrow-to-region (point) (match-end 0)) (throw 'objects-forbidden element))))) ;; At an heading or inlinetask, objects are in title. - ((memq type '(headline inlinetask)) + ((memq type '(heading + inlinetask + ;; to be deprecated + headline)) (let ((case-fold-search nil)) (goto-char (org-element-property :begin element)) (looking-at org-complex-heading-regexp) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 1371e1d59..62810e82e 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -263,7 +263,7 @@ otherwise." (< (point) (org-element-property :contents-end context)))) ;; In an heading or inlinetask, point must be either on the ;; heading itself or on the blank lines below. - ((memq type '(headline inlinetask)) + ((memq type '(heading inlinetask)) (or (not (org-at-heading-p)) (and (save-excursion (beginning-of-line) diff --git a/lisp/org.el b/lisp/org.el index 73ee7473d..0b87ed854 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8982,7 +8982,7 @@ a link." (call-interactively #'org-open-at-point-global)) ;; On a heading or an inlinetask, but not on a timestamp, ;; a link, a footnote reference or a citation. - ((memq type '(headline inlinetask)) + ((memq type '(heading inlinetask)) (org-match-line org-complex-heading-regexp) (let ((tags-beg (match-beginning 5)) (tags-end (match-end 5))) @@ -17165,7 +17165,10 @@ and returns at first non-nil value." (save-excursion (goto-char (region-beginning)) (org-at-heading-p))))) - (when (org-check-for-hidden 'headlines) (org-hidden-tree-error)) + (when (or (org-check-for-hidden 'headings) + ;; To be deprecated + (org-check-for-hidden 'headlines)) + (org-hidden-tree-error)) (call-interactively 'org-do-promote)) ;; At an inline task. ((org-at-heading-p) @@ -17203,7 +17206,10 @@ and returns at first non-nil value." (save-excursion (goto-char (region-beginning)) (org-at-heading-p))))) - (when (org-check-for-hidden 'headlines) (org-hidden-tree-error)) + (when (or (org-check-for-hidden 'headings) + ;; To be deprecated + (org-check-for-hidden 'headlines)) + (org-hidden-tree-error)) (call-interactively 'org-do-demote)) ;; At an inline task. ((org-at-heading-p) @@ -17219,11 +17225,13 @@ and returns at first non-nil value." (defun org-check-for-hidden (what) "Check if there are hidden headings/items in the current visual line. -WHAT can be either `headlines' or `items'. If the current line is +WHAT can be either `headings' or `items'. If the current line is an outline or item heading and it has a folded subtree below it, this function returns t, nil otherwise." (let ((re (cond - ((eq what 'headlines) org-outline-regexp-bol) + ((eq what 'headings) org-outline-regexp-bol) + ;; for backward compatibility + ((eq what 'headlines) org-outline-regexp-bol) ((eq what 'items) (org-item-beginning-re)) (t (error "This should not happen")))) beg end) @@ -19046,7 +19054,7 @@ ELEMENT." (t (goto-char start) (current-indentation)))) - ((memq type '(headline inlinetask nil)) + ((memq type '(heading inlinetask nil)) (if (org-match-line "[ \t]*$") (org--get-expected-indentation element t) 0)) @@ -19737,7 +19745,7 @@ region only contains such lines." (looking-at "[ \t]*\\(:\\(?: \\|$\\)\\)")) (replace-match "" nil nil nil (if (= (line-end-position) (match-end 0)) 0 1))) - ((and (memq type '(babel-call clock comment diary-sexp headline + ((and (memq type '(babel-call clock comment diary-sexp heading horizontal-rule keyword paragraph planning)) (<= (org-element-property :post-affiliated element) (point))) @@ -21408,7 +21416,7 @@ modified." (unindent-tree (lambda (contents) (dolist (element (reverse contents)) - (if (memq (org-element-type element) '(headline section)) + (if (memq (org-element-type element) '(heading section)) (funcall unindent-tree (org-element-contents element)) (save-excursion (save-restriction diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 9a00c11f1..7c222163d 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1664,10 +1664,10 @@ targets and targets." ((and user-label (or (plist-get info :html-prefer-user-labels) ;; Used CUSTOM_ID property unconditionally. - (memq type '(headline inlinetask)))) + (memq type '(heading inlinetask)))) user-label) ((and named-only - (not (memq type '(headline inlinetask radio-target target))) + (not (memq type '(heading inlinetask radio-target target))) (not user-label)) nil) (t diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index 4e5fcc8e0..d6f7cfbba 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -2609,7 +2609,7 @@ Return nil, otherwise." (let* ((genealogy (org-element-lineage destination)) (data (reverse genealogy)) (label (let ((type (org-element-type destination))) - (if (memq type '(headline target)) + (if (memq type '(heading target)) (org-export-get-reference destination info) (error "FIXME: Unable to resolve %S" destination))))) (or diff --git a/lisp/ox.el b/lisp/ox.el index 2672650da..964809ce8 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -333,22 +333,24 @@ according to the back-end used.") :tag "Org Export General" :group 'org-export) -(defcustom org-export-with-archived-trees 'headline +(defcustom org-export-with-archived-trees 'heading "Whether sub-trees with the ARCHIVE tag should be exported. This can have three different values: nil Do not export, pretend this tree is not present. t Do export the entire tree. -`headline' Only export the heading, but skip the tree below it. +`heading' Only export the heading, but skip the tree below it. This option can also be set with the OPTIONS keyword, e.g. \"arch:nil\"." :group 'org-export-general :type '(choice (const :tag "Not at all" nil) - (const :tag "Heading only" headline) + (const :tag "Heading only" heading) (const :tag "Entirely" t)) - :safe (lambda (x) (memq x '(t nil headline)))) + :safe (lambda (x) (memq x '(t nil heading + ;; to be deprecated + headline)))) (defcustom org-export-with-author t "Non-nil means insert author name into the exported file. @@ -1713,7 +1715,7 @@ INFO is a plist holding export options." (lambda (data genealogy) (let ((type (org-element-type data))) (cond - ((memq type '(headline inlinetask)) + ((memq type '(heading inlinetask)) (let ((tags (org-element-property :tags data))) (if (cl-some (lambda (tag) (member tag select)) tags) ;; When a select tag is found, mark full @@ -3351,7 +3353,7 @@ Return a string of lines to be included in the format expected by (or contents-begin (org-element-property :begin element)) (org-element-property (if contents-begin :contents-end :end) element)) (when (and only-contents - (memq (org-element-type element) '(headline inlinetask))) + (memq (org-element-type element) '(heading inlinetask))) ;; Skip planning line and property-drawer. (goto-char (point-min)) (when (looking-at-p org-planning-line-re) (forward-line)) @@ -3994,7 +3996,7 @@ inherited from parent headings and FILETAGS keywords." (let ((current-tag-list (org-element-property :tags element))) (dolist (parent (org-element-lineage element)) (dolist (tag (org-element-property :tags parent)) - (when (and (memq (org-element-type parent) '(headline inlinetask)) + (when (and (memq (org-element-type parent) '(heading inlinetask)) (not (member tag current-tag-list))) (push tag current-tag-list)))) ;; Add FILETAGS keywords and return results. -- 2.33.0