Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I expand an abbrev without the space getting added on the end ?

0 views
Skip to first unread message

Glenn Coombs

unread,
Sep 3, 1992, 7:45:31 AM9/3/92
to

I have just written the following bit of code:

(defun magic-main ()
"insert a main () construct automatically"
(beginning-of-line) ; put main at margin
(delete-horizontal-space)
(end-of-line)
(insert-string "\n{\n\t\n}")
(search-backward ")"))

(define-abbrev c-mode-abbrev-table "main" "main ()" 'magic-main)

which should expand a main to:

main ()
{

}

and leave the cursor just before the close bracket. However, the
space that I type after main in order to get it expanded gets added
in after the expansion call has been executed. This means that I end
up with:

main ( )
{

}

and I have to manually delete a space. Does anyone know of a way to
stop this space from appearing or a way to work round it ?

--

-
Glenn ... gl...@prl.philips.co.uk

Wayne Mesard

unread,
Sep 4, 1992, 4:18:33 PM9/4/92
to
gl...@prl.philips.co.uk (Glenn Coombs) writes:
> I have just written the following bit of code:
>
> (defun magic-main ()
> "insert a main () construct automatically"
> (beginning-of-line) ; put main at margin
> (delete-horizontal-space)
> (end-of-line)
> (insert-string "\n{\n\t\n}")
> (search-backward ")"))
>
> (define-abbrev c-mode-abbrev-table "main" "main ()" 'magic-main)

> the


> space that I type after main in order to get it expanded gets added
> in after the expansion call has been executed.

[...]


> and I have to manually delete a space. Does anyone know of a way to
> stop this space from appearing or a way to work round it ?

The insertion of the character you type is the very last thing that
happens during the abbrev-expansion procedure and there's no opportunity
for client elisp code to suppress that.

If you explicitly expand the abbrev via "Control-x '" you won't get an
extra space. I suggest you do that. Also, if you type some other
character to get the abbrev expanded, such as a comma, then you'll get
that character instead of the Space.

There is no over way around this. Believe me, I've tried.
--
Wayne();
WMe...@us.Oracle.COM

Joe Wells

unread,
Sep 5, 1992, 1:47:20 PM9/5/92
to
In article <WMESARD.92...@tofu.oracle.com> wme...@tofu.oracle.com (Wayne Mesard) writes:

The insertion of the character you type is the very last thing that
happens during the abbrev-expansion procedure and there's no opportunity
for client elisp code to suppress that.

You can do this:

(setq unread-command-char ?\C-?)

This will only work if DEL (aka C-?) is bound to a function that deletes
the previous character. If necessary, you save the old binding of some
key, rebind that key to a function that will delete the previous character
and restore the old binding, and then set unread-command-char to that key.

--
Enjoy,

Joe Wells <j...@cs.bu.edu>
Member of the League for Programming Freedom --- send e-mail for details

Lennart Staflin

unread,
Sep 5, 1992, 2:12:05 PM9/5/92
to
You can also bind the space-key to something that expands an eventual
abbreviation but doesn't insert a space.

In tex-mode i use the following function:

(defun TeX-insert-space (arg)
(interactive "p")
(expand-abbrev)
(if (and (= arg 1)
skip-space)
nil
(if (and last-abbrev last-abbrev-location
(< last-abbrev-location (point))
(< (- (point) last-abbrev-location) 200))
(let ((here (point)))
(goto-char last-abbrev-location)
(if (search-forward "\C-b" here 'noerr)
(delete-char -1)
(self-insert-command arg)))
(self-insert-command arg)))
(setq skip-space nil))

[Ignore the skip-space variable, its an old left-over.]

With this function bound to space, the abbreviations expansion can
contain a C-b, if it does the point will be moved to the C-b and no
space will be inserted. If the expansion does not contain a C-b a
normal space will be inserted.

Some typical abbreviations:

"csref" 14 "\\ref{}"
"setof" 3 "\\setof{}{}"

-- Lennart Staflin

0 new messages