unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: dkcombs@panix.com (David Combs)
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to complete \] when I input \[ .
Date: Mon, 15 Sep 2008 07:57:34 +0200	[thread overview]
Message-ID: <873ak2uf1t.fsf@tux.homenetwork> (raw)
In-Reply-To: <gakhra$rpd$1@reader1.panix.com> (David Combs's message of "Mon,  15 Sep 2008 02:38:34 +0000 (UTC)")

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




  reply	other threads:[~2008-09-15  5:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-16 13:09 How to complete \] when I input \[ xiaopeng hu
2008-08-16 13:15 ` David Hansen
2008-08-16 14:00   ` xiaopeng hu
2008-08-16 14:55     ` Thierry Volpiatto
2008-08-16 15:46     ` David Hansen
     [not found]     ` <mailman.16901.1218898721.18990.help-gnu-emacs@gnu.org>
2008-09-15  2:38       ` David Combs
2008-09-15  5:57         ` Thierry Volpiatto [this message]
     [not found]   ` <mailman.16899.1218895239.18990.help-gnu-emacs@gnu.org>
2008-08-16 15:56     ` Chat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=873ak2uf1t.fsf@tux.homenetwork \
    --to=thierry.volpiatto@gmail.com \
    --cc=dkcombs@panix.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).