逛 Reddit 时遇到了这个函数
;; https://github.com/pietroiusti/.emacs.d/blob/master/custom-functions.el
(defun gp/vscode-current-buffer-file-at-point ()
(interactive)
(start-process-shell-command "code"
nil
(concat "code --goto "
(buffer-file-name)
":"
(number-to-string (1+ (current-line))) ;; +1 who knows why
":"
(number-to-string (current-column)))))
(define-key global-map (kbd "C-<escape>") 'gp/vscode-current-buffer-file-at-point)
只是改了下函数名字和绑定的快捷键
;; {{{ vscode: Visual Studio Code
(defun my/open-in-vscode ()
(interactive)
(start-process-shell-command "code"
nil
(concat "code --goto "
(buffer-file-name)
":"
(number-to-string (1+ (current-line))) ;; +1 who knows why
":"
(number-to-string (current-column)))))
(define-key global-map (kbd "C-c c") 'my/open-in-vscode)
;; }}}
但是在我的 Emacs 上运行不起来,emacs -Q
M-x eval-buffer
后提示:
Symbol's function definition is void: current-line
Emacs 版本:
GNU Emacs 29.0.50 (build 1, aarch64-apple-darwin22.1.0, NS
appkit-2299.00 Version 13.0.1 (Build 22A400)) of 2022-11-23
Emacs 文档里没有对 current-line 的描述,EmacsWiki 也没搜到有用的信息。
另外补上在 Obsidian 中打开 Emacs 的做法: