Skip to content

Commit a6c40a4

Browse files
committed
Reduce length of some variable names
* ob-jupyter.el (org-babel-jupyter-initiate-session-by-key): Get rid of unnecessary variable. (org-babel-jupyter-cleanup-file-links): result-pos -> pos, link-path -> path, link-dir -> dir. Add resource-dir variable to avoid calculating the same thing in a loop. (org-babel-execute:jupyter): kernel-lang -> lang
1 parent 62b3de4 commit a6c40a4

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

ob-jupyter.el

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,12 @@ kernel starts on the remote host /ssh:ec2: with a session name of
356356
jl. The remote host must have jupyter installed since the
357357
\"jupyter kernel\" command will be used to start the kernel on
358358
the host."
359-
(let* ((kernel (alist-get :kernel params))
360-
(key (org-babel-jupyter-session-key params))
359+
(let* ((key (org-babel-jupyter-session-key params))
361360
(client (gethash key org-babel-jupyter-session-clients)))
362361
(unless client
363362
(setq client (org-babel-jupyter-initiate-client
364363
(org-babel-jupyter-parse-session session)
365-
kernel))
364+
(alist-get :kernel params)))
366365
(puthash key client org-babel-jupyter-session-clients)
367366
(jupyter-with-repl-buffer client
368367
(let ((forget-client (lambda () (remhash key org-babel-jupyter-session-clients))))
@@ -393,25 +392,24 @@ the host."
393392
"Delete the files of image links for the current source block result.
394393
Do this only if the file exists in
395394
`org-babel-jupyter-resource-directory'."
396-
(when-let* ((result-pos (org-babel-where-is-src-block-result))
397-
(link-re (format "^[ \t]*%s[ \t]*$" org-bracket-link-regexp)))
395+
(when-let*
396+
((pos (org-babel-where-is-src-block-result))
397+
(link-re (format "^[ \t]*%s[ \t]*$" org-bracket-link-regexp))
398+
(resource-dir (expand-file-name org-babel-jupyter-resource-directory)))
398399
(save-excursion
399-
(goto-char result-pos)
400+
(goto-char pos)
400401
(forward-line)
401402
(let ((bound (org-babel-result-end)))
402403
;; This assumes that `jupyter-org-client' only emits bracketed links as
403404
;; images
404405
(while (re-search-forward link-re bound t)
405-
(when-let* ((link-path
406-
(org-element-property :path (org-element-context)))
407-
(link-dir
408-
(when (file-name-directory link-path)
409-
(expand-file-name (file-name-directory link-path))))
410-
(resource-dir
411-
(expand-file-name org-babel-jupyter-resource-directory)))
412-
(when (and (equal link-dir resource-dir)
413-
(file-exists-p link-path))
414-
(delete-file link-path))))))))
406+
(when-let*
407+
((path (org-element-property :path (org-element-context)))
408+
(dir (when (file-name-directory path)
409+
(expand-file-name (file-name-directory path)))))
410+
(when (and (equal dir resource-dir)
411+
(file-exists-p path))
412+
(delete-file path))))))))
415413

416414
;; TODO: What is a better way to handle discrepancies between how `org-mode'
417415
;; views header arguments and how `emacs-jupyter' views them? Should the
@@ -470,9 +468,9 @@ the PARAMS alist."
470468
(thread-first (alist-get :session params)
471469
(org-babel-jupyter-initiate-session params)
472470
(thread-last (buffer-local-value 'jupyter-current-client))))
473-
(kernel-lang (jupyter-kernel-language jupyter-current-client))
474-
(vars (org-babel-variable-assignments:jupyter params kernel-lang))
475-
(code (org-babel-expand-body:jupyter body params vars kernel-lang)))
471+
(lang (jupyter-kernel-language jupyter-current-client))
472+
(vars (org-babel-variable-assignments:jupyter params lang))
473+
(code (org-babel-expand-body:jupyter body params vars lang)))
476474
(pcase-let ((`(,req ,maybe-result)
477475
(org-babel-jupyter--execute code async-p)))
478476
;; KLUDGE: Remove the file result-parameter so that

0 commit comments

Comments
 (0)