Browse Source

org-element: Add :post-affiliated property to all elements

* lisp/org-element.el (org-element-headline-parser,
  org-element-inlinetask-parser, org-element-item-parser,
  org-element-section-parser, org-element-clock-parser,
  org-element-node-property-parser, org-element-planning-parser,
  org-element-table-row-parser): Add dummy :post-affiliated property.

* lisp/org.el (org--get-expected-indentation, org-indent-line,
  org-indent-region, org-adaptive-fill-function,
  org-toggle-fixed-width, org-forward-paragraph,
  org-backward-paragraph, org-mode-flyspell-verify): Remove nullity
  checks for :post-affiliated.

Even though these elements cannot have affiliated keywords, beginning
of element is a logical default value.  It makes checking the nullity
of the unnecessary.
Nicolas Goaziou 10 years ago
parent
commit
2593b4d878
2 changed files with 43 additions and 42 deletions
  1. 33 24
      lisp/org-element.el
  2. 10 18
      lisp/org.el

+ 33 - 24
lisp/org-element.el

@@ -73,9 +73,9 @@
 ;; refers to the element or object containing it.  Greater elements,
 ;; elements and objects containing objects will also have
 ;; `:contents-begin' and `:contents-end' properties to delimit
-;; contents.  Eventually, greater elements and elements accepting
-;; affiliated keywords will have a `:post-affiliated' property,
-;; referring to the buffer position after all such keywords.
+;; contents.  Eventually, All elements have a `:post-affiliated'
+;; property referring to the buffer position after all affiliated
+;; keywords, if any, or to their beginning position otherwise.
 ;;
 ;; At the lowest level, a `:parent' property is also attached to any
 ;; string, as a text property.
@@ -777,7 +777,8 @@ containing `:raw-value', `:title', `:alt-title', `:begin',
 `:end', `:pre-blank', `:contents-begin' and `:contents-end',
 `:level', `:priority', `:tags', `:todo-keyword',`:todo-type',
 `:scheduled', `:deadline', `:closed', `:archivedp', `:commentedp'
-`:footnote-section-p' and `:post-blank' keywords.
+`:footnote-section-p', `:post-blank' and `:post-affiliated'
+keywords.
 
 The plist also contains any property set in the property drawer,
 with its name in upper cases and colons added at the
@@ -902,7 +903,8 @@ Assume point is at beginning of the headline."
 				       end)
 			  :footnote-section-p footnote-section-p
 			  :archivedp archivedp
-			  :commentedp commentedp)
+			  :commentedp commentedp
+			  :post-affiliated begin)
 		    time-props
 		    standard-props))))
 	(let ((alt-title (org-element-property :ALT_TITLE headline)))
@@ -972,7 +974,7 @@ Return a list whose CAR is `inlinetask' and CDR is a plist
 containing `:title', `:begin', `:end', `:contents-begin' and
 `:contents-end', `:level', `:priority', `:raw-value', `:tags',
 `:todo-keyword', `:todo-type', `:scheduled', `:deadline',
-`:closed' and `:post-blank' keywords.
+`:closed', `:post-blank' and `:post-affiliated' keywords.
 
 The plist also contains any property set in the property drawer,
 with its name in upper cases and colons added at the
@@ -1076,7 +1078,8 @@ Assume point is at beginning of the inline task."
 			 :tags tags
 			 :todo-keyword todo
 			 :todo-type todo-type
-			 :post-blank (count-lines before-blank end))
+			 :post-blank (count-lines before-blank end)
+			 :post-affiliated begin)
 		   time-props
 		   standard-props))))
       (org-element-put-property
@@ -1135,8 +1138,8 @@ STRUCT is the structure of the plain list.
 
 Return a list whose CAR is `item' and CDR is a plist containing
 `:bullet', `:begin', `:end', `:contents-begin', `:contents-end',
-`:checkbox', `:counter', `:tag', `:structure' and `:post-blank'
-keywords.
+`:checkbox', `:counter', `:tag', `:structure', `:post-blank' and
+`:post-affiliated' keywords.
 
 When optional argument RAW-SECONDARY-P is non-nil, item's tag, if
 any, will not be parsed as a secondary string, but as a plain
@@ -1195,7 +1198,8 @@ Assume point is at the beginning of the item."
 			:checkbox checkbox
 			:counter counter
 			:structure struct
-			:post-blank (count-lines contents-end end)))))
+			:post-blank (count-lines contents-end end)
+			:post-affiliated begin))))
       (org-element-put-property
        item :tag
        (let ((raw-tag (org-list-get-tag begin struct)))
@@ -1483,8 +1487,8 @@ CONTENTS is the contents of the element."
 LIMIT bounds the search.
 
 Return a list whose CAR is `section' and CDR is a plist
-containing `:begin', `:end', `:contents-begin', `contents-end'
-and `:post-blank' keywords."
+containing `:begin', `:end', `:contents-begin', `contents-end',
+`:post-blank' and `:post-affiliated' keywords."
   (save-excursion
     ;; Beginning of section is the beginning of the first non-blank
     ;; line after previous headline.
@@ -1499,7 +1503,8 @@ and `:post-blank' keywords."
 		  :end end
 		  :contents-begin begin
 		  :contents-end pos-before-blank
-		  :post-blank (count-lines pos-before-blank end))))))
+		  :post-blank (count-lines pos-before-blank end)
+		  :post-affiliated begin)))))
 
 (defun org-element-section-interpreter (section contents)
   "Interpret SECTION element as Org syntax.
@@ -1629,8 +1634,8 @@ CONTENTS is nil."
 LIMIT bounds the search.
 
 Return a list whose CAR is `clock' and CDR is a plist containing
-`:status', `:value', `:time', `:begin', `:end' and `:post-blank'
-as keywords."
+`:status', `:value', `:time', `:begin', `:end', `:post-blank' and
+`:post-affiliated' as keywords."
   (save-excursion
     (let* ((case-fold-search nil)
 	   (begin (point))
@@ -1654,7 +1659,8 @@ as keywords."
 		  :duration duration
 		  :begin begin
 		  :end end
-		  :post-blank post-blank)))))
+		  :post-blank post-blank
+		  :post-affiliated begin)))))
 
 (defun org-element-clock-interpreter (clock contents)
   "Interpret CLOCK element as Org syntax.
@@ -2095,8 +2101,8 @@ CONTENTS is nil."
 LIMIT bounds the search.
 
 Return a list whose CAR is `node-property' and CDR is a plist
-containing `:key', `:value', `:begin', `:end' and `:post-blank'
-keywords."
+containing `:key', `:value', `:begin', `:end', `:post-blank' and
+`:post-affiliated' keywords."
   (save-excursion
     (looking-at org-property-re)
     (let ((case-fold-search t)
@@ -2111,7 +2117,8 @@ keywords."
 		  :value value
 		  :begin begin
 		  :end end
-		  :post-blank (count-lines pos-before-blank end))))))
+		  :post-blank (count-lines pos-before-blank end)
+		  :post-affiliated begin)))))
 
 (defun org-element-node-property-interpreter (node-property contents)
   "Interpret NODE-PROPERTY element as Org syntax.
@@ -2227,8 +2234,8 @@ CONTENTS is the contents of the element."
 LIMIT bounds the search.
 
 Return a list whose CAR is `planning' and CDR is a plist
-containing `:closed', `:deadline', `:scheduled', `:begin', `:end'
-and `:post-blank' keywords."
+containing `:closed', `:deadline', `:scheduled', `:begin',
+`:end', `:post-blank' and `:post-affiliated' keywords."
   (save-excursion
     (let* ((case-fold-search nil)
 	   (begin (point))
@@ -2254,7 +2261,8 @@ and `:post-blank' keywords."
 		  :scheduled scheduled
 		  :begin begin
 		  :end end
-		  :post-blank post-blank)))))
+		  :post-blank post-blank
+		  :post-affiliated begin)))))
 
 (defun org-element-planning-interpreter (planning contents)
   "Interpret PLANNING element as Org syntax.
@@ -2470,7 +2478,7 @@ LIMIT bounds the search.
 
 Return a list whose CAR is `table-row' and CDR is a plist
 containing `:begin', `:end', `:contents-begin', `:contents-end',
-`:type' and `:post-blank' keywords."
+`:type', `:post-blank' and `:post-affiliated' keywords."
   (save-excursion
     (let* ((type (if (looking-at "^[ \t]*|-") 'rule 'standard))
 	   (begin (point))
@@ -2491,7 +2499,8 @@ containing `:begin', `:end', `:contents-begin', `:contents-end',
 		  :end end
 		  :contents-begin contents-begin
 		  :contents-end contents-end
-		  :post-blank 0)))))
+		  :post-blank 0
+		  :post-affiliated begin)))))
 
 (defun org-element-table-row-interpreter (table-row contents)
   "Interpret TABLE-ROW element as Org syntax.

+ 10 - 18
lisp/org.el

@@ -22380,7 +22380,7 @@ ELEMENT."
 	      (if level (1+ level) 0))))
 	 ((item plain list)
 	  (org-list-item-body-column
-	   (or (org-element-property :post-affiliated element) start)))
+	   (org-element-property :post-affiliated element)))
 	 (otherwise
 	  (goto-char start)
 	  (org-get-indentation))))
@@ -22512,8 +22512,7 @@ Also align node properties according to `org-property-format'."
 	   (type (org-element-type element)))
       (cond ((and (memq type '(plain-list item))
 		  (= (line-beginning-position)
-		     (or (org-element-property :post-affiliated element)
-			 (org-element-property :begin element))))
+		     (org-element-property :post-affiliated element)))
 	     'noindent)
 	    ((and (eq type 'src-block)
 		  org-src-tab-acts-natively
@@ -22582,8 +22581,7 @@ assumed to be significant there."
 	      ;; according to the element type, or not indented at
 	      ;; all.  Other parts are indented as a single block.
 	      (let* ((post (copy-marker
-			    (or (org-element-property :post-affiliated element)
-				(org-element-property :begin element))))
+			    (org-element-property :post-affiliated element)))
 		     (cbeg
 		      (copy-marker
 		       (cond
@@ -22744,7 +22742,7 @@ matches in paragraphs or comments, use it."
 			 (org-element-at-point)))
 	      (type (org-element-type element))
 	      (post-affiliated (org-element-property :post-affiliated element)))
-	 (unless (and post-affiliated (< p post-affiliated))
+	 (unless (< p post-affiliated)
 	   (case type
 	     (comment
 	      (save-excursion
@@ -22753,10 +22751,7 @@ matches in paragraphs or comments, use it."
 		(concat (match-string 0) "# ")))
 	     (footnote-definition "")
 	     ((item plain-list)
-	      (make-string (org-list-item-body-column
-			    (or post-affiliated
-				(org-element-property :begin element)))
-			   ?\s))
+	      (make-string (org-list-item-body-column post-affiliated) ?\s))
 	     (paragraph
 	      ;; Fill prefix is usually the same as the current line,
 	      ;; unless the paragraph is at the beginning of an item.
@@ -22989,9 +22984,7 @@ region only contains such lines."
            ((and (memq type '(babel-call clock comment diary-sexp headline
 					 horizontal-rule keyword paragraph
 					 planning))
-		 (or (not (org-element-property :post-affiliated element))
-		     (<= (org-element-property :post-affiliated element)
-			 (point))))
+		 (<= (org-element-property :post-affiliated element) (point)))
             (skip-chars-forward " \t")
             (insert ": "))
            ((and (org-looking-at-p "[ \t]*$")
@@ -23946,7 +23939,7 @@ item, etc.  It also provides some special moves for convenience:
            (skip-chars-forward " \r\t\n")
            (or (eobp) (beginning-of-line)))
           ;; On affiliated keywords, move to element's beginning.
-          ((and post-affiliated (< (point) post-affiliated))
+          ((< (point) post-affiliated)
            (goto-char post-affiliated))
           ;; At a table row, move to the end of the table.  Similarly,
           ;; at a node property, move to the end of the property
@@ -24025,7 +24018,7 @@ convenience:
      ((= (point) begin)
       (backward-char)
       (org-backward-paragraph))
-     ((and post-affiliated (<= (point) post-affiliated)) (goto-char begin))
+     ((<= (point) post-affiliated) (goto-char begin))
      ((memq type '(node-property table-row))
       (goto-char (org-element-property
                   :post-affiliated (org-element-property :parent element))))
@@ -24521,7 +24514,7 @@ To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
 		   (otherwise t)))))))
       (cond
        ;; Ignore checks in all affiliated keywords but captions.
-       ((and post-affiliated (< (point) post-affiliated))
+       ((< (point) post-affiliated)
 	(and (save-excursion
 	       (beginning-of-line)
 	       (let ((case-fold-search t)) (looking-at "[ \t]*#\\+CAPTION:")))
@@ -24544,8 +24537,7 @@ To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
 	  ((comment quote-section) t)
 	  (comment-block
 	   ;; Allow checks between block markers, not on them.
-	   (and (> (line-beginning-position)
-		   (org-element-property :post-affiliated element))
+	   (and (> (line-beginning-position) post-affiliated)
 		(save-excursion
 		  (end-of-line)
 		  (skip-chars-forward " \r\t\n")