[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to complete \] when I input \[ .
From: |
Thierry Volpiatto |
Subject: |
Re: How to complete \] when I input \[ . |
Date: |
Mon, 15 Sep 2008 07:57:34 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
dkcombs@panix.com (David Combs) writes:
> In article <mailman.16901.1218898721.18990.help-gnu-emacs@gnu.org>,
> Thierry Volpiatto <thierry.volpiatto@gmail.com> wrote:
>>"xiaopeng hu" <huxiaopengstat@gmail.com> writes:
>>
>>> I mean \[ \]. thanks
>>>
>>> 2008/8/16 David Hansen <david.hansen@gmx.net>
>>>
>>>> On Sat, 16 Aug 2008 21:09:46 +0800 xiaopeng hu wrote:
>>>>
>>>> > When I input \[ , how to complete \] and put point at middle?
>>>> >
>>>>
>>>> Should work:
>>>>
>>>> (global-set-key (kbd "[") #'insert-pair)
>>>>
>>>> David
>>
>>,----
>>| (defun insert-second-hook ()
>>| (interactive)
>>| (insert "\[\\]")
>>| (goto-char (- (point) 2)))
>>| (global-set-key (kbd "\[") 'insert-second-hook)
>>`----
>>
>>--
>>A + Thierry Volpiatto
>>Location: Saint-Cyr-Sur-Mer - France
>
> If you're got time, please briefly explain how it works, what it does, etc.
If i remember OP wanted completion on \[ with \] with the "\" included
thats why there is \ in insert.
This version complete the "[" with "]" and put point between the [].
,----[ insert pair of [] ]
| (defun insert-second-hook ()
| (interactive)
| (insert "[]")
| (goto-char (- (point) 1)))
| (global-set-key (kbd "\[") 'insert-second-hook)
`----
when you press key [ it insert the two [] and then go back one char.
Note that is a very simple code and can be much better, look at
pair-mode.el.
Note also you can set key [ locally for a special mode with
`define-key' instead of setting it globally with `global-set-key'.
Personnaly i don't like completion on pairs so i don't use that :)
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France