Skip to content

Releases: jixiuf/squirrel

0.9.26.3

30 Jun 12:54
Compare
Choose a tag to compare
0.9.26.3 Pre-release
Pre-release

rebase 08283b8
主要想实现两个功能:

  1. 当squirrel 切换中英文状态 、简繁体等时 能够执行指定的系统脚本
  2. 提供命令行工具 控制中英文状态 /Library/Input\ Methods/Squirrel.app/Contents/MacOS/squirrel_client

因而可以实现

  1. 在emacs中 当shift键切换成中文输入状态时,自动进入evil-mode 的insert state (跟vim的输入模式类似)
  2. 在emacs中进入evil-normal-state时自动将输入法切换到英文输入状态

当 ~/bin/squirrel_toggle_option文件存在时 toggle option 操作会执行此脚本(切换中英文,切换简繁等)
比如当切换中英文状态时
如果~/bin/squirrel_toggle_option 存在并有可执行权限 则会调用此脚本 并且传递一个参数
"ascii_mode" 或者”!ascii_mode" 用来表明当前中英文状态

这个机制可以给用户一个机会,当切换中英文状态时执行一定的操作(如vim 进入insert模式,或emacs 的evil-mode 进入insert state)
也可以在这个脚本中记录输入法的中英文状态,以便外部程序查看

比如结合[Hammerspoon http://www.hammerspoon.org] 可以实现在emacs中当输入法切换成中文时自动进入evil-mode的insert 模式

~/bin/squirrel_toggle_option

#!/bin/sh
# accept one param
# it may be [ascii_mode !ascii_mode,
# full_shape, !full_shape ,
# ascii_punct,!ascii_punct,
# simplification !simplification,
# extended_charset !extended_charset]
# 
# http://www.hammerspoon.org
if [ $1 = "!ascii_mode" ]; then
    # 切换到中文的时候调用hammerspoon中绑定的一个函数,
    # 在那里做处理
    # 主要判断 当前激活的窗口是不是emacs,如果是emacs ,
   # 模拟按键 使emacs 进入evil-insert-state态
    open -g "hammerspoon://emacs_evil_insert_state"
fi

在~/.hammerspoon/init.lua文件中加入以下代码 (前提是装了https://github.com/Hammerspoon/hammerspoon/releases


-- 主要用来实现 当输入法开始进入中文模式时,使用emacs 自动进入evil-insert-state(相当于vim中进入insert mode)
-- 在当在emacs中编辑文件时,模拟按下f18键,以使emacs 进入evil-insert-state状态
function emacs_evil_insert_state()
   local win = hs.window.frontmostWindow()
   if win ==nil then
      return
   end
   local app = win:application()
   if app:bundleID()=="org.gnu.Emacs" then
      -- emacs 中f18 绑定为进入evil-insert-state
      -- 此处模拟在emacs 中按f18键

      -- (global-set-key (kbd "<f18>") 'evil-insert-state) 
      -- (define-key isearch-mode-map (kbd "<f18>") 'evil-insert-state)

      hs.eventtap.keyStroke({}, "f18")
   elseif app:bundleID()=="com.googlecode.iterm2" then -- 如果是在终端下,通过终端的窗口标题来区分当前是否在用emacs编辑文件
      -- 如果是在iterm2终端中,也模拟按下f18键,
      -- hs.alert.show(win:title())
      if string.match(win:title(), " em ") then -- em is an emacsclient wrapper
         hs.eventtap.keyStroke({}, "f18")
      elseif string.match(win:title(), " emacs ") then
         hs.eventtap.keyStroke({}, "f18")
      elseif string.match(win:title(), " emacsclient ") then
         hs.eventtap.keyStroke({}, "f18")
      elseif string.match(win:title(), " vim ") then
         -- do something when you edit file using vim in iterm
      end
   end
end
 --可以在外部通过 open -g "hammerspoon://emacs_evil_insert_state" 执行这个函数
hs.urlevent.bind("emacs_evil_insert_state", function() emacs_evil_insert_state() end)

emacs 中加入f18的按键绑定

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 这段代码实现 squirrel中文输入法的切换与evil-mode 的协调
;; 主要实现两个功能
;; 1 shift切换到中文输入法时,自动进入evil-insert-state
;; 2当emacs进入evil-normal-state ,使squirrel输入法进入输入英文状态
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun my-evil-normal()
  (interactive)
  (evil-normal-state)
;; do something else if you want
  (setq this-command 'evil-normal-state))

(define-key evil-insert-state-map [escape] 'my-evil-normal)

(defun disable-input-method-hook()
  (start-process "squirrel-input-method-disable-chinese" nil "/Library/Input Methods/Squirrel.app/Contents/MacOS/squirrel_client" "-s" "ascii_mode" "--clear"))
;; 输入法进入normal state时,关闭输入法的中文模式
(add-hook 'evil-normal-state-entry-hook 'disable-input-method-hook)
(global-set-key (kbd "<f17>") 'my-evil-normal) 
(define-key isearch-mode-map (kbd "<f17>") 'my-evil-normal) 

;; 当切换输入法到中文状态时的时候会回调到这里
;;回调的时候有可能是上面disable-input-method-hook 里调,此时不应该切到insert模式
(defun my-evil-insert()
  (interactive)
  (unless (equal 'evil-normal-state last-command)
    (evil-insert-state)))
(global-set-key (kbd "<f18>") 'my-evil-insert) 
(define-key isearch-mode-map (kbd "<f18>") 'my-evil-insert)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

另外https://github.com/rime/squirrel/wiki 中有介绍如何只保留一个Squirrel输入法

官方的版本打包成了pkg安装包, 我不知道怎么打包pkg ,只压缩成zip 包就上传了。
解压开后 把它移到 /Libary/Input Methods/目录下,应该就可以了。 如果不行 ,则建议安装官方版本后,再将它移到 /Libary/Input Methods/ 后重启就可以了。

主要为vim 或emacs-evil-mode整合提供便利

04 Oct 16:03
Compare
Choose a tag to compare

主要想实现两个功能:
提供两个功能

  1. 当squirrel 切换中英文状态 、简繁体等时 能够执行指定的系统脚本
  2. 提供命令行工具 控制中英文状态 /Library/Input\ Methods/Squirrel.app/Contents/MacOS/squirrel_client

因而可以实现

  1. 在emacs中 当shift键切换成中文输入状态时,自动进入evil-mode 的insert state (跟vim的输入模式类似)
  2. 在emacs中进入evil-normal-state时自动将输入法切换到英文输入状态

/bin/squirrel_toggle_option文件存在时 toggle option 操作会执行此脚本(切换中英文,切换简繁等)
比如当切换中英文状态时
如果
/bin/squirrel_toggle_option 存在并有可执行权限 则会调用此脚本 并且传递一个参数
"ascii_mode" 或者”!ascii_mode" 用来表明当前中英文状态

这个机制可以给用户一个机会,当切换中英文状态时执行一定的操作(如vim 进入insert模式,或emacs 的evil-mode 进入insert state)
也可以在这个脚本中记录输入法的中英文状态,以便外部程序查看

比如结合[Hammerspoon http://www.hammerspoon.org] 可以实现在emacs中当输入法切换成中文时自动进入evil-mode的insert 模式

~/bin/squirrel_toggle_option

#!/bin/sh
# accept one param
# it may be [ascii_mode !ascii_mode,
# full_shape, !full_shape ,
# ascii_punct,!ascii_punct,
# simplification !simplification,
# extended_charset !extended_charset]
# 
# http://www.hammerspoon.org
if [ $1 = "!ascii_mode" ]; then
    # 切换到中文的时候调用hammerspoon中绑定的一个函数,
    # 在那里做处理
    # 主要判断 当前激活的窗口是不是emacs,如果是emacs ,
   # 模拟按键 使emacs 进入evil-insert-state态
    open -g "hammerspoon://emacs_evil_insert_state"
fi

在~/.hammerspoon/init.lua文件中加入以下代码 (前提是装了https://github.com/Hammerspoon/hammerspoon/releases


-- 主要用来实现 当输入法开始进入中文模式时,使用emacs 自动进入evil-insert-state(相当于vim中进入insert mode)
-- 在当在emacs中编辑文件时,模拟按下f18键,以使emacs 进入evil-insert-state状态
function emacs_evil_insert_state()
   local win = hs.window.frontmostWindow()
   if win ==nil then
      return
   end
   local app = win:application()
   if app:bundleID()=="org.gnu.Emacs" then
      -- emacs 中f18 绑定为进入evil-insert-state
      -- 此处模拟在emacs 中按f18键

      -- (global-set-key (kbd "<f18>") 'evil-insert-state) 
      -- (define-key isearch-mode-map (kbd "<f18>") 'evil-insert-state)

      hs.eventtap.keyStroke({}, "f18")
   elseif app:bundleID()=="com.googlecode.iterm2" then -- 如果是在终端下,通过终端的窗口标题来区分当前是否在用emacs编辑文件
      -- 如果是在iterm2终端中,也模拟按下f18键,
      -- hs.alert.show(win:title())
      if string.match(win:title(), " em ") then -- em is an emacsclient wrapper
         hs.eventtap.keyStroke({}, "f18")
      elseif string.match(win:title(), " emacs ") then
         hs.eventtap.keyStroke({}, "f18")
      elseif string.match(win:title(), " emacsclient ") then
         hs.eventtap.keyStroke({}, "f18")
      elseif string.match(win:title(), " vim ") then
         -- do something when you edit file using vim in iterm
      end
   end
end
 --可以在外部通过 open -g "hammerspoon://emacs_evil_insert_state" 执行这个函数
hs.urlevent.bind("emacs_evil_insert_state", function() emacs_evil_insert_state() end)

emacs 中加入f18的按键绑定

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 这段代码实现 squirrel中文输入法的切换与evil-mode 的协调
;; 主要实现两个功能
;; 1 shift切换到中文输入法时,自动进入evil-insert-state
;; 2当emacs进入evil-normal-state ,使squirrel输入法进入输入英文状态
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun my-evil-normal()
  (interactive)
  (evil-normal-state)
;; do something else if you want
  (setq this-command 'evil-normal-state))

(define-key evil-insert-state-map [escape] 'my-evil-normal)

(defun disable-input-method-hook()
  (start-process "squirrel-input-method-disable-chinese" nil "/Library/Input Methods/Squirrel.app/Contents/MacOS/squirrel_client" "-s" "ascii_mode" "--clear"))
;; 输入法进入normal state时,关闭输入法的中文模式
(add-hook 'evil-normal-state-entry-hook 'disable-input-method-hook)
(global-set-key (kbd "<f17>") 'my-evil-normal) 
(define-key isearch-mode-map (kbd "<f17>") 'my-evil-normal) 

;; 当切换输入法到中文状态时的时候会回调到这里
;;回调的时候有可能是上面disable-input-method-hook 里调,此时不应该切到insert模式
(defun my-evil-insert()
  (interactive)
  (unless (equal 'evil-normal-state last-command)
    (evil-insert-state)))
(global-set-key (kbd "<f18>") 'my-evil-insert) 
(define-key isearch-mode-map (kbd "<f18>") 'my-evil-insert)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

另外https://github.com/rime/squirrel/wiki 中有介绍如何只保留一个Squirrel输入法

官方的版本打包成了pkg安装包, 我不知道怎么打包pkg ,只压缩成zip 包就上传了。
解压开后 把它移到 /Libary/Input Methods/目录下,应该就可以了。 如果不行 ,则建议安装官方版本后,再将它移到 /Libary/Input Methods/ 后重启就可以了。