如何禁用重复isearch前进/后退的粘滞高亮

时间:2013-06-20 01:56:15

标签: emacs

如果没有黑客攻击源或创建我自己的isearch-repeat ...功能,是否可以禁用isearch-repeat-forwardisearch-repeat-backward的默认粘滞突出显示?

我正在使用Emacs Trunk的最新开发者版本--with-ns。


以下是一些想法(正在进行的工作),但它们无法解决问题 - isearch-mode-end-hook似乎与isearch-repeat-forwardisearch-repeat-backward无关。如果在退出lawlist-lazy-highlight-cleanup时任何键盘输入(转义和/或箭头键)可以暂时链接到isearch-repeat,那就太好了。

(add-hook 'isearch-mode-end-hook 'my-isearch-end)
(defun my-isearch-end ()
  "Custom behaviors for `isearch-mode-end-hook'."
  (when isearch-mode-end-hook-quit
    (lawlist-lazy-highlight-cleanup t)))

(defun lawlist-lazy-highlight-cleanup (&optional force)
  "Stop lazy highlighting and remove extra highlighting from current buffer.
FORCE non-nil means do it whether or not `lazy-highlight-cleanup'
is nil.  This function is called when exiting an incremental search if
`lazy-highlight-cleanup' is non-nil."
  (interactive '(t))
  (if (or force lazy-highlight-cleanup)
      (while isearch-lazy-highlight-overlays
        (delete-overlay (car isearch-lazy-highlight-overlays))
        (setq isearch-lazy-highlight-overlays
              (cdr isearch-lazy-highlight-overlays))))
  (when isearch-lazy-highlight-timer
    (cancel-timer isearch-lazy-highlight-timer)
    (setq isearch-lazy-highlight-timer nil))
(lawlist-isearch-dehighlight))

(defun lawlist-isearch-dehighlight ()
(interactive)
  (when isearch-overlay
    (delete-overlay isearch-overlay)))

(defun lawlist-isearch-repeat-forward ()
  "Repeat incremental search forwards."
  (interactive)
  (isearch-repeat 'forward)
;; need to add something that says sit-for any keyboard input before cleanup occurs.
;; (read-event) ;; read-char-exclusive | read-char | read-event
(sit-for 60)
(lawlist-lazy-highlight-cleanup))

(defun lawlist-isearch-repeat-backward ()
  "Repeat incremental search backwards."
  (interactive)
  (isearch-repeat 'backward)
;; need to add something that says sit-for any keyboard input before cleanup occurs.
;; (read-event) ;; read-char-exclusive | read-char | read-event
(sit-for 60)
(lawlist-lazy-highlight-cleanup))

2 个答案:

答案 0 :(得分:1)

虽然这不能解决你的问题,但它可能会做你最终想要解决的问题:

(define-key isearch-mode-map [(control up)]   'isearch-ring-retreat)
(define-key isearch-mode-map [(control down)] 'isearch-ring-advance)

键入C-S后,您可以使用C-up和C-down来浏览搜索历史记录。所以C-S C-up会做你想做的事:重复上一次搜索而不留下“粘性”叠加。

另请参阅search-ring-update,如果您愿意,可以进一步自定义。

答案 1 :(得分:0)

使用isearch.el的源代码作为指导,以下OSX附加键分配消除了粘滞突出显示的问题,如上述问题所述。

(define-key global-map [?\s-f] 'isearch-forward)
(define-key esc-map [?\s-f] 'isearch-forward-regexp)
(define-key minibuffer-local-isearch-map [?\s-f] 'isearch-forward-exit-minibuffer)
(define-key isearch-mode-map [?\s-f] 'isearch-repeat-forward)

(define-key global-map [?\s-F] 'isearch-backward)
(define-key esc-map [?\s-F] 'isearch-backward-regexp)
(define-key minibuffer-local-isearch-map [?\s-F] 'isearch-reverse-exit-minibuffer)
(define-key isearch-mode-map [?\s-F] 'isearch-repeat-backward)