summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ecay <aaronecay@gmail.com>2016-09-03 02:45:27 +0100
committerAaron Ecay <aaronecay@gmail.com>2016-09-03 02:45:27 +0100
commitd350baf2dbcdd97755d20dc96a8e6c06a6b195bc (patch)
treeb524c4fa8749b749f6394f36e3b9a59b5e2a864d
parent2510f6ec471f775048e27a4bfad16c3b6620e30d (diff)
downloadorg-mode-d350baf2dbcdd97755d20dc96a8e6c06a6b195bc.tar.gz
babel: change single-armed ‘if’ statements to ‘when’
* lisp/ob-comint.el (org-babel-comint-eval-invisibly-and-wait-for-file): * lisp/ob-core.el (org-babel-initiate-session): (org-babel-hide-result-toggle): (org-babel-insert-result): * lisp/ob-eval.el (org-babel--shell-command-on-region): * lisp/ob-table.el (org-babel-table-truncate-at-newline): * lisp/ob-tangle.el (org-babel-tangle): Change `if' without else to `when'.
-rw-r--r--lisp/ob-comint.el8
-rw-r--r--lisp/ob-core.el28
-rw-r--r--lisp/ob-eval.el24
-rw-r--r--lisp/ob-table.el2
-rw-r--r--lisp/ob-tangle.el4
5 files changed, 33 insertions, 33 deletions
diff --git a/lisp/ob-comint.el b/lisp/ob-comint.el
index 2e113af..8f32046 100644
--- a/lisp/ob-comint.el
+++ b/lisp/ob-comint.el
@@ -143,14 +143,14 @@ Don't return until FILE exists. Code in STRING must ensure that
FILE exists at end of evaluation."
(unless (org-babel-comint-buffer-livep buffer)
(error "Buffer %s does not exist or has no process" buffer))
- (if (file-exists-p file) (delete-file file))
+ (when (file-exists-p file) (delete-file file))
(process-send-string
(get-buffer-process buffer)
(if (= (aref string (1- (length string))) ?\n) string (concat string "\n")))
;; From Tramp 2.1.19 the following cache flush is not necessary
- (if (file-remote-p default-directory)
- (with-parsed-tramp-file-name default-directory nil
- (tramp-flush-directory-property v "")))
+ (when (file-remote-p default-directory)
+ (with-parsed-tramp-file-name default-directory nil
+ (tramp-flush-directory-property v "")))
(while (not (file-exists-p file)) (sit-for (or period 0.25))))
(provide 'ob-comint)
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index ec9198a..2f2a6f2 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -928,8 +928,8 @@ the session. Copy the body of the code block to the kill ring."
(or (and dir (file-name-as-directory dir)) default-directory))
(init-cmd (intern (format "org-babel-%s-initiate-session" lang)))
(prep-cmd (intern (concat "org-babel-prep-session:" lang))))
- (if (and (stringp session) (string= session "none"))
- (error "This block is not using a session!"))
+ (when (and (stringp session) (string= session "none"))
+ (error "This block is not using a session!"))
(unless (fboundp init-cmd)
(error "No org-babel-initiate-session function for %s!" lang))
(with-temp-buffer (insert (org-trim body))
@@ -1380,15 +1380,15 @@ portions of results lines."
(eq (overlay-get overlay 'invisible)
'org-babel-hide-result))
(overlays-at start)))
- (if (or (not force) (eq force 'off))
- (mapc (lambda (ov)
- (when (member ov org-babel-hide-result-overlays)
- (setq org-babel-hide-result-overlays
- (delq ov org-babel-hide-result-overlays)))
- (when (eq (overlay-get ov 'invisible)
- 'org-babel-hide-result)
- (delete-overlay ov)))
- (overlays-at start)))
+ (when (or (not force) (eq force 'off))
+ (mapc (lambda (ov)
+ (when (member ov org-babel-hide-result-overlays)
+ (setq org-babel-hide-result-overlays
+ (delq ov org-babel-hide-result-overlays)))
+ (when (eq (overlay-get ov 'invisible)
+ 'org-babel-hide-result)
+ (delete-overlay ov)))
+ (overlays-at start)))
(setq ov (make-overlay start end))
(overlay-put ov 'invisible 'org-babel-hide-result)
;; make the block accessible to isearch
@@ -2306,7 +2306,7 @@ INFO may provide the values of these header arguments (in the
(funcall wrap "#+BEGIN_EXPORT latex" "#+END_EXPORT" nil nil
"{{{results(@@latex:" "@@)}}}"))
((member "org" result-params)
- (goto-char beg) (if (org-at-table-p) (org-cycle))
+ (goto-char beg) (when (org-at-table-p) (org-cycle))
(funcall wrap "#+BEGIN_SRC org" "#+END_SRC" nil nil
"{{{results(src_org{" "})}}}"))
((member "code" result-params)
@@ -2316,11 +2316,11 @@ INFO may provide the values of these header arguments (in the
(format "{{{results(src_%s[%s]{" lang results-switches)
"})}}}")))
((member "raw" result-params)
- (goto-char beg) (if (org-at-table-p) (org-cycle)))
+ (goto-char beg) (when (org-at-table-p) (org-cycle)))
((or (member "drawer" result-params)
;; Stay backward compatible with <7.9.2
(member "wrap" result-params))
- (goto-char beg) (if (org-at-table-p) (org-cycle))
+ (goto-char beg) (when (org-at-table-p) (org-cycle))
(funcall wrap ":RESULTS:" ":END:" 'no-escape nil
"{{{results(" ")}}}"))
((and inline (member "file" result-params))
diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index e3be638..4a368b7 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -120,18 +120,18 @@ function in various versions of Emacs.
(delete-file input-file))
(when (and error-file (file-exists-p error-file))
- (if (< 0 (nth 7 (file-attributes error-file)))
- (with-current-buffer (get-buffer-create error-buffer)
- (let ((pos-from-end (- (point-max) (point))))
- (or (bobp)
- (insert "\f\n"))
- ;; Do no formatting while reading error file,
- ;; because that can run a shell command, and we
- ;; don't want that to cause an infinite recursion.
- (format-insert-file error-file nil)
- ;; Put point after the inserted errors.
- (goto-char (- (point-max) pos-from-end)))
- (current-buffer)))
+ (when (< 0 (nth 7 (file-attributes error-file)))
+ (with-current-buffer (get-buffer-create error-buffer)
+ (let ((pos-from-end (- (point-max) (point))))
+ (or (bobp)
+ (insert "\f\n"))
+ ;; Do no formatting while reading error file,
+ ;; because that can run a shell command, and we
+ ;; don't want that to cause an infinite recursion.
+ (format-insert-file error-file nil)
+ ;; Put point after the inserted errors.
+ (goto-char (- (point-max) pos-from-end)))
+ (current-buffer)))
(delete-file error-file))
exit-status))
diff --git a/lisp/ob-table.el b/lisp/ob-table.el
index 30e160b..efee5b7 100644
--- a/lisp/ob-table.el
+++ b/lisp/ob-table.el
@@ -63,7 +63,7 @@ If STRING ends in a newline character, then remove the newline
character and replace it with ellipses."
(if (and (stringp string) (string-match "[\n\r]\\(.\\)?" string))
(concat (substring string 0 (match-beginning 0))
- (if (match-string 1 string) "...")) string))
+ (when (match-string 1 string) "...")) string))
(defmacro org-sbe (source-block &rest variables)
"Return the results of calling SOURCE-BLOCK with VARIABLES.
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index 8562d6e..a64dc53 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -280,8 +280,8 @@ used to limit the exported source code blocks by language."
;; We avoid append-to-file as it does not work with tramp.
(let ((content (buffer-string)))
(with-temp-buffer
- (if (file-exists-p file-name)
- (insert-file-contents file-name))
+ (when (file-exists-p file-name)
+ (insert-file-contents file-name))
(goto-char (point-max))
;; Handle :padlines unless first line in file
(unless (or (string= "no" (cdr (assoc :padline (nth 4 spec))))