summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-01-28 17:11:48 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-02-10 15:40:10 +0100
commit88659208793dca18b7672428175e9a712af7b5ad (patch)
treebe25093c0fb3d97a5439f8359eb8a18704b895a7
parent5f94f49db063784f2ee9079e8d5c91a685412c60 (diff)
downloadorg-mode-88659208793dca18b7672428175e9a712af7b5ad.tar.gz
ob: Remove indentation information from Babel properties
* lisp/ob-core.el (org-babel-get-src-block-info): Do not return block indentation. (org-babel-parse-src-block-match): Ignore block indentation. (org-babel-demarcate-block): Find appropriate indentation instead of using the one from the original block. (org-babel-where-is-src-block-result): Change signature. Indent according to context instead of relying on indentation from original block. (org-babel-insert-result): Change signature. (org-babel-check-confirm-evaluate): (org-babel-execute-src-block): (org-babel-insert-header-arg): Apply change to src-block info. * lisp/ob-exp.el (org-babel-exp-process-buffer): Apply change to src-block info. * lisp/ob-lob.el (org-babel-lob-get-info): Do not return indentation. (org-babel-lob-execute): Apply change to lob-info. Indentation from source block is often wrong at the block and its results may not be in the same context.
-rw-r--r--lisp/ob-core.el59
-rw-r--r--lisp/ob-exp.el6
-rw-r--r--lisp/ob-lob.el34
3 files changed, 51 insertions, 48 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index bdd969f..79e7372 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -53,6 +53,7 @@
(declare-function with-parsed-tramp-file-name "tramp" (filename var &rest body))
(declare-function org-edit-src-code "org-src" (&optional code edit-buffer-name))
(declare-function org-edit-src-exit "org-src" ())
+(declare-function org-get-indentation "org" (&optional line))
(declare-function org-in-regexp "org" (regexp &optional nlines visually))
(declare-function org-open-at-point "org" (&optional in-emacs reference-buffer))
(declare-function org-save-outline-visibility "org-macs" (use-markers &rest body))
@@ -62,6 +63,7 @@
(declare-function org-split-string "org" (string &optional separators))
(declare-function org-entry-get "org"
(pom property &optional inherit literal-nil))
+(declare-function org-indent-line "org" ())
(declare-function org-make-options-regexp "org" (kwds &optional extra))
(declare-function org-do-remove-indentation "org" (&optional n))
(declare-function org-next-block "org" (arg &optional backward block-regexp))
@@ -252,15 +254,13 @@ references; a process which could likely result in the execution
of other code blocks.
Returns a list
- (language body header-arguments-alist switches name indent block-head)."
+ (language body header-arguments-alist switches name block-head)."
(let ((case-fold-search t) head info name indent)
;; full code block
(if (setq head (org-babel-where-is-src-block-head))
(save-excursion
(goto-char head)
(setq info (org-babel-parse-src-block-match))
- (setq indent (car (last info)))
- (setq info (butlast info))
(while (and (= 0 (forward-line -1))
(looking-at org-babel-multi-line-header-regexp))
(setf (nth 2 info)
@@ -278,7 +278,7 @@ Returns a list
(setf (nth 2 info) (org-babel-process-params (nth 2 info))))
(when info
(setf (nth 2 info) (org-babel-generate-file-param name (nth 2 info))))
- (when info (append info (list name indent head)))))
+ (when info (append info (list name head)))))
(defvar org-babel-exp-reference-buffer nil
"Buffer containing original contents of the exported buffer.
@@ -302,7 +302,7 @@ should be asked whether to allow evaluation."
(and export (equal eval "query-export"))
(if (functionp org-confirm-babel-evaluate)
(save-excursion
- (goto-char (nth 6 info))
+ (goto-char (nth 5 info))
(funcall org-confirm-babel-evaluate
;; language, code block body
(nth 0 info) (nth 1 info)))
@@ -640,7 +640,7 @@ block."
(interactive)
(let* ((org-babel-current-src-block-location
(or org-babel-current-src-block-location
- (nth 6 info)
+ (nth 5 info)
(org-babel-where-is-src-block-head)
;; inline src block
(and (org-babel-get-inline-src-block-matches)
@@ -683,7 +683,6 @@ block."
(or (org-bound-and-true-p
org-babel-call-process-region-original)
(symbol-function 'call-process-region)))
- (indent (nth 5 info))
result cmd)
(unwind-protect
(let ((call-process-region
@@ -740,7 +739,7 @@ block."
(setq result-params
(remove "file" result-params)))))
(org-babel-insert-result
- result result-params info new-hash indent lang))
+ result result-params info new-hash lang))
(run-hooks 'org-babel-after-execute-hook)
result)
(setq call-process-region
@@ -850,7 +849,7 @@ arguments and pop open the results in a preview buffer."
(interactive)
(let* ((info (org-babel-get-src-block-info 'light))
(lang (car info))
- (begin (nth 6 info))
+ (begin (nth 5 info))
(lang-headers (intern (concat "org-babel-header-args:" lang)))
(headers (org-babel-combine-header-arg-lists
org-babel-common-header-args-w-values
@@ -1453,8 +1452,7 @@ specified in the properties of the current outline entry."
(defvar org-src-preserve-indentation) ;; declare defcustom from org-src
(defun org-babel-parse-src-block-match ()
"Parse the results from a match of the `org-babel-src-block-regexp'."
- (let* ((block-indentation (string-width (match-string 1)))
- (lang (org-match-string-no-properties 2))
+ (let* ((lang (org-match-string-no-properties 2))
(lang-headers (intern (concat "org-babel-default-header-args:" lang)))
(switches (match-string 3))
(body (let* ((body (org-match-string-no-properties 5))
@@ -1480,8 +1478,7 @@ specified in the properties of the current outline entry."
(org-babel-params-from-properties lang)
(list (org-babel-parse-header-arguments
(org-no-properties (or (match-string 4) ""))))))
- switches
- block-indentation)))
+ switches)))
(defun org-babel-parse-inline-src-block-match ()
"Parse the results from a match of the `org-babel-inline-src-block-regexp'."
@@ -1877,7 +1874,7 @@ region is not active then the point is demarcated."
(save-excursion
(goto-char place)
(let ((lang (nth 0 info))
- (indent (make-string (nth 5 info) ? )))
+ (indent (make-string (org-get-indentation) ?\s)))
(when (string-match "^[[:space:]]*$"
(buffer-substring (point-at-bol)
(point-at-eol)))
@@ -1916,7 +1913,7 @@ region is not active then the point is demarcated."
(goto-char start) (move-end-of-line 1)))))
(defvar org-babel-lob-one-liner-regexp)
-(defun org-babel-where-is-src-block-result (&optional insert info hash indent)
+(defun org-babel-where-is-src-block-result (&optional insert info hash)
"Find where the current source block results begin.
Return the point at the beginning of the result of the current
source block. Specifically at the beginning of the results line.
@@ -1931,7 +1928,7 @@ following the source block."
(match-end 0)))
(name (nth 4 (or info (org-babel-get-src-block-info 'light))))
(head (unless on-lob-line (org-babel-where-is-src-block-head)))
- found beg end)
+ found beg end ind)
(when head (goto-char head))
(org-with-wide-buffer
(setq
@@ -1945,10 +1942,18 @@ following the source block."
;; - if it does need to be rebuilt then do set end
name (setq beg (org-babel-find-named-result name))
(prog1 beg
- (when (and hash (not (string= hash (match-string 5))))
- (goto-char beg) (setq end beg) ;; beginning of result
- (forward-line 1)
- (delete-region end (org-babel-result-end)) nil)))
+ (goto-char beg)
+ (setq ind (org-get-indentation))
+ (when hash
+ (looking-at org-babel-result-regexp)
+ (unless (string= (match-string 5) hash)
+ (setq end beg)
+ (let ((element (org-element-at-point)))
+ (delete-region
+ (org-element-property :begin element)
+ (progn (goto-char (org-element-property :end element))
+ (skip-chars-backward " \t\n")
+ (line-beginning-position 2))))))))
(and
;; unnamed results:
;; - return t if it is found, else return nil
@@ -1965,6 +1970,7 @@ following the source block."
(beginning-of-line 1)
(cond
((looking-at (concat org-babel-result-regexp "\n"))
+ (setq ind (org-get-indentation))
(throw 'non-comment t))
((and (looking-at "^[ \t]*#")
(not (looking-at
@@ -1985,7 +1991,11 @@ following the source block."
(goto-char end)
(unless beg
(if (looking-at "[\n\r]") (forward-char 1) (insert "\n")))
- (when (wholenump indent) (indent-to indent))
+ (if ind (indent-to ind)
+ ;; Open line to properly indent.
+ (save-excursion (insert "\n"))
+ (org-indent-line)
+ (delete-char 1))
(insert (concat
"#+" org-babel-results-keyword
(when hash
@@ -2097,8 +2107,7 @@ If the path of the link is a file path it is expanded using
;; scalar result
(funcall echo-res result))))
-(defun org-babel-insert-result
- (result &optional result-params info hash indent lang)
+(defun org-babel-insert-result (result &optional result-params info hash lang)
"Insert RESULT into the current buffer.
By default RESULT is inserted after the end of the current source
@@ -2197,7 +2206,7 @@ INFO may provide the values of these header arguments (in the
(point))))
(existing-result
(unless inlinep
- (org-babel-where-is-src-block-result t info hash indent)))
+ (org-babel-where-is-src-block-result t info hash)))
(bad-inline-p
(when inlinep
(or
@@ -2215,7 +2224,7 @@ INFO may provide the values of these header arguments (in the
(outside-scope-p (and existing-result
(or (> visible-beg existing-result)
(<= visible-end existing-result))))
- beg end)
+ beg end indent)
(when (and (stringp result) ; ensure results end in a newline
(not inlinep)
(> (length result) 0)
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index f63bf22..22ebf9c 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -228,10 +228,10 @@ may make them unreachable."
(org-no-properties
(concat
":var results="
- (mapconcat 'identity
- (butlast lob-info 2)
+ (mapconcat #'identity
+ (butlast lob-info)
" ")))))))
- "" (nth 3 lob-info) (nth 2 lob-info))
+ "" (nth 2 lob-info))
'lob))
(rep (org-fill-template
org-babel-exp-call-line-template
diff --git a/lisp/ob-lob.el b/lisp/ob-lob.el
index bb8aae7..1318724 100644
--- a/lisp/ob-lob.el
+++ b/lisp/ob-lob.el
@@ -108,32 +108,26 @@ from `inline-babel-call' or `babel-call' DATUM, when provided."
(if in (format "[%s]" in) ""))
(or (org-element-property :arguments context) ""))
(org-element-property :end-header context)
- (string-width ;Indentation.
- (org-with-wide-buffer
- (goto-char (org-element-property :begin context))
- (buffer-substring-no-properties
- (line-beginning-position) (point))))
(org-element-property :name context)))))
(defvar org-babel-default-header-args:emacs-lisp) ; Defined in ob-emacs-lisp.el
(defun org-babel-lob-execute (info)
"Execute the lob call specified by INFO."
(let* ((mkinfo (lambda (p)
- (list "emacs-lisp" "results" p nil
- (nth 3 info) ;; name
- (nth 2 info))))
- (pre-params (apply #'org-babel-merge-params
- org-babel-default-header-args
- org-babel-default-header-args:emacs-lisp
- (append
- (org-babel-params-from-properties)
- (list
- (org-babel-parse-header-arguments
- (org-no-properties
- (concat
- ":var results="
- (mapconcat #'identity (butlast info 2)
- " "))))))))
+ ;; Make plist P compatible with
+ ;; `org-babel-get-src-block-info'.
+ (list "emacs-lisp" "results" p nil (nth 2 info))))
+ (pre-params
+ (apply #'org-babel-merge-params
+ org-babel-default-header-args
+ org-babel-default-header-args:emacs-lisp
+ (append
+ (org-babel-params-from-properties)
+ (list
+ (org-babel-parse-header-arguments
+ (org-no-properties
+ (concat ":var results="
+ (mapconcat #'identity (butlast info) " "))))))))
(pre-info (funcall mkinfo pre-params))
(cache-p (and (cdr (assoc :cache pre-params))
(string= "yes" (cdr (assoc :cache pre-params)))))