From 6b4db0a978cc3492f0d0ac7e29008de6846fbe4a Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Mon, 16 May 2016 10:58:01 -0400 Subject: [PATCH] ox: provide [+-]n functionality --- contrib/lisp/ox-groff.el | 4 ++-- lisp/org-element.el | 16 +++++++++++----- lisp/ox-html.el | 4 ++-- lisp/ox-latex.el | 4 ++-- lisp/ox-odt.el | 4 ++-- lisp/ox.el | 16 ++++++++++------ 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/contrib/lisp/ox-groff.el b/contrib/lisp/ox-groff.el index b49edce..517da9a 100644 --- a/contrib/lisp/ox-groff.el +++ b/contrib/lisp/ox-groff.el @@ -1488,9 +1488,9 @@ contextual information." (custom-env (and lang (cadr (assq (intern lang) org-groff-custom-lang-environments)))) - (num-start (case (org-element-property :number-lines src-block) + (num-start (case (car (org-element-property :number-lines src-block)) (continued (org-export-get-loc src-block info)) - (new 0))) + (new (or (cdr (org-element-property :number-lines src-block)) 0)))) (retain-labels (org-element-property :retain-labels src-block)) (caption (and (not (org-export-read-attribute :attr_groff src-block :disable-caption)) diff --git a/lisp/org-element.el b/lisp/org-element.el index 368da60..65f9833 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -1896,8 +1896,11 @@ containing `:begin', `:end', `:number-lines', `:preserve-indent', ;; Switches analysis (number-lines (cond ((not switches) nil) - ((string-match "-n\\>" switches) 'new) - ((string-match "+n\\>" switches) 'continued))) + ((string-match "-n *\\([0-9]+\\)" switches) (cons 'new (- (string-to-number (match-string 1 switches)) 1 ))) + ((string-match "+n *\\([0-9]+\\)" switches) (cons 'continued (- (string-to-number (match-string 1 switches)) 1 ))) + ((string-match "-n" switches) (cons 'new 0)) + ((string-match "+n" switches) (cons 'continued 0)) + )) (preserve-indent (and switches (string-match "-i\\>" switches))) ;; Should labels be retained in (or stripped from) example @@ -2393,7 +2396,7 @@ Assume point is at the beginning of the block." (looking-at (concat "^[ \t]*#\\+BEGIN_SRC" "\\(?: +\\(\\S-+\\)\\)?" - "\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)+\\)?" + "\\(\\(?: +\\(?:-l \".+\"\\|[+-]n *[[:digit:]]+\\|[+-][[:alpha:]]\\)\\)+\\)?" "\\(.*\\)[ \t]*$")) (org-match-string-no-properties 1))) ;; Get switches. @@ -2403,8 +2406,11 @@ Assume point is at the beginning of the block." ;; Switches analysis (number-lines (cond ((not switches) nil) - ((string-match "-n\\>" switches) 'new) - ((string-match "+n\\>" switches) 'continued))) + ((string-match "-n *\\([0-9]+\\)" switches) (cons 'new (- (string-to-number (match-string 1 switches)) 1 ))) + ((string-match "+n *\\([0-9]+\\)" switches) (cons 'continued (- (string-to-number (match-string 1 switches)) 1 ))) + ((string-match "-n" switches) (cons 'new 0)) + ((string-match "+n" switches) (cons 'continued 0)) + )) (preserve-indent (and switches (string-match "-i\\>" switches))) (label-fmt diff --git a/lisp/ox-html.el b/lisp/ox-html.el index b188c38..5503d9e 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2209,9 +2209,9 @@ a plist used as a communication channel." ;; Does the src block contain labels? (retain-labels (org-element-property :retain-labels element)) ;; Does it have line numbers? - (num-start (case (org-element-property :number-lines element) + (num-start (case (car (org-element-property :number-lines element)) (continued (org-export-get-loc element info)) - (new 0)))) + (new (or (cdr (org-element-property :number-lines element)) 0))))) (org-html-do-format-code code lang refs retain-labels num-start))) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 7fa68c5..0159d48 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -2762,9 +2762,9 @@ contextual information." (custom-env (and lang (cadr (assq (intern lang) org-latex-custom-lang-environments)))) - (num-start (case (org-element-property :number-lines src-block) + (num-start (case (car (org-element-property :number-lines src-block)) (continued (org-export-get-loc src-block info)) - (new 0))) + (new (or (cdr (org-element-property :number-lines src-block)) 0)))) (retain-labels (org-element-property :retain-labels src-block)) (attributes (org-export-read-attribute :attr_latex src-block)) (float (plist-get attributes :float)) diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index d996689..9acf3c6 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -3168,9 +3168,9 @@ and prefix with \"OrgSrc\". For example, ;; Does the src block contain labels? (retain-labels (org-element-property :retain-labels element)) ;; Does it have line numbers? - (num-start (case (org-element-property :number-lines element) + (num-start (case (car (org-element-property :number-lines element)) (continued (org-export-get-loc element info)) - (new 0)))) + (new (or (cdr (org-element-property :number-lines element)) 0))))) (org-odt-do-format-code code info lang refs retain-labels num-start))) (defun org-odt-src-block (src-block _contents info) diff --git a/lisp/ox.el b/lisp/ox.el index 5ad17ec..c05f55e 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -4148,9 +4148,9 @@ error if no block contains REF." (when (re-search-backward ref-re nil t) (cond ((org-element-property :use-labels el) ref) - ((eq (org-element-property :number-lines el) 'continued) + ((eq (car (org-element-property :number-lines el)) 'continued) (+ (org-export-get-loc el info) (line-number-at-pos))) - (t (line-number-at-pos))))))) + (t (+ (or (cdr (org-element-property :number-lines el)) 0) (line-number-at-pos)))))))) info 'first-match) (signal 'org-link-broken (list ref)))) @@ -4467,15 +4467,19 @@ ELEMENT is excluded from count." ;; Only count lines from src-block and example-block elements ;; with a "+n" or "-n" switch. A "-n" switch resets counter. ((not (memq (org-element-type el) '(src-block example-block))) nil) - ((let ((linums (org-element-property :number-lines el))) + ((let* ((linums (org-element-property :number-lines el))) (when linums ;; Accumulate locs or reset them. (let ((lines (org-count-lines (org-trim (org-element-property :value el))))) - (setq loc (if (eq linums 'new) lines (+ loc lines)))))) + (setq loc (if (eq (car linums) 'new) + (+ lines (cdr linums)) + (+ loc lines (cdr linums))))))) ;; Return nil to stay in the loop. nil))) info 'first-match) + (if (eq (car (org-element-property :number-lines element)) 'continued) + (setq loc (+ (or (cdr (org-element-property :number-lines element)) 0) loc))) ;; Return value. loc)) @@ -4573,9 +4577,9 @@ code." (let* ((refs (and (org-element-property :retain-labels element) (cdr code-info))) ;; Handle line numbering. - (num-start (cl-case (org-element-property :number-lines element) + (num-start (cl-case (car (org-element-property :number-lines element)) (continued (org-export-get-loc element info)) - (new 0))) + (new (or (cdr (org-element-property :number-lines element)) 0)))) (num-fmt (and num-start (format "%%%ds " -- 2.8.2