在window10上运行emacs-27.1会因为路径问题而导致有些命令不能正常应用,比如find。
PS C:Usersgaowei> scoop which find
C:Windowssystem32find.exe
无论用find还是用find.exe全部调用的是windows的命令,如果直接在emacs中用grep-find命令会报错:
find . -type f -exec grep -nH -e diary "{}" ";"
Access denied - .
File not found - -TYPE
File not found - F
File not found - -EXEC
File not found - GREP
File not found - -NH
File not found - -E
File not found - DIARY
File not found - ;
迂回的解决方案是安装busybox,用grep-find的时候加前缀:
Grep started at Thu Aug 27 13:24:07
busybox find . -type f -exec grep -nH -e diary "{}" ";"
./01.Screen.org:113:On a display that supports a mouse, you can use the mouse to choose a command from the menu bar. An arrow on the right edge of a menu item means it leads to a subsidiary menu, or submenu. A '...' at the end of a menu item means that the command will prompt you for further input before it actually does anything.
然而反复输入busybox着实影响效率。
有没有更优的解决方案呢?
我们可以用getenv函数参与emas的路径:
ELISP> (getenv "PATH")
"C:ProgramDatascoopshims;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:ProgramDatachocolateybin;C:Usersgaoweiscoopshims;C:UsersgaoweiAppDataLocalMicrosoftWindowsApps"
注意其中的反斜杠,真让人头疼。
我们同时会注意到,emacs中有71中与path相关的变量。
我们调用函数setenv修改环境变量PATH。
(setenv VARIABLE &optional VALUE SUBSTITUTE-ENV-VARS)
我们在上文中苦恼于冗余的反斜杠,emacs提供了便捷的解决方案,直接用/替代。因此最总的路径,我们可以修改为:
"C:/ProgramData/scoop/shims;C:/Users/gaowei/scoop/shims;C:/Users/gaowei/.emacs.d/bin;C:/Users/gaowei/AlphaApps;C:/Windows/system32;C:/Windows;C:/Windows/System32/Wbem;C:/Windows/System32/WindowsPowerShell/v1.0;C:/Windows/System32/OpenSSH/;C:/Users/gaowei/AppData/Local/Microsoft/WindowsApps")
nil)
由于我们的配置要适配于多种系统,因此要加上选择语句:
(if (eq system-type 'windows-nt)
(setenv
"PATH"
"C:/ProgramData/scoop/shims;C:/Users/gaowei/scoop/shims;C:/Users/gaowei/.emacs.d/bin;C:/Users/gaowei/AlphaApps;C:/Windows/system32;C:/Windows;C:/Windows/System32/Wbem;C:/Windows/System32/WindowsPowerShell/v1.0;C:/Windows/System32/OpenSSH/;C:/Users/gaowei/AppData/Local/Microsoft/WindowsApps")
nil)
其中变量”system-type"记录了当前操作系统种类。
ELISP> (eval 'system-type)
windows-ntELISP> (eval 'system-type)
windows-nt
此时,grep-find就能无碍运行。
以上,变量修改完成,我的机器信息为:
gaowei@alpha
------------
OS: Windows 10 专业版 x86_64
Host: TIMI RedmiBook 16
Kernel: 10.0.19041
Uptime: 7 hours, 57 mins
Packages: 27 (scoop)
Shell: bash 4.4.23
Resolution: 1920x1080
DE: Aero
Terminal: Windows Terminal
CPU: AMD Ryzen 5 4500U with Radeon Graphics (6) @ 2.370GHz
GPU: Caption
GPU: AMD Radeon(TM) Graphics
GPU
Memory: 8640MiB / 15741MiB
Emacs相关问题,期待留言交流。
页面更新:2024-05-23
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号