(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
> 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
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
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