summaryrefslogtreecommitdiff
path: root/lisp/ob-core.el
diff options
context:
space:
mode:
authorSébastien Delafond <sdelafond@gmail.com>2016-03-16 09:54:05 +0100
committerSébastien Delafond <sdelafond@gmail.com>2016-03-16 09:54:05 +0100
commit7534ff9598bd34a99bbf5c6225f0b850b4b04e29 (patch)
tree8725bf84bc3c502417a4172961520c98216ca8d1 /lisp/ob-core.el
parent429ffc1240438c683f885944b7a2259924adca52 (diff)
parent84539dca3aa301ecfe48858eceef1ced0505388b (diff)
Merge tag 'upstream/8.3.4'
Upstream version 8.3.4
Diffstat (limited to 'lisp/ob-core.el')
-rw-r--r--lisp/ob-core.el78
1 files changed, 58 insertions, 20 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 617ef69..fcd15c4 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -1,6 +1,6 @@
;;; ob-core.el --- working with code blocks in org-mode
-;; Copyright (C) 2009-2015 Free Software Foundation, Inc.
+;; Copyright (C) 2009-2016 Free Software Foundation, Inc.
;; Authors: Eric Schulte
;; Dan Davison
@@ -33,12 +33,16 @@
(if (memq system-type '(windows-nt cygwin))
".exe"
nil))
+
;; dynamically scoped for tramp
(defvar org-babel-call-process-region-original nil)
-(defvar org-src-lang-modes)
(defvar org-babel-library-of-babel)
+(defvar org-edit-src-content-indentation)
+(defvar org-src-lang-modes)
+
(declare-function outline-show-all "outline" ())
(declare-function org-every "org" (pred seq))
+(declare-function org-get-indentation "org" (&optional line))
(declare-function org-remove-indentation "org" (code &optional n))
(declare-function org-reduce "org" (CL-FUNC CL-SEQ &rest CL-KEYS))
(declare-function org-mark-ring-push "org" (&optional pos buffer))
@@ -99,6 +103,7 @@
(declare-function org-element-context "org-element" (&optional element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-at-point "org-element" ())
+(declare-function org-element-normalize-string "org-element" (s))
(declare-function org-element-property "org-element" (property element))
(declare-function org-every "org" (pred seq))
(declare-function org-macro-escape-arguments "org-macro" (&rest args))
@@ -260,7 +265,7 @@ Returns a list
(setq info (org-babel-parse-src-block-match))
(setq indent (car (last info)))
(setq info (butlast info))
- (while (and (forward-line -1)
+ (while (and (= 0 (forward-line -1))
(looking-at org-babel-multi-line-header-regexp))
(setf (nth 2 info)
(org-babel-merge-params
@@ -317,6 +322,8 @@ name of the code block."
org-confirm-babel-evaluate)))
(code-block (if ,info (format " %s " ,lang) " "))
(block-name (if ,name (format " (%s) " ,name) " ")))
+ ;; Silence byte-compiler if `body' doesn't use those vars.
+ (ignore noeval query)
,@body)))
(defsubst org-babel-check-evaluate (info)
@@ -613,6 +620,8 @@ multiple blocks are being executed (e.g., in chained execution
through use of the :var header argument) this marker points to
the outer-most code block.")
+(defvar *this*)
+
;;;###autoload
(defun org-babel-execute-src-block (&optional arg info params)
"Execute the current source code block.
@@ -660,7 +669,8 @@ block."
(skip-chars-forward " \t")
(let ((result (org-babel-read-result)))
(message (replace-regexp-in-string
- "%" "%%" (format "%S" result))) result)))
+ "%" "%%" (format "%S" result)))
+ result)))
((org-babel-confirm-evaluate
(let ((i info)) (setf (nth 2 i) merged-params) i))
(let* ((lang (nth 0 info))
@@ -756,7 +766,7 @@ org-babel-expand-body:lang function."
"\n")))
;;;###autoload
-(defun org-babel-expand-src-block (&optional arg info params)
+(defun org-babel-expand-src-block (&optional _arg info params)
"Expand the current source code block.
Expand according to the source code block's header
arguments and pop open the results in a preview buffer."
@@ -809,8 +819,7 @@ arguments and pop open the results in a preview buffer."
(let ((results (copy-sequence original)))
(dolist (new-list others)
(dolist (arg-pair new-list)
- (let ((header (car arg-pair))
- (args (cdr arg-pair)))
+ (let ((header (car arg-pair)))
(setq results
(cons arg-pair (org-remove-if
(lambda (pair) (equal header (car pair)))
@@ -903,7 +912,7 @@ arguments and pop open the results in a preview buffer."
(add-hook 'org-tab-first-hook 'org-babel-header-arg-expand)
;;;###autoload
-(defun org-babel-load-in-session (&optional arg info)
+(defun org-babel-load-in-session (&optional _arg info)
"Load the body of the current source-code block.
Evaluate the header arguments for the source block before
entering the session. After loading the body this pops open the
@@ -972,7 +981,7 @@ with a prefix argument then this is passed on to
(defvar org-src-window-setup)
;;;###autoload
-(defun org-babel-switch-to-session-with-code (&optional arg info)
+(defun org-babel-switch-to-session-with-code (&optional arg _info)
"Switch to code buffer and display session."
(interactive "P")
(let ((swap-windows
@@ -1098,7 +1107,13 @@ end-body --------- point at the end of the body"
(body (match-string 5))
(beg-body (match-beginning 5))
(end-body (match-end 5)))
- ,@body
+ ;; Silence byte-compiler in case `body' doesn't use all
+ ;; those variables.
+ (ignore full-block beg-block end-block lang
+ beg-lang end-lang switches beg-switches
+ end-switches header-args beg-header-args
+ end-header-args body beg-body end-body)
+ ,@body
(goto-char end-block)))))
(unless visited-p (kill-buffer to-be-removed))
(goto-char point))))
@@ -1625,7 +1640,7 @@ Note: this function removes any hlines in TABLE."
(rownames (funcall (lambda ()
(let ((tp table))
(mapcar
- (lambda (row)
+ (lambda (_row)
(prog1
(pop (car tp))
(setq tp (cdr tp))))
@@ -1699,13 +1714,17 @@ to the table for reinsertion to org-mode."
(org-babel-put-colnames table colnames) table))
table))
-(defun org-babel-where-is-src-block-head ()
+(defun org-babel-where-is-src-block-head (&optional src-block)
"Find where the current source block begins.
+
+If optional argument SRC-BLOCK is `src-block' type element, find
+its current beginning instead.
+
Return the point at the beginning of the current source block.
Specifically at the beginning of the #+BEGIN_SRC line. Also set
match-data relatively to `org-babel-src-block-regexp', which see.
If the point is not on a source block then return nil."
- (let ((element (org-element-at-point)))
+ (let ((element (or src-block (org-element-at-point))))
(when (eq (org-element-type element) 'src-block)
(let ((end (org-element-property :end element)))
(org-with-wide-buffer
@@ -1803,7 +1822,8 @@ buffer or nil if no such result exists."
(catch 'is-a-code-block
(when (re-search-forward
(concat org-babel-result-regexp
- "[ \t]" (regexp-quote name) "[ \t]*[\n\f\v\r]") nil t)
+ "[ \t]" (regexp-quote name) "[ \t]*[\n\f\v\r]")
+ nil t)
(when (and (string= "name" (downcase (match-string 1)))
(or (beginning-of-line 1)
(looking-at org-babel-src-block-regexp)
@@ -2449,12 +2469,30 @@ file's directory then expand relative links."
(defun org-babel-update-block-body (new-body)
"Update the body of the current code block to NEW-BODY."
- (if (not (org-babel-where-is-src-block-head))
- (error "Not in a source block")
- (save-match-data
- (replace-match (concat (org-babel-trim (org-remove-indentation new-body))
- "\n") nil t nil 5))
- (indent-rigidly (match-beginning 5) (match-end 5) 2)))
+ (let ((element (org-element-at-point)))
+ (unless (eq (org-element-type element) 'src-block)
+ (error "Not in a source block"))
+ (goto-char (org-babel-where-is-src-block-head element))
+ (let* ((ind (org-get-indentation))
+ (body-start (line-beginning-position 2))
+ (body (org-element-normalize-string
+ (if (or org-src-preserve-indentation
+ (org-element-property :preserve-indent element))
+ new-body
+ (with-temp-buffer
+ (insert (org-remove-indentation new-body))
+ (indent-rigidly
+ (point-min)
+ (point-max)
+ (+ ind org-edit-src-content-indentation))
+ (buffer-string))))))
+ (delete-region body-start
+ (org-with-wide-buffer
+ (goto-char (org-element-property :end element))
+ (skip-chars-backward " \t\n")
+ (line-beginning-position)))
+ (goto-char body-start)
+ (insert body))))
(defun org-babel-merge-params (&rest plists)
"Combine all parameter association lists in PLISTS.