From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: [PATCH 1/3] Add :begin-line and :end-line to parser results Date: Sun, 31 Mar 2013 23:14:59 -0400 Message-ID: <1364786101-16603-2-git-send-email-aaronecay@gmail.com> References: <1364786101-16603-1-git-send-email-aaronecay@gmail.com> Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMVDI-0002On-Jt for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 23:15:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMVDG-0003h6-Ck for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 23:15:16 -0400 Received: from mail-qe0-f53.google.com ([209.85.128.53]:60105) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMVDG-0003h2-7A for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 23:15:14 -0400 Received: by mail-qe0-f53.google.com with SMTP id q19so1016778qeb.40 for ; Sun, 31 Mar 2013 20:15:13 -0700 (PDT) In-Reply-To: <1364786101-16603-1-git-send-email-aaronecay@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org * lisp/org-element.el: Add :begin-line and :end-line to parser results These properties give the line on which an element begins/ends --- lisp/org-element.el | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/lisp/org-element.el b/lisp/org-element.el index e09d2cb..c074092 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -521,6 +521,8 @@ Assume point is at the beginning of the block." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :hiddenp hidden :contents-begin contents-begin :contents-end contents-end @@ -575,6 +577,8 @@ Assume point is at beginning of drawer." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :drawer-name name :hiddenp hidden :contents-begin contents-begin @@ -635,6 +639,8 @@ Assume point is at beginning of dynamic block." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :block-name name :arguments arguments :hiddenp hidden @@ -696,6 +702,8 @@ Assume point is at the beginning of the footnote definition." (list :label label :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :post-blank (count-lines ending end) @@ -812,6 +820,8 @@ Assume point is at beginning of the headline." (list :raw-value raw-value :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :pre-blank (if (not contents-begin) 0 (count-lines pos-after-head contents-begin)) @@ -977,6 +987,8 @@ Assume point is at beginning of the inline task." (list :raw-value raw-value :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :hiddenp hidden :contents-begin contents-begin :contents-end contents-end @@ -1096,6 +1108,8 @@ Assume point is at the beginning of the item." (list :bullet bullet :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) ;; CONTENTS-BEGIN and CONTENTS-END may be ;; mixed up in the case of an empty item ;; separated from the next by a blank line. @@ -1181,6 +1195,8 @@ Assume point is at the beginning of the list." (list :type type :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :structure struct @@ -1238,6 +1254,8 @@ Assume point is at the beginning of the property drawer." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :hiddenp hidden :contents-begin contents-begin :contents-end contents-end @@ -1291,6 +1309,8 @@ Assume point is at the beginning of the block." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :hiddenp hidden :contents-begin contents-begin :contents-end contents-end @@ -1326,6 +1346,8 @@ and `:post-blank' keywords." (list 'section (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin begin :contents-end pos-before-blank :post-blank (count-lines pos-before-blank end)))))) @@ -1381,9 +1403,14 @@ Assume point is at the beginning of the block." (list :type type :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :hiddenp hidden :contents-begin contents-begin :contents-end contents-end + :contents (and contents-begin contents-end + (buffer-substring-no-properties + contents-begin contents-end)) :post-blank (count-lines pos-before-blank end) :post-affiliated post-affiliated) (cdr affiliated))))))))) @@ -1437,6 +1464,8 @@ containing `:begin', `:end', `:info', `:post-blank' and (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :info info :post-blank (count-lines pos-before-blank end) :post-affiliated post-affiliated) @@ -1488,6 +1517,8 @@ as keywords." :duration duration :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank post-blank))))) (defun org-element-clock-interpreter (clock contents) @@ -1547,6 +1578,8 @@ Assume point is at comment beginning." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :value value :post-blank (count-lines com-end end) :post-affiliated post-affiliated) @@ -1596,6 +1629,8 @@ Assume point is at comment block beginning." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :value value :hiddenp hidden :post-blank (count-lines pos-before-blank end) @@ -1636,6 +1671,8 @@ containing `:begin', `:end', `:value', `:post-blank' and (list :value value :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank (count-lines pos-before-blank end) :post-affiliated post-affiliated) (cdr affiliated)))))) @@ -1708,6 +1745,8 @@ keywords." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :value value :switches switches :number-lines number-lines @@ -1772,6 +1811,8 @@ Assume point is at export-block beginning." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :type type :value value :hiddenp hidden @@ -1826,6 +1867,8 @@ Assume point is at the beginning of the fixed-width area." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :value value :post-blank (count-lines end-area end) :post-affiliated post-affiliated) @@ -1862,6 +1905,8 @@ keywords." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank (count-lines post-hr end) :post-affiliated post-affiliated) (cdr affiliated)))))) @@ -1902,6 +1947,8 @@ containing `:key', `:value', `:begin', `:end', `:post-blank' and :value value :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank (count-lines pos-before-blank end) :post-affiliated post-affiliated) (cdr affiliated)))))) @@ -1948,6 +1995,8 @@ Assume point is at the beginning of the latex environment." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :value value :post-blank (count-lines code-end end) :post-affiliated code-begin) @@ -1983,6 +2032,8 @@ keywords." :value value :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank (count-lines pos-before-blank end)))))) (defun org-element-node-property-interpreter (node-property contents) @@ -2080,6 +2131,8 @@ Assume point is at the beginning of the paragraph." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :post-blank (count-lines before-blank end) @@ -2127,6 +2180,8 @@ and `:post-blank' keywords." :scheduled scheduled :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank post-blank))))) (defun org-element-planning-interpreter (planning contents) @@ -2172,6 +2227,8 @@ Assume point is at beginning of the section." (list 'quote-section (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :value value :post-blank (count-lines pos-before-blank end)))))) @@ -2260,6 +2317,8 @@ Assume point is at the beginning of the block." (org-trim parameters)) :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :number-lines number-lines :preserve-indent preserve-indent :retain-labels retain-labels @@ -2334,6 +2393,8 @@ Assume point is at the beginning of the table." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :type type :tblfm tblfm ;; Only `org' tables have contents. `table.el' tables @@ -2389,6 +2450,8 @@ containing `:begin', `:end', `:contents-begin', `:contents-end', (list :type type :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :post-blank 0))))) @@ -2436,6 +2499,8 @@ Assume point is at beginning of the block." (nconc (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :hiddenp hidden @@ -2498,6 +2563,8 @@ Assume point is at the first star marker." (list 'bold (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :post-blank post-blank))))) @@ -2551,6 +2618,8 @@ Assume point is at the first tilde marker." (list :value value :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank post-blank))))) (defun org-element-code-interpreter (code contents) @@ -2589,6 +2658,8 @@ Assume point is at the beginning of the entity." :utf-8 (nth 6 value) :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :use-brackets-p bracketsp :post-blank post-blank))))) @@ -2660,6 +2731,8 @@ Assume point is at the beginning of the snippet." :value value :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank post-blank))))) (defun org-element-export-snippet-interpreter (export-snippet contents) @@ -2716,6 +2789,8 @@ and `:post-blank' as keywords." :type type :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank post-blank)))) (org-element-put-property footnote-reference :inline-definition @@ -2776,6 +2851,8 @@ Assume point is at the beginning of the babel call." (list 'inline-babel-call (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :info info :post-blank post-blank))))) @@ -2837,6 +2914,8 @@ Assume point is at the beginning of the inline src block." :parameters parameters :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank post-blank))))) (defun org-element-inline-src-block-interpreter (inline-src-block contents) @@ -2884,6 +2963,8 @@ Assume point is at the first slash marker." (list 'italic (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :post-blank post-blank))))) @@ -2927,6 +3008,8 @@ Assume point is at the beginning of the latex fragment." (list :value value :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank post-blank))))) (defun org-element-latex-fragment-interpreter (latex-fragment contents) @@ -3060,6 +3143,8 @@ Assume point is at the beginning of the link." :search-option search-option :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :post-blank post-blank))))) @@ -3136,6 +3221,8 @@ Assume point is at the macro." :args args :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank post-blank))))) (defun org-element-macro-interpreter (macro contents) @@ -3179,6 +3266,8 @@ Assume point is at the radio target." (list 'radio-target (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :post-blank post-blank @@ -3221,6 +3310,8 @@ Assume point is at the beginning of the statistics-cookie." (list 'statistics-cookie (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :value value :post-blank post-blank))))) @@ -3263,6 +3354,8 @@ Assume point is at the first plus sign marker." (list 'strike-through (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :post-blank post-blank))))) @@ -3298,6 +3391,8 @@ Assume point is at the underscore." (list 'subscript (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :use-brackets-p bracketsp :contents-begin contents-begin :contents-end contents-end @@ -3348,6 +3443,8 @@ Assume point is at the caret." (list 'superscript (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :use-brackets-p bracketsp :contents-begin contents-begin :contents-end contents-end @@ -3377,6 +3474,8 @@ and `:post-blank' keywords." (list 'table-cell (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :post-blank 0)))) @@ -3415,6 +3514,8 @@ Assume point is at the target." (list 'target (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :value value :post-blank post-blank))))) @@ -3518,6 +3619,8 @@ Assume point is at the beginning of the timestamp." :minute-end minute-end :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank post-blank) repeater-props))))) @@ -3649,6 +3752,8 @@ Assume point is at the first underscore marker." (list 'underline (list :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :contents-begin contents-begin :contents-end contents-end :post-blank post-blank))))) @@ -3680,6 +3785,8 @@ Assume point is at the first equal sign marker." (list :value value :begin begin :end end + :begin-line (org-element--line-number-at-pos begin) + :end-line (org-element--line-number-at-pos end) :post-blank post-blank))))) (defun org-element-verbatim-interpreter (verbatim contents) @@ -4876,6 +4983,19 @@ end of ELEM-A." (cdr overlays))) (goto-char (org-element-property :end elem-B))))) +(defun org-element--line-number-at-pos (pos) + "Return the buffer line number at POS, widening if necessary. + +In the case of a temporary buffer being prepared for export, this +function looks for text properties (inserted if +`org-export-with-concordance' is set to t) which allow it to +return the line number in the original buffer, irrespective of +changes the export process makes." + (or (get-text-property pos 'org-line-num-pre) + (save-excursion + (widen) + (line-number-at-pos pos)))) + (provide 'org-element) ;; Local variables: -- 1.8.2