如何在org-mode中用windows默认程序打开链接的文件
Table of Contents
缘起
有一个需要,要给电脑的中文件做一个目录。如果用思维导出软件是肯定没有问题的,但是由于觉得org大纲组织形式其实与思维导图是一个性质,所以还是想用org文件做目录。 然后问题就出现了,如果不进行任何设置的话,点击链接的话,emacs会默认使用emacs来打开,而不是使用操作系统的默认程序打开。
初始的方法:使用file链接
如果要使用window程序打开的话,还需要做一些配置,否则emacs会直接打开这个文件。
搜索了一下,配置还是挺简单的。以ppt文件为例。
(add-to-list
'org-file-apps
'("\\.docx\\'" . default))
上面如果不用default,用system也可以。
改进的方法:使用file+sys链接
在视频发布后,长问长青在评论中说,使用file+sys链接,可以直接使用系统的文件打开,而不需要任何配置,我试了下,的确如此,再次感谢,又学到了。
解决file+sys无法补全的问题
但是同时也有了新的问题,因为file+sys的链接,在插入时提示:“(no completion support)”,也就是意味着没有补全的提示。
以下内容20221215更新
枫泪绝 在评论中告诉我了,corfu 是可以在mini-buffer中被全的,并告诉了我配置的方法,就是加入以下配置
;;You can also enable Corfu more generally for every minibuffer, as long as no other completion UI is active. If you use Mct or Vertico as your main minibuffer completion UI, the following snippet should yield the desired result. (defun corfu-enable-always-in-minibuffer () "Enable Corfu in the minibuffer if Vertico/Mct are not active." (unless (or (bound-and-true-p mct--active) (bound-and-true-p vertico--input)) ;; (setq-local corfu-auto nil) Enable/disable auto completion (corfu-mode 1))) (add-hook 'minibuffer-setup-hook #'corfu-enable-always-in-minibuffer 1)
但这个方法并不完美,不知道什么原因,需要在 file+sys: 后加一个空格,输入盘符后才能启动补全,这样就不如 file: 的链接是从当前org文件所在的目录启动。另外这个空格是需要删除的。
需要解决空格的问题
每次手动定位到那个空格再去删自然是很麻烦的事情,最近正好 elisp 开窍了,就想着写一段 elisp 搞定,很粗浅,见笑。
(defun remove-whitespace() "Delete the unwanted whitespace" (interactive) (save-excursion (search-backward "+sys:") (forward-word) (forward-char) (delete-char 1)))
方法三:使用file链接,改成file+sys链接
忽然发现可以直接使用file链接修改 D:\02 Programs\08 Tools\doublecmd\009.txt
(defun file2FileSys() "Convert the file link to file+sys link" (interactive) (save-excursion (search-backward "file:") (forward-word) (insert "+sys")))