unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* abbrevs and cursor control
@ 2003-02-13 19:01 Harry Putnam
  2003-02-14  9:02 ` Kai Großjohann
  0 siblings, 1 reply; 6+ messages in thread
From: Harry Putnam @ 2003-02-13 19:01 UTC (permalink / raw)


Is there any way to control things like where the cursor lands during
and inserted abbrev?

Something like can be done with skeletons

(define-skeleton hp-mkeywords
	"Insert nifty keywords string into mail/news messages
         and closing characters to make it searchable in a blob"
	nil
	"Keywords: "_"\n" 
	(format-time-string "X-Key-Date: %b %d %Y %w\n") 
	"X-&&: ") 

I'd like to do something like that with the symplicity of an abbrev
rather than calling command or hitting command keys.

I'm thinking of stuff like one might want when writing perl or other
scripts.
An example might be some standard stuff needed for a perl style
getopts section with the cursor located as shown:

  ## ========== BEGIN Getopts section ==========
  ## Declare vars inside qw()
  use vars qw(<cursor>);
  use Getopt::Std;
  my $optstr ="";
  getopts($optstr);

Easy enough if you don't care where the curor goes.. Just wondered
if that can be controlled in an abbrev.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: abbrevs and cursor control
  2003-02-13 19:01 abbrevs and cursor control Harry Putnam
@ 2003-02-14  9:02 ` Kai Großjohann
  2003-02-14 10:00   ` Harry Putnam
  0 siblings, 1 reply; 6+ messages in thread
From: Kai Großjohann @ 2003-02-14  9:02 UTC (permalink / raw)


Harry Putnam <hgp@sbcglobal.net> writes:

> (define-skeleton hp-mkeywords
> 	"Insert nifty keywords string into mail/news messages
>          and closing characters to make it searchable in a blob"
> 	nil
> 	"Keywords: "_"\n" 
> 	(format-time-string "X-Key-Date: %b %d %Y %w\n") 
> 	"X-&&: ") 
>
> I'd like to do something like that with the symplicity of an abbrev
> rather than calling command or hitting command keys.

I hope you mean ease of use rather than ease of definition.  Actually,
you can marry skeletons and abbrevs: the define-abbrev function (and
its ilk) allows you to specify a hook.  You could specify the empty
string as the expansion and the skeleton as the hook.
-- 
A turnip curses Elvis

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: abbrevs and cursor control
  2003-02-14  9:02 ` Kai Großjohann
@ 2003-02-14 10:00   ` Harry Putnam
  2003-02-14 12:49     ` Kai Großjohann
  0 siblings, 1 reply; 6+ messages in thread
From: Harry Putnam @ 2003-02-14 10:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 2194 bytes --]

kai.grossjohann@uni-duisburg.de (Kai Großjohann) writes:

> Harry Putnam <hgp@sbcglobal.net> writes:
>
>> (define-skeleton hp-mkeywords
>> 	"Insert nifty keywords string into mail/news messages
>>          and closing characters to make it searchable in a blob"
>> 	nil
>> 	"Keywords: "_"\n" 
>> 	(format-time-string "X-Key-Date: %b %d %Y %w\n") 
>> 	"X-&&: ") 
>>
>> I'd like to do something like that with the symplicity of an abbrev
>> rather than calling command or hitting command keys.
>
> I hope you mean ease of use rather than ease of definition.  Actually,
> you can marry skeletons and abbrevs: the define-abbrev function (and
> its ilk) allows you to specify a hook.  You could specify the empty
> string as the expansion and the skeleton as the hook.

Swish... that was the sound of your response zooming right over my
head.  Not sure I understand how an empty string can expand, but
maybe I'm reading this wrong.  

After poring over C-h f define-abbrev I got sort of close I guess, but
this:

(define-abbrev TABLE NAME EXPANSION &optional HOOK COUNT SYSTEM-FLAG)

Though its the kind of thing lisp programmers consider the epitome of
lucid. Its not very helpfull to laypeople.  No indication of where
parens might go or other really usefull stuff.

I tried this:

(define-abbrev cperl-mode-abbrev-table "hpb" "" hp-pbase 0 )
then lots of other stuff with parens, finally discovering:
 
(define-abbrev cperl-mode-abbrev-table "hpb" "" (hp-pbase 0))

Evaling with C-x e does insert the hp-pbase skeleton but I'll be
damed if I can see what to type to get it to expand like other
abbrevs.

Typing hpb<spc> just makes the `hpb' disappear and the skeleton stuff 
isn't inserted.

This piece from C-h f:
  If EXPANSION is not a string, the abbrev is a special one,
  which does not expand in the usual way but only runs HOOK.

Kind of sounds like EXPANSION shouldn't be a string at all.  Not even
the empty one "".

So trying 
 (define-abbrev cperl-mode-abbrev-table "hpb" nil (hp-pbase 0))
or
 (define-abbrev cperl-mode-abbrev-table "hpb"  (hp-pbase 0))

C-x e will still insert the hp-pbase skeleton but still nothing good
happens when typing hpb<spc>.  I've run out of experiments.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: abbrevs and cursor control
  2003-02-14 10:00   ` Harry Putnam
@ 2003-02-14 12:49     ` Kai Großjohann
  2003-02-15  3:18       ` Harry Putnam
  0 siblings, 1 reply; 6+ messages in thread
From: Kai Großjohann @ 2003-02-14 12:49 UTC (permalink / raw)


Harry Putnam <hgp@sbcglobal.net> writes:

> After poring over C-h f define-abbrev I got sort of close I guess, but
> this:
>
> (define-abbrev TABLE NAME EXPANSION &optional HOOK COUNT SYSTEM-FLAG)
>
> Though its the kind of thing lisp programmers consider the epitome of
> lucid. Its not very helpfull to laypeople.  No indication of where
> parens might go or other really usefull stuff.
>
> I tried this:
>
> (define-abbrev cperl-mode-abbrev-table "hpb" "" hp-pbase 0 )

(define-abbrev cperl-mode-abbrev-table "hpb" "" 'hp-pbase)

Does this work?

> This piece from C-h f:
>   If EXPANSION is not a string, the abbrev is a special one,
>   which does not expand in the usual way but only runs HOOK.
>
> Kind of sounds like EXPANSION shouldn't be a string at all.  Not even
> the empty one "".

Yes, try nil instead of "".  You already know more about
define-abbrev than I do :-)

-- 
A turnip curses Elvis

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: abbrevs and cursor control
  2003-02-14 12:49     ` Kai Großjohann
@ 2003-02-15  3:18       ` Harry Putnam
  2003-02-15 10:23         ` Kai Großjohann
  0 siblings, 1 reply; 6+ messages in thread
From: Harry Putnam @ 2003-02-15  3:18 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 1578 bytes --]

kai.grossjohann@uni-duisburg.de (Kai Großjohann) writes:

> Harry Putnam <hgp@sbcglobal.net> writes:
>
>> After poring over C-h f define-abbrev I got sort of close I guess, but
>> this:
>>
>> (define-abbrev TABLE NAME EXPANSION &optional HOOK COUNT SYSTEM-FLAG)
>>
>> Though its the kind of thing lisp programmers consider the epitome of
>> lucid. Its not very helpfull to laypeople.  No indication of where
>> parens might go or other really usefull stuff.
>>
>> I tried this:
>>
>> (define-abbrev cperl-mode-abbrev-table "hpb" "" hp-pbase 0 )
>
> (define-abbrev cperl-mode-abbrev-table "hpb" "" 'hp-pbase)
>
> Does this work?

Yes.. and thanks.  I'm not sure how long I would have stumbled around
before I hit that particular combination.

>
>> This piece from C-h f:
>>   If EXPANSION is not a string, the abbrev is a special one,
>>   which does not expand in the usual way but only runs HOOK.
>>
>> Kind of sounds like EXPANSION shouldn't be a string at all.  Not even
>> the empty one "".
>
> Yes, try nil instead of "".  You already know more about
> define-abbrev than I do :-)

It doesn't work that way:
 (define-abbrev cperl-mode-abbrev-table "hpb" nil 'hp-pbase)

So I guess the confusing line from C-h f does mean the empty string
("")..

But now that I see how to do it... my abbrev powers have increased by
several orders of magnitude.  Won't be long before: 

 (define-abbrev cperl-mode-abbrev-table "npscr" "" 'hp-newp)

Will insert a functional debugged full bore search  application.

Oh, how might I have spotted the correct syntax.. from the help
provided? 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: abbrevs and cursor control
  2003-02-15  3:18       ` Harry Putnam
@ 2003-02-15 10:23         ` Kai Großjohann
  0 siblings, 0 replies; 6+ messages in thread
From: Kai Großjohann @ 2003-02-15 10:23 UTC (permalink / raw)


Harry Putnam <hgp@sbcglobal.net> writes:

> Oh, how might I have spotted the correct syntax.. from the help
> provided? 

It says, if HOOK is non-nil, it should be a function of no args.

In Emacs, symbols (with quote in front) are used as functions.  For
example, consider (add-hook 'text-mode-hook 'turn-on-auto-fill).  It
adds the function turn-on-auto-fill to the variable text-mode-hook.
See how the quote is used in front of turn-on-auto-fill when a
function should be passed?

Note that the above also uses a quote in front of the variable.
That's similar to `set': (set 'x 3).  Normally, you use setq instead
of set -- the q stands for quote so you can omit the first quote...

-- 
A turnip curses Elvis

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-02-15 10:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-13 19:01 abbrevs and cursor control Harry Putnam
2003-02-14  9:02 ` Kai Großjohann
2003-02-14 10:00   ` Harry Putnam
2003-02-14 12:49     ` Kai Großjohann
2003-02-15  3:18       ` Harry Putnam
2003-02-15 10:23         ` Kai Großjohann

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).