这似乎很简单,但我在任何地方都找不到说明,所以我想在这里问一下。是否有一种方法可以在组织文件中执行整个缓冲区的代码块,并从命令行将它们全部保存在该组织文件中?
到目前为止,我已经尝试过这样的方法,但它不起作用(只是挂起):
emacsclient -a --eval '(find-file "index.org")(org-babel-execute-buffer)(save-buffer)'发布于 2022-05-09 03:49:18
这可能会有帮助:
#!/usr/bin/env sh
":"; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
(pop argv)
(require 'org-element)
(defun require-lang (lang)
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)
(pcase (downcase lang)
((or "hy" "hylang") (use-package ob-hy :demand t :straight '(ob-hy :type git :host github :repo "allison-casey/ob-hy") :init (setq org-babel-hy-command "/usr/bin/env hy")))))
(defun message-advice (func &rest args) (interactive)
(let* ((*message (apply #'format args)))
(unless (or (string-prefix-p "executing" *message)
(string-prefix-p "Code block" *message))
(apply func args))))
(advice-add #'message :around #'message-advice)
(defun org-babel-eval-error-notify-advice (exit-code stderr)
"Open a buffer to display STDERR and a message with the value of EXIT-CODE."
(let ((buf (get-buffer-create org-babel-error-buffer-name)))
(with-current-buffer buf
(goto-char (point-max))
(save-excursion (insert stderr))
(message (buffer-string)))
(display-buffer buf))
(message "Babel evaluation exited with code %S" exit-code))
(advice-add #'org-babel-eval-error-notify :override #'org-babel-eval-error-notify-advice)
(let ((org-confirm-babel-evaluate)
(lang-list '()))
(with-temp-buffer
(while argv
(let ((arg (pop argv)))
(pcase arg
((or "-l" "--languages")
(while (and (> (length argv) 1) (not (string-prefix-p "-" (car argv))))
(add-to-list 'lang-list (pop argv) t)))
(_ (setq file arg)))))
(insert-file-contents file)
(mapc 'require-lang lang-list)
(org-babel-execute-buffer)))这里有更多信息:
https://github.com/sylvorg/settings/blob/main/README.org#org-interpreter
如果您专门搜索execute org files,也会有很多资源;我会发布链接,但我不知道这里是否欢迎这样做。
https://stackoverflow.com/questions/71388302
复制相似问题