总算是用WSL的spacemacs给折腾好了,给大家总结一下

emacs原来还有内置的输入法。

哈哈,几个借助PowerShell实现的高仿程序

1.在windows下截图(当然是Snipaste)简单编辑后复制到剪贴板,往emacs里粘贴图片文件到当前文件目录下的images里(暂时不会自动插入链接,需要时再动手加),写笔记时截图感觉好用啊,哈哈哈

(defun my-yank-image-from-win-clipboard-through-powershell()
  "to simplify the logic, use c:/Users/Public as temporary directoy, and move it into current directoy"
  (interactive)
  (let* ((powershell "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
         (file-name (format-time-string "screenshot_%Y%m%d_%H%M%S.png"))
         ;; (file-path-powershell (concat "c:/Users/\$env:USERNAME/" file-name))
         (file-path-wsl (concat "./images/" file-name))
         )
    ;; (shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/\\$env:USERNAME/" file-name "\\\")\""))
    (shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/Public/" file-name "\\\")\""))
    (rename-file (concat "/mnt/c/Users/Public/" file-name) file-path-wsl)
    ))
  1. 接下来,在wsl的emacs中打开win10的文件管理器,看名字就知道,仿的谁… …
(defun xah-open-in-desktop-from-wsl()
  "open desktop by send command from wsl into powershell"
  (interactive)
  (let* ((powershell "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
         (directory (replace-regexp-in-string "/mnt/\\([a-zA-Z]\\)" "\\1:" default-directory))
         )
    (shell-command (concat powershell " -command \"start " directory "\""))
    )
  )
  1. 再次高仿,使用win10下的默认程序打开文件
(defun xah-open-in-xternal-app-from-wsl()
  "open desktop by send command from wsl into powershell"
  (interactive)
  (let* ((powershell "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
         (directory (replace-regexp-in-string "/mnt/\\([a-zA-Z]\\)" "\\1:" default-directory))
         (-file-list
          (if (string-equal major-mode "dired-mode")
              (dired-get-marked-files)
            (list (buffer-file-name))))
         )
    (shell-command (concat powershell " -command \"start " (replace-regexp-in-string "/mnt/\\([a-zA-Z]\\)" "\\1:" (nth 0 -file-list)) "\""))
    )
  )
6 个赞

看到了国外网友的博客上的一个设置: Launching WSL Programs from a Right Click Windows Menu — Nick Janetakis 。跟上面的知乎专栏的内容功能差不多。

您好,请问一下不直接用Emacs for windows,在msys2里单独安装使用Emacs有什么额外的好处吗?我自己感觉好像在msys里加载慢一些,dotfile加载也有点bug,但是还是看到有人在用,所以请教一下。

听说官方版emacs windows就是msys编译的,那这样两个应该就是一样的,我使用过msys2版,除了home,path路径不一样,也没发现什么区别

用msys2的话,安装其他依赖软件更方便

楼主请问一下,为什么不在shell command里使用shell脚本呢?我看到另一个类似MacOS脚本也是在call-shell-command以后调用了Applescript脚本,不用shell是有什么特殊的考量吗

我也不知道啊,仅是有这个想法后,又刚好知道可以这么实现,就这么干了