org-模式 - 禁用elisp的代码执行确认对话框
问题描述:
我有下面的代码来调用elisp的功能“myfun”,当用户点击链接:org-模式 - 禁用elisp的代码执行确认对话框
#+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]]
我们可以禁用该对话框吗?
答
添加下面一行的init.el:
(setq org-confirm-elisp-link-function nil)
...但注意在变量的文档警告。执行任意代码(以elisp或任何语言)是有风险的。 – Nick
也许将它仅添加到组织文件会更好,但不要将其添加到init.el中。 – lucky1928
是的 - 至少,你可以看看代码,并确保它不包含隐藏的炸弹,在标记如上。这可以通过[文件变量]来完成(https://www.gnu.org/software/emacs/manual/html_node/emacs/File-Variables.html#File-Variables)。而且你不会给任何文件一揽子权限来执行任何代码。 – Nick