Emacs Slime mode : slime-tramp 對應遠端檔案路徑

遠端使用 swank 伺服器

在 Emacs slime-connect 連接遠端 SBCL (common lisp) 。

M-x slime-connect 
Host: localhost 
Port: 4005
Close old connections first? (y or n) y
Versions differ: nil (slime) vs. 2.31 (swank). Continue? (y or n) y

slime-tramp 的用途

  • SLIME 在遠端 Lisp 回報檔案路徑時,可以自動轉換成 TRAMP 格式路徑(像 /ssh:remote-host:/path/to/file.lisp),
    這樣 Emacs 不需要額外的 sshfs 掛載就能直接打開遠端檔案。

  • 不需要手動維護 slime-filename-translations 的 alist,適合「只用 ssh 連線,不掛載遠端檔案」的情境。

 自動路徑轉換

當 Lisp 回傳例如:

#P"/home/user/project/foo.lisp"

Emacs 會自動轉成:

/ssh:remote-host:/home/user/project/foo.lisp

相關參數

  • slime-translate-from-lisp-filename-function
    從 Lisp 傳回路徑 → 轉換為 Emacs 可以理解的檔案路徑。
  • slime-translate-to-lisp-filename-function
    從 Emacs 的檔案路徑 → 轉換成 Lisp 端可以理解的路徑。
 
這兩個通常由 slime-filename-translations 自動設定,不需要手動修改

在 Emacs init.lisp 設定遠端檔案修改儲存

(require 'slime)
(slime-setup '( slime-cl-indent
                               slime-asdf slime-fancy
                               slime-fancy-inspector
                               slime-fuzzy slime-autodoc
                               slime-sprof
                               slime-tramp))

(push (slime-create-filename-translator
       :machine-instance "service-1"
       :remote-host "service-1"
       :username "user1")
      slime-filename-translations)

可以配合遠端 repl 開發源碼。

移除舊的緩存和臨時檔

出現類似

tramp-sh-handle-file-newer-than-file-p: Files /tmp/#!ssh:user1@service-1:!home!user1!src!main.lisp# and /ssh:user1@service-1:/home/user1/src/main.lisp must have same method, user,  host...

有時 TRAMP 會因為緩存或舊的臨時檔而產生不一致的行為。你可以試著關閉 Emacs,然後手動刪除 TRAMP 的暫存目錄。

在你的 Linux 或 macOS 系統上,TRAMP 的暫存檔通常位於 /tmp/ 目錄下。你可以找找看是否有類似 /tmp/tramp.23423 的目錄,或是檔名中有 #! 的檔案。找到並刪除它們。


留言

這個網誌中的熱門文章

計算碟形端板的內容積/calculate internal volume of spherically dished

壓力容器設計:最低設計金屬溫度 (MDMT)

壓寶計劃:如何設計桶槽的容積刻度尺/ How to design the volume scale of the barrel tank