如何限制flyspell给出的“建议”的数量?

时间:2013-10-04 16:29:36

标签: emacs menu flyspell

在emacs flyspell模式下,有时建议列表很长,因此弹出菜单比屏幕高,需要垂直滚动菜单,因为“保存字”选项位于菜单的底部

有没有办法执行以下操作之一:

  1. 将“保存字词”移至菜单顶部?
  2. 严格限制显示的建议数量?
  3. 修改匹配单词的阈值?

2 个答案:

答案 0 :(得分:1)

此代码会将所有ispell解决方案限制为最大limit-ispell-choices-to,这会在flyspell中获得所需的限制。

(defvar limit-ispell-choices-to 5
  "Number indicating the maximum number of choices to present")

(defadvice ispell-parse-output (after limit-ispell-choices activate)
  (when (and (listp ad-return-value)
             ad-return-value)
    (let* ((miss-list-end (nthcdr (- limit-ispell-choices-to 1) 
                                  (nth 2 ad-return-value)))
           (guess-list-end (nthcdr (- limit-ispell-choices-to 1) 
                                   (nth 3 ad-return-value))))
      (when miss-list-end (setcdr miss-list-end nil))
      (when guess-list-end (setcdr guess-list-end nil)))))

答案 1 :(得分:0)

这会将“保存字”放在顶部。我刚刚在源代码中交换了两个单词。 这有点像黑客,但我看不到更好的方法。

(defun flyspell-emacs-popup (event poss word)
  "The Emacs popup menu."
  (unless window-system
    (error "This command requires pop-up dialogs"))
  (if (not event)
      (let* ((mouse-pos  (mouse-position))
         (mouse-pos  (if (nth 1 mouse-pos)
                 mouse-pos
               (set-mouse-position (car mouse-pos)
                           (/ (frame-width) 2) 2)
               (mouse-position))))
    (setq event (list (list (car (cdr mouse-pos))
                (1+ (cdr (cdr mouse-pos))))
              (car mouse-pos)))))
  (let* ((corrects   (if flyspell-sort-corrections
             (sort (car (cdr (cdr poss))) 'string<)
               (car (cdr (cdr poss)))))
     (cor-menu   (if (consp corrects)
             (mapcar (lambda (correct)
                   (list correct correct))
                 corrects)
               '()))
     (affix      (car (cdr (cdr (cdr poss)))))
     show-affix-info
     (base-menu  (let ((save (if (and (consp affix) show-affix-info)
                     (list
                      (list (concat "Save affix: " (car affix))
                        'save)
                      '("Accept (session)" session)
                      '("Accept (buffer)" buffer))
                   '(("Save word" save)
                     ("Accept (session)" session)
                     ("Accept (buffer)" buffer)))))
               (if (consp cor-menu)
               (append save (cons "" cor-menu))
             save)))
     (menu       (cons "flyspell correction menu" base-menu)))
    (car (x-popup-menu event
               (list (format "%s [%s]" word (or ispell-local-dictionary
                            ispell-dictionary))
                 menu)))))