【问题标题】:orgmode - disable elisp code execute confirmation dialogorgmode - 禁用 elisp 代码执行确认对话框
【发布时间】:2017-07-28 17:40:15
【问题描述】:

当用户点击链接时,我有以下代码调用 elisp 函数“myfun”:

#+BEGIN_SRC elisp :results output raw
  (defun myfun(filepath lineno)
    (if (not (get-buffer bufname))
        (get-buffer-create bufname)
      )
    (switch-to-buffer-other-window bufname)
    (global-linum-mode)
    (erase-buffer)
    (insert-file-contents (format "%s" filepath))
    (goto-char (point-min))
    (forward-line lineno)
    (setq start (point))
    (forward-line -1)
    (setq end (point))
    (let ((x (make-overlay start end)))
      (overlay-put x 'face '(:background "#fef0f1")))
    )

  (defun createSampleFile(file-name count)
    (let ((c 0))
      (with-temp-buffer
        (while (< c (* 2 count))
          (setq c (1+ c))
          (insert (format "line %d\n" c))
          (write-file filename)
          ))))

  (let ((c 0)(filename nil))
    (while (< c 4)
      (setq c (1+ c))
      (setq filename (format "./test%d.txt" c))
      (createSampleFile filename c)
      (princ (format "[[elisp:(myfun '%s' %d)][%s]]\n" filename c filename))
      ))
#+END_SRC

#+RESULTS:
[[elisp:(myfun './test1.txt' 1)][./test1.txt]]
[[elisp:(myfun './test2.txt' 2)][./test2.txt]]
[[elisp:(myfun './test3.txt' 3)][./test3.txt]]
[[elisp:(myfun './test4.txt' 4)][./test4.txt]]

但是当点击链接时,我总是得到下面的提示警告对话框:

我们可以禁用该对话框吗?

【问题讨论】:

    标签: elisp org-mode


    【解决方案1】:

    将下面的行添加到 init.el:

    (setq org-confirm-elisp-link-function nil)
    

    【讨论】:

    • ... 但请注意变量文档中的警告。执行任意代码(以 elisp 或任何语言)是有风险的。
    • 也许最好只将其添加到 org 文件中,但不要将其添加到 init.el 中。
    • 是的 - 至少,您可以查看代码并确保它不包含隐藏的炸弹,然后再将其标记为上述。这可以通过file variable 完成。而且您不会授予任何文件执行任何代码的全面权限。
    • @Nick 你认为 org-confirm-babel-evaluate 和这个案例一样吗。我通常在 init.el 中将其设置为 nill。 babel 代码需要用户运行我想,打开文件时会自动执行吗?
    • 正如 NickD 提到的,更安全的选择是将其添加为文件的第一行:# -*- mode: Org; org-confirm-elisp-link-function: nil; -*-
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多