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

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

Re: left brackets insert both


From: rgb
Subject: Re: left brackets insert both
Date: 25 Mar 2005 09:49:48 -0800
User-agent: G2/0.2

Shug Boabby wrote:
> excellent! i had found the exact setup once rgb had pointed me to the
> function call, but cheers david!
>
> however, it is sometimes annoying that a single type of a bracket
does
> this... any chance i could set it only to work on double taps? i get
> nothing when i try something like:
>   (global-set-key [?\< ?\<] 'skeleton-pair-insert-maybe)
> i guess its trying to find the skeleton pair to << instead of <

You can probably adapt this to your needs.

(defmacro my-insert-if-double (new-txt)
   "If last key same as this key, replace both with new-txt."
   `(lambda (cnt)
      (interactive "p")
      (if (equal (preceding-char) last-command-char)
          (progn
              (backward-delete-char 1)
              (insert ,new-txt))
          (self-insert-command cnt))))
 (add-hook 'html-mode-hook
   (lambda ()
     (local-set-key [(<)]  (my-insert-if-double "&lt;"))
     (local-set-key [(>)]  (my-insert-if-double "&gt;"))
     (local-set-key [(&)]  (my-insert-if-double "&amp;"))
     (local-set-key [(\")] (my-insert-if-double "&quot;"))))



reply via email to

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