在Emacs里如何指定「可执行脚本」的路径?

大家好,最近在Mac上折腾Emacs时,使用的是emacs-sis这个插件;切换插件是im-select,遇到的问题是:

我的im-select是手动下载的可执行文件,放在「~/bin/im-select」路径下,我在Emacs里怎么指定读取这个im-select?

在Win下这样配置

(sis-ism-lazyman-config “1033” “2052” 'im-select)

在Mac下,肯定不能这样写吧?

(sis-ism-lazyman-config “com.apple.keylayout.US” “com.sogou.inputmethod.sogou.pinyin”
'~/bin/im-select)

根据sis的手册,Mac上并不需要im-select

我没有安装sis推荐的macism,感觉会有点卡,我直接扒得GitHub - ybian/smartim: A Vim plugin to make it stand well with input methods (Mac only) 里面的执行脚本,在obsidian上配合vim插件使用良好,但还是想用在emacs上,不知道怎么指定路径。

你可能需要的是exec-path这个变量

用绝对路径或者

(setenv "PATH" (concat (getenv "PATH") ":/path"))
(use-package sis
  :config
  (setq sis-other-cursor-color "red")
  (setq sis-external-ism "im-select")
  (sis-ism-lazyman-config "com.apple.keylayout.ABC" "im.rime.inputmethod.Squirrel.Hans")
  (sis-global-cursor-color-mode t)
  (sis-global-context-mode t)
  (sis-global-respect-mode t)
  (sis-global-inline-mode t)
  (add-to-list 'sis-context-detectors
               (lambda (&rest _)
                 ;; (when (or (and (eq major-mode 'org-mode) (org-at-heading-p))
                 (when (or (eq major-mode 'org-mode)
                           (eq major-mode 'telega-chat-mode))
                   'other))))

我用 brew 装的 im-select。

感谢前面兄弟的回答,经过刚才多次尝试,现在已经初步调整好了,这里贴上我的解决方案。(请结合图片一起看,全部配置贴上会格式错乱,请谅解)

「可执行im-select文件扔在/Users/jeffery/bin目录下」

全局定义PATH:

(setq exec-path (append exec-path '("/Users/jeffery/bin"))))

插件配置:

;; For Linux
(when (eq system-type 'gnu/linux)
  (sis-ism-lazyman-config
   "1"
   "2"
   'fcitx5))
;; For MacOS
(when (eq system-type 'darwin)
  (setq sis-external-ism "im-select")
  (sis-ism-lazyman-config
   "com.apple.keylayout.US"
   "com.apple.inputmethod.SCIM.Shuangpin"))

;; enable the /cursor color/ mode
(sis-global-cursor-color-mode t)
;; enable the /respect/ mode
(sis-global-respect-mode t)
;; enable the /context/ mode for all buffers
(sis-global-context-mode t)
;; enable the /inline english/ mode for all buffers
(sis-global-inline-mode t)
)

终于搞定Mac下Emacs的输入法切换了,有相同困扰的朋友可以参考。

其余细节可以参考我的配置: 2023-03-22_16-55

2023-03-22_16-57

建议用 markdown 回复,用图片的话别人没办法复制你的代码 :smiling_face_with_tear: