pyim 添加了新的 page tooltip, 欢迎大家测试

这个新的 tooltip 使用 emacs 26 的 child-frame, 速度和对中文的支持比 popup 都好,欢迎大家测试。

  1. emacs26
  2. pyim master
  3. (setq pyim-page-tooltip 'child-frame)
2 个赞

1

linux可用吗

应该可以。不过我还没来得及测试,没升级呢

我来报个 bug

环境

  • macOS 10.11.6
  • Emacs 26.0.90 ~ 27.0.50
  • pyim master

步骤

⋊> /path/to/emacs -nw -Q -l /path/to/test-pyim.el

配置 (test-pyim.el)

;;; Usage: /path/to/emacs -nw -Q -l /path/to/test-pyim.el
;;; Date: 2017-12-05_13.29.00
(toggle-debug-on-error)
(global-set-key (kbd "C-h") 'delete-backward-char)
(global-set-key (kbd "M-h") 'backward-kill-word)
(global-set-key (kbd "<f1>") 'help-command)
(define-key isearch-mode-map "\C-h" 'isearch-delete-char)

;; ------------------------------------------------------------------

(setq package-user-dir (concat user-emacs-directory (format "elpa--%s/%s" (file-name-base load-file-name) emacs-version)))
(setq package-archives
      (cond
       ((string-equal (getenv "LANG") "zh_CN.UTF-8")
        '(("gnu"   . "http://elpa.emacs-china.org/gnu/")
          ("melpa" . "http://elpa.emacs-china.org/melpa/")))
       (t
        '(("gnu"   . "https://elpa.gnu.org/packages/")
          ("melpa" . "https://melpa.org/packages/")))))

(package-initialize)

(defun require-packages (&rest packages)
  (dolist (pkg packages)
    (unless (package-installed-p pkg)
      (package-refresh-contents)
      (package-install pkg))
    (require pkg)))

;; ------------------------------------------------------------------

(setq el-get-dir (concat user-emacs-directory (format "el-get--%s/%s" (file-name-base load-file-name) emacs-version)))
(add-to-list 'load-path (concat el-get-dir "/el-get"))

(setq el-get-git-shallow-clone t)
(setq el-get-byte-compile nil)
(setq el-get-bundle-byte-compile nil)
(setq el-get-install-skip-emacswiki-recipes t)

(unless (require 'el-get nil 'noerror)
  (with-current-buffer
      (url-retrieve-synchronously
       "https://raw.githubusercontent.com/dimitri/el-get/master/el-get-install.el")
    (goto-char (point-max))
    (eval-print-last-sexp)))

(remove-hook 'el-get-post-install-hooks 'el-get-post-install-notification)

;; ------------------------------------------------------------------

(require-packages
 'pos-tip
 'popup
 'async)

(el-get-bundle pyim
  :type git
  :url "https://github.com/tumashu/pyim"
  (require 'pyim)
  (global-set-key (kbd "C-\\") 'toggle-input-method)
  (setq default-input-method "pyim"
        pyim-default-scheme 'quanpin
        pyim-page-tooltip 'child-frame))

(add-hook 'after-init-hook
          (lambda ()
            (switch-to-buffer "*scratch*")
            (insert "w")
            (pyim-convert-code-at-point)
            ))

(run-hooks 'after-init-hook)
;;; test-pyim.el ends here

emacs 26 在 macos 上面不支持 child frame ?

测试下面这段代码, 如果运行有问题,那就是 emacs 的bug了。

(make-frame
   `((parent-frame . ,(window-frame))
     (width . 50)
     (height . 10)))

测试一下下面这段代码

 (setq my-frame
      (make-frame
       `((parent-frame . ,(window-frame))
         (width . 50)
         (height . 10))))

(set-frame-parameter my-frame 'parent-frame (window-frame))
Debugger entered--Lisp error: (void-variable my-frame)
  (set-frame-parameter my-frame 'parent-frame (window-frame))
  eval((set-frame-parameter my-frame 'parent-frame (window-frame)) nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

。。。 第一个 setq 要运行一下才能运行第二个。。。。

这个就没法了。。。。。。 可能是 emacs 的bug

EVAL下面这个函数,然后 再测试一下 pyim, 看看效果

(defun pyim-tooltip-show-with-child-frame (string position)
  "在 POSITION 处使用 child-frame 显示 STRING."
  (let* ((buffer (get-buffer-create " *pyim-child-frame-buffer*"))
         (string-width-height (pos-tip-string-width-height string))
         (string-width (car string-width-height))
         (string-height (cdr string-width-height))
         (x-and-y (pos-tip-compute-pixel-position position)))

    (unless (frame-live-p pyim-tooltip-child-frame)
      (setq pyim-tooltip-child-frame
            (let ((after-make-frame-functions nil))
              (make-frame
               `(,@pyim-tooltip-child-frame-parameters
                 (parent-frame . ,(window-frame))
                 (no-accept-focus . t)
                 (min-width  . t)
                 (min-height . t)
                 (border-width . 0)
                 (internal-border-width . 0)
                 (vertical-scroll-bars . nil)
                 (horizontal-scroll-bars . nil)
                 (left-fringe . 10)
                 (right-fringe . 0)
                 (menu-bar-lines . 0)
                 (tool-bar-lines . 0)
                 (line-spacing . 0)
                 (unsplittable . t)
                 (no-other-frame . t)
                 (undecorated . t)
                 (visibility . nil)
                 (cursor-type . nil)
                 (minibuffer . nil)
                 (width . 50)
                 (height . 2)
                 (no-special-glyphs . t)))))
      (let ((window (frame-root-window pyim-tooltip-child-frame)))
        (set-window-parameter window 'mode-line-format 'none)
        (set-window-parameter window 'header-line-format 'none)
        (set-window-buffer window buffer)))

    (dolist (alist `( ;;(parent-frame . ,(window-frame))
                     (visibility   . t)
                     (top    .  ,(+ (cdr x-and-y) 10))
                     (left   .  ,(+ (car x-and-y) 10))
                     (width  .  ,(+ string-width 1))
                     (height .  ,(+ string-height 1))))
      (let ((parameter (car alist))
            (value (cdr alist)))
        (set-frame-parameter
         pyim-tooltip-child-frame parameter value)))

    (with-current-buffer buffer
      (erase-buffer)
      (insert string)
      (redisplay))))

速度怎么样?

怎用使用或者说调出emacs的pyim输入法?

去看pyim的README吧,写的很详细

那个网址在哪呢?

百度也行。