瀏覽代碼

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'.
Aaron Ecay 8 年之前
父節點
當前提交
d350baf2db
共有 5 個文件被更改,包括 33 次插入33 次删除
  1. 4 4
      lisp/ob-comint.el
  2. 14 14
      lisp/ob-core.el
  3. 12 12
      lisp/ob-eval.el
  4. 1 1
      lisp/ob-table.el
  5. 2 2
      lisp/ob-tangle.el

+ 4 - 4
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)

+ 14 - 14
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))

+ 12 - 12
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))
 

+ 1 - 1
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.

+ 2 - 2
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))))