Browse Source

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.
Aaron Ecay 1 year ago
parent
commit
ccfe51d83c
7 changed files with 14 additions and 15 deletions
  1. 2 2
      lisp/ob-C.el
  2. 1 1
      lisp/ob-comint.el
  3. 1 1
      lisp/ob-fortran.el
  4. 2 2
      lisp/ob-lua.el
  5. 3 3
      lisp/ob-octave.el
  6. 2 2
      lisp/ob-python.el
  7. 3 4
      lisp/ob-scheme.el

+ 2 - 2
lisp/ob-C.el

@@ -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)

+ 1 - 1
lisp/ob-comint.el

@@ -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)

+ 1 - 1
lisp/ob-fortran.el

@@ -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)))
 

+ 2 - 2
lisp/ob-lua.el

@@ -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

+ 3 - 3
lisp/ob-octave.el

@@ -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)

+ 2 - 2
lisp/ob-python.el

@@ -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

+ 3 - 4
lisp/ob-scheme.el

@@ -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)