help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: show-paren-timeout


From: August Karlstrom
Subject: Re: show-paren-timeout
Date: Fri, 11 Mar 2005 20:37:09 +0100

On fre, 2005-03-11 at 03:30 +0100, August Karlstrom wrote:
> Does anyone know if there's a way to customize `show-paren-mode' so that
> any matching parenthesis is highlighted, but only for a limited amount
> of time, say one second? I find it annoying that the highlighting
> doesn't go away when I leave the cursor beside a parenthesis. There is
> an option called `show-paren-delay' but no `show-paren-timeout'.

I fixed it myself. If anyone's interested here's the code I added to
`.emacs':

;; SHOW PAREN MODE CUSTOMIZATION

(defconst my-show-paren-timeout 1 
  "*Time in seconds until a matching paren is unhighlighted.")

(defvar my-show-paren-timeout-timer nil
  "*Timer used by advice `timeout' of `show-paren-function'.")

(defvar my-show-paren-timeout-saved-point nil
  "*Location used by advice `timeout' of `show-paren-function'.")

(require 'advice)

(defadvice show-paren-function (after timeout)
  "Unhighlight matching paren after `my-show-paren-timeout' seconds."
  (if (and (integerp my-show-paren-timeout-saved-point) 
           (= (point) my-show-paren-timeout-saved-point))
      (progn (delete-overlay show-paren-overlay)
             (delete-overlay show-paren-overlay-1))
    (setq my-show-paren-timeout-saved-point (point))
    (setq my-show-paren-timeout-timer
          (run-with-idle-timer my-show-paren-timeout nil 
                               (lambda ()
                                 (when (= (point) 
                                          my-show-paren-timeout-saved-
point)
                                   (delete-overlay show-paren-overlay)
                                   (delete-overlay show-paren-
overlay-1)))))))

(ad-activate 'show-paren-function)

-- 
August





reply via email to

[Prev in Thread] Current Thread [Next in Thread]