1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-21 06:55:35 +00:00

ob-*: single armed “if” -> “when”

* lisp/ob-C.el (org-babel-C-val-to-base-type):
* lisp/ob-comint.el (org-babel-comint-buffer-livep):
* lisp/ob-fortran.el (org-babel-fortran-ensure-main-wrap):
* lisp/ob-octave.el (org-babel-octave-import-elisp-from-file):
* lisp/ob-scheme.el (org-babel-scheme-get-repl): Transform ‘if’ with
no else branch to ‘when’
* lisp/ob-lua.el (org-babel-lua-evaluate-external-process):
* lisp/ob-python.el (org-babel-python-evaluate-external-process):
Simplify conditional logic slightly.
This commit is contained in:
Aaron Ecay 2018-05-10 01:14:24 +01:00
parent 2b7677c097
commit ccfe51d83c
7 changed files with 14 additions and 15 deletions

View File

@ -373,8 +373,8 @@ FORMAT can be either a format string or a function which is called with VAL."
(pcase (org-babel-C-val-to-base-type v)
(`stringp (setq type 'stringp))
(`floatp
(if (or (not type) (eq type 'integerp))
(setq type 'floatp)))
(when (or (not type) (eq type 'integerp))
(setq type 'floatp)))
(`integerp
(unless type (setq type 'integerp)))))
val)

View File

@ -36,7 +36,7 @@
(defun org-babel-comint-buffer-livep (buffer)
"Check if BUFFER is a comint buffer with a live process."
(let ((buffer (if buffer (get-buffer buffer))))
(let ((buffer (when buffer (get-buffer buffer))))
(and buffer (buffer-live-p buffer) (get-buffer-process buffer) buffer)))
(defmacro org-babel-comint-in-buffer (buffer &rest body)

View File

@ -108,7 +108,7 @@ its header arguments."
"Wrap body in a \"program ... end program\" block if none exists."
(if (string-match "^[ \t]*program[ \t]*.*" (capitalize body))
(let ((vars (org-babel--get-vars params)))
(if vars (error "Cannot use :vars if `program' statement is present"))
(when vars (error "Cannot use :vars if `program' statement is present"))
body)
(format "program main\n%s\nend program main\n" body)))

View File

@ -290,13 +290,13 @@ last statement in BODY, as elisp."
(let ((raw
(pcase result-type
(`output (org-babel-eval org-babel-lua-command
(concat (if preamble (concat preamble "\n"))
(concat preamble (and preamble "\n")
body)))
(`value (let ((tmp-file (org-babel-temp-file "lua-")))
(org-babel-eval
org-babel-lua-command
(concat
(if preamble (concat preamble "\n") "")
preamble (and preamble "\n")
(format
(if (member "pp" result-params)
org-babel-lua-pp-wrapper-method

View File

@ -254,9 +254,9 @@ This removes initial blank and comment lines and then calls
(with-temp-file temp-file
(insert-file-contents file-name)
(re-search-forward "^[ \t]*[^# \t]" nil t)
(if (< (setq beg (point-min))
(setq end (point-at-bol)))
(delete-region beg end)))
(when (< (setq beg (point-min))
(setq end (point-at-bol)))
(delete-region beg end)))
(org-babel-import-elisp-from-file temp-file '(16))))
(provide 'ob-octave)

View File

@ -265,13 +265,13 @@ last statement in BODY, as elisp."
(let ((raw
(pcase result-type
(`output (org-babel-eval org-babel-python-command
(concat (if preamble (concat preamble "\n"))
(concat preamble (and preamble "\n")
body)))
(`value (let ((tmp-file (org-babel-temp-file "python-")))
(org-babel-eval
org-babel-python-command
(concat
(if preamble (concat preamble "\n") "")
preamble (and preamble "\n")
(format
(if (member "pp" result-params)
org-babel-python-pp-wrapper-method

View File

@ -112,10 +112,9 @@
(or buffer
(progn
(run-geiser impl)
(if name
(progn
(rename-buffer name t)
(org-babel-scheme-set-session-buffer name (current-buffer))))
(when name
(rename-buffer name t)
(org-babel-scheme-set-session-buffer name (current-buffer)))
(current-buffer)))))
(defun org-babel-scheme-make-session-name (buffer name impl)