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

multiple inserts within skeletons

112 views
Skip to first unread message

Oliver Lohmann

unread,
Apr 28, 2003, 3:29:28 PM4/28/03
to help-gn...@gnu.org
hello,

i want to repeat my inputs for @param with the follwing construct
(only an example) until i take a key or any other trigger
to exit the input ring:

(defun myComment(s1 s2)
(interactive "sbriefDescr: \nsMethodParam: ")
(skeleton-insert'(nil
>"/**" \n
>"* " s1 \n
>"* " \n
>"* @param " s2 \n
;;--> ;; more params here please...
>"* " \n
>"* " \n
>"* @author " user-full-name \n
>"* @note " user-mail-address \n
>"* @date " (insert-date) \n
>"*/" \n _ )))


thanks for your help!


kind regards
oliver lohmann

Oliver Scholz

unread,
Apr 29, 2003, 5:58:07 AM4/29/03
to
Oliver Lohmann <nagas...@yahoo.de> writes:

> hello,
>
> i want to repeat my inputs for @param with the follwing construct
> (only an example) until i take a key or any other trigger
> to exit the input ring:
>
> (defun myComment(s1 s2)
> (interactive "sbriefDescr: \nsMethodParam: ")
> (skeleton-insert'(nil

[...]

Why don't you use `define-skeleton' instead of writing a defun with
`skeleton-insert'?

A skeleton may contain a sub-skeleton as an element. In this case it
is repeated until the user hits RET without having anything
entered. For example:

(define-skeleton my-comment
"FIXME: documentation"
nil
"BEGIN NONSENSE" \n
> "Everything on the following lines" \n
> "is pure nonsense." \n
("Type a silly word: " "lirum larum -- " str & \n | -15)
"END NONSENSE")


Oliver
--
10 Floréal an 211 de la Révolution
Liberté, Egalité, Fraternité!

Oliver Lohmann

unread,
Apr 29, 2003, 6:52:06 AM4/29/03
to help-gn...@gnu.org
On Tue, 2003-04-29 at 11:58, Oliver Scholz wrote:

> A skeleton may contain a sub-skeleton as an element. In this case it
> is repeated until the user hits RET without having anything
> entered. For example:
>
> (define-skeleton my-comment
> "FIXME: documentation"
> nil
> "BEGIN NONSENSE" \n
> > "Everything on the following lines" \n
> > "is pure nonsense." \n
> ("Type a silly word: " "lirum larum -- " str & \n | -15)
> "END NONSENSE")


thanks, that's all i need!

best regards
oliver

Harry Putnam

unread,
Apr 29, 2003, 10:51:25 AM4/29/03
to
Oliver Scholz <alkib...@gmx.de> writes:


> A skeleton may contain a sub-skeleton as an element. In this case it
> is repeated until the user hits RET without having anything
> entered. For example:
>
> (define-skeleton my-comment
> "FIXME: documentation"
> nil
> "BEGIN NONSENSE" \n
> > "Everything on the following lines" \n
> > "is pure nonsense." \n
> ("Type a silly word: " "lirum larum -- " str & \n | -15)
> "END NONSENSE")

This is close to something I've tried to do a few times. Maybe you
can coach me a little here.

I'd like to produce and insert that looks like:

# Keywords: Some Key words
# More commentary
# yet more comentary
# CURRENT_DATE
# &&

Trying to rework your example like this comes sort of close.:

(define-skeleton my-comment
"Keywords formatted input"
nil
"# Keywords: "
("Type descriptive comments: " "# " str & \n | -15)
"END NONSENSE")

# Keywords: # some key words
# more commentary
# yet more commentary
# CURRENT_DATE
# &&

NOTE: Current Date and closing ampersands added by hand but I'd like
the skeleton to do that for me.

1) How can I make the octothorpe begin to appear only after the
keywords line, so it doesn't appear after `Keywords'.

2) Can I arrange the skeleton so that when I press C-g to break out,
it inserts the CURRENT_DATE followed by `# &&' on a separate line?
Or in some other way cause those last two items to be inserted
automatically

Oliver Scholz

unread,
Apr 29, 2003, 12:22:08 PM4/29/03
to
[Note: skeletons are not Lisp, but a special purpose language. The
various parts of a skeleton program are called “elements”. Elements
may be strings, sexpr (which are either sub-skeletons or Lisp
expressions) or special skeleton commands like >, _, @, \n, | or
&. Have a look at `C-h f skeleton-insert RET' or at the “Autotype”
info manual.]

Harry Putnam <h...@sbcglobal.net> writes:

> Oliver Scholz <alkib...@gmx.de> writes:
[define-skeleton]

> This is close to something I've tried to do a few times. Maybe you
> can coach me a little here.
>
> I'd like to produce and insert that looks like:
>
> # Keywords: Some Key words
> # More commentary
> # yet more comentary
> # CURRENT_DATE
> # &&
>
> Trying to rework your example like this comes sort of close.:
>
> (define-skeleton my-comment
> "Keywords formatted input"
> nil
> "# Keywords: "
> ("Type descriptive comments: " "# " str & \n | -15)
> "END NONSENSE")
>
> # Keywords: # some key words
> # more commentary
> # yet more commentary
> # CURRENT_DATE
> # &&
>
> NOTE: Current Date and closing ampersands added by hand but I'd like
> the skeleton to do that for me.

By “current date” do you mean the current date or the literal text
“CURRENT_DATE”? If the former: skeletons may contain abitrary Lisp
expressions as elements, which are then evaluated and the return value
is inserted into the buffer. You could use this feature together with
the function `current-time-string'. for example:

(define-skeleton my-test-skel
"Insert the current time and date."
nil
"Date: " (current-time-string) ".")

If you mean just the literal “CURRENT_DATE”: just add a string to the
skeleton language.

> 1) How can I make the octothorpe begin to appear only after the
> keywords line, so it doesn't appear after `Keywords'.

I don't know what an “octothorpe” is; it's not im my Webster's. I
assume that you mean the “#”?

If so, I believe, you want something like this:

(define-skeleton my-comment
"Insert keywords formatted input."
"Keywords: "
"# Keywords: " str \n
("Comment: " "# " str "\n"))

Basically the difference is, that this uses the combination of
PROMPT + “str” two times in two different ways: "Keywords: " and the
first occurence of “str” in the top-skeleton; "Comment: " and the
second “str” in the sub-skeleton.

[The “str & \n | -15” stuff that I recommended earlier is pointless,
as I realize now: sub-skeletons are inserted *only*, if the user has
entered something at the prompt.]

> 2) Can I arrange the skeleton so that when I press C-g to break out,
> it inserts the CURRENT_DATE followed by `# &&' on a separate line?
> Or in some other way cause those last two items to be inserted
> automatically

Well, for one you could simply hit RET, when prompted for a
“descriptive comment”. The skeleton program then leaves the
sub-skeleton loop and resumes the top skeleton. But if you have (like
me) the bad habit to type `C-g' all the time to get out of the
minibuffer, you can use the `resume:' keyword to specify a place where
the skeleton should resume execution after the user hit `C-g'. For
example.

(define-skeleton my-repeat-ad-nauseam
""
nil
("Type something, please: " str "\n")
& "Allright, we finished in a normal way."
| resume: & "Aha, you lost temper and hit `C-g'.")

I hope this sets you on the track. :-)

Harry Putnam

unread,
Apr 29, 2003, 7:13:26 PM4/29/03
to
Oliver Scholz <alkib...@gmx.de> writes:

Oliver... I must have some language setting that will help me read
your response. I see quite a lot of unusual chars, back slashes and
three diget number in your text.I'm running a fairly recent cvs emacs:
GNU Emacs 21.3.50.1 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
I've set no language var away from what ever is default.

I've included quite a lot of your answer hoping to show what I see on
this end, but not sure it will come to you as I see it. Can you
suggest a setting that will allow me to see in english what you've
said?

Afterwards please ignore the hefty inclusion and have a look at my clumsy
attempt at the end

I think I'm getting the gist of what you intend... thanks.

> By “current date” do you mean the current date or the literal text
> “CURRENT_DATE”? If the former: skeletons may contain abitrary Lisp
> expressions as elements, which are then evaluated and the return value
> is inserted into the buffer. You could use this feature together with
> the function `current-time-string'. for example:

I meant actual current time when skeleton is fired.

> (define-skeleton my-test-skel
> "Insert the current time and date."
> nil
> "Date: " (current-time-string) ".")

Yeah, like that..

> If you mean just the literal “CURRENT_DATE”: just add a string to the
> skeleton language.
>
>> 1) How can I make the octothorpe begin to appear only after the
>> keywords line, so it doesn't appear after `Keywords'.
>
> I don't know what an “octothorpe” is; it's not im my Webster's. I
> assume that you mean the “#”?

Commonly called a pound sign (#).

> If so, I believe, you want something like this:
>
> (define-skeleton my-comment
> "Insert keywords formatted input."
> "Keywords: "
> "# Keywords: " str \n
> ("Comment: " "# " str "\n"))
>

Yup, again... Thanks

> Basically the difference is, that this uses the combination of
> PROMPT + “str” two times in two different ways: "Keywords: " and the
> first occurence of “str” in the top-skeleton; "Comment: " and the
> second “str” in the sub-skeleton.
>
> [The “str & \n | -15” stuff that I recommended earlier is pointless,
> as I realize now: sub-skeletons are inserted *only*, if the user has
> entered something at the prompt.]

>> 2) Can I arrange the skeleton so that when I press C-g to break out,
>> it inserts the CURRENT_DATE followed by `# &&' on a separate line?
>> Or in some other way cause those last two items to be inserted
>> automatically
>
> Well, for one you could simply hit RET, when prompted for a
> “descriptive comment”. The skeleton program then leaves the
> sub-skeleton loop and resumes the top skeleton. But if you have (like
> me) the bad habit to type `C-g' all the time to get out of the
> minibuffer, you can use the `resume:' keyword to specify a place where
> the skeleton should resume execution after the user hit `C-g'. For
> example.
>
> (define-skeleton my-repeat-ad-nauseam
> ""
> nil
> ("Type something, please: " str "\n")
> & "Allright, we finished in a normal way."
> | resume: & "Aha, you lost temper and hit `C-g'.")
>
> I hope this sets you on the track. :-)

Thank you. Yes this is what I was after. Putting all you told me
together I come up with an almost working skeleton. It fails to
handle the <RET> style of closure unlike your example.

My code produces a double ending if I choose to close with <RET> but
works if I close with C-g. I'm pretty sure its got some parens
arranged wrong or not enough `lists withing lists', but since my lisp
skills are non-existent I've resorted to dozens of trials... so far
none have worked like your example. Maybe you can spot the short
comming?


(define-skeleton hp-com_keywords
"Insert commented keywords formatted input."


"Keywords: "
"# Keywords: " str \n
("Comment: " "# " str "\n")

& "# "(format-time-string "%b %d %Y %w %T\n")
& "# && CLOSED WITH <RET>"
| resume: & "# "(format-time-string "%b %d %Y %w %T\n")"# && CLOSED WITH C-g")

Using <RET> style closure produces:

# Keywords: SOME KEY WORDS
# Commentary ->
# More commentary ->
# Apr 29 2003 2 16:08:22
# && CLOSED WITH <RET>Apr 29 2003 2 16:08:22
# && CLOSED WITH C-g

Using C-g produces:

# Keywords: SOME KEY WORDS
# Commentary ->
# More commentary ->
# Apr 29 2003 2 16:09:02
# && CLOSED WITH C-g

I'm missing how to setup the body of the skeleton so it works like
your example.

Oliver Scholz

unread,
Apr 30, 2003, 5:23:16 AM4/30/03
to
Harry Putnam <h...@sbcglobal.net> writes:

> Oliver Scholz <alkib...@gmx.de> writes:
>
> Oliver... I must have some language setting that will help me read
> your response. I see quite a lot of unusual chars, back slashes and
> three diget number in your text.

[...]

That sounds as if the text is interpreted as unibyte text. What is the
value of `enable-multibyte-characters' in this buffer? -- But if it is
t, what does `C-u C-x =' return with point on such a character?

> I've included quite a lot of your answer hoping to show what I see on
> this end, but not sure it will come to you as I see it. Can you
> suggest a setting that will allow me to see in english what you've
> said?

You didn't loose any information. I just have used typographical
English quotations marks (from the Unicode charset) in some places
instead of the usual ASCII-ones. Perhaps I should turn this off
again, it is probably sufficient that I annoy the people in the German
Usenet with this fancy of mine. :-)

[...]


> Thank you. Yes this is what I was after. Putting all you told me
> together I come up with an almost working skeleton. It fails to
> handle the <RET> style of closure unlike your example.
>
> My code produces a double ending if I choose to close with <RET> but
> works if I close with C-g. I'm pretty sure its got some parens
> arranged wrong or not enough `lists withing lists', but since my lisp
> skills are non-existent I've resorted to dozens of trials... so far
> none have worked like your example. Maybe you can spot the short
> comming?
>
>
> (define-skeleton hp-com_keywords
> "Insert commented keywords formatted input."
> "Keywords: "
> "# Keywords: " str \n
> ("Comment: " "# " str "\n")
> & "# "(format-time-string "%b %d %Y %w %T\n")
> & "# && CLOSED WITH <RET>"
> | resume: & "# "(format-time-string "%b %d %Y %w %T\n")"# && CLOSED WITH C-g")

^^^ ^^^

There's an `&' missing in those places. You have to "tye" elements
together that you want to insert conditionally (that is: based on the
*same* condition). An `&' means: "Insert the following element only if
point was moved due to processing of the previous element." (Which
usually means that the previous element caused some insertion.)

An IF-THEN-ELSE statement would look like this:

ELEMENT & ELEMENT [& ELEMENT] | ELEMENT [& ELEMENT]

^ ^
if then ^ else

For example:

(define-skeleton hunt-the-snark
"Insert a silly example sentence."
"Enter the name of a person: "
str & " hunts " & "the " & "snark."
| "Nobody " & "is hunting " & "anyone.")

Delete the `|' or any of the `&'s and you'll probably see what I mean.
(To get through to the THEN-part, hit RET immediately when you are
prompted for the name of a person.)

Of course, if you simply want "&&" at the end, you don't need all
those `&' and `|':

(define-skeleton hp-com_keywords
"Insert commented keywords formatted input."
"Keywords: "
"# Keywords: " str \n
("Comment: " "# " str "\n")

resume:


"# "(format-time-string "%b %d %Y %w %T\n")

"# &&")

Oliver
--
11 Floréal an 211 de la Révolution
Liberté, Egalité, Fraternité!

Harry Putnam

unread,
May 7, 2003, 4:24:32 PM5/7/03
to
Oliver Scholz <alkib...@gmx.de> writes:

Going to the subject of multibyte chars instead of the original
topic of skeletons for a moment:

> Harry Putnam <h...@sbcglobal.net> writes:
>
>> Oliver Scholz <alkib...@gmx.de> writes:
>>
>> Oliver... I must have some language setting that will help me read
>> your response. I see quite a lot of unusual chars, back slashes and
>> three diget number in your text.
> [...]
>
> That sounds as if the text is interpreted as unibyte text. What is the
> value of `enable-multibyte-characters' in this buffer? -- But if it is
> t, what does `C-u C-x =' return with point on such a character?

Oliver... Sorry I took so long to reply here.

Since its been so long since this thread was current.. The response
of yours referenced abouve is:
Message-ID: <usms1u...@ID-87814.user.dfncis.de>

About `enable-multibyte-characters': In that buffer the value is `nil'
but I ran into something I don't understand trying to set it to `t'.

M-x set-variable enable-multibyte-characters t

Gives me:
Variable enable-multibyte-characters is read-only

I don't recall ever seeinig that message come up when setting a var before.

C-u C-x = on a character that looks like an `a' with two small dots
over it followed by slash (\)200\234current date(a with dots)\200\235

character: ā (0342, 226, 0xe2)
charset: eight-bit-graphic (8-bit graphic char (0xA0..0xFF))
code point: 226
syntax: which means: whitespace
category:
buffer code: 0xE2
file code: 0xE2 (encoded by coding system utf-8)
font: -Adobe-Courier-Bold-R-Normal--14-100-100-100-M-90-ISO8859-1

Oliver Scholz

unread,
May 8, 2003, 3:34:00 AM5/8/03
to
Harry Putnam <h...@sbcglobal.net> writes:

> Oliver Scholz <alkib...@gmx.de> writes:
[...]
>> That sounds as if the text is interpreted as unibyte text. What is the
>> value of `enable-multibyte-characters' in this buffer? -- But if it is
>> t, what does `C-u C-x =' return with point on such a character?
>
> Oliver... Sorry I took so long to reply here.
>
> Since its been so long since this thread was current.. The response
> of yours referenced abouve is:
> Message-ID: <usms1u...@ID-87814.user.dfncis.de>
>
> About `enable-multibyte-characters': In that buffer the value is `nil'
> but I ran into something I don't understand trying to set it to `t'.
>
> M-x set-variable enable-multibyte-characters t
>
> Gives me:
> Variable enable-multibyte-characters is read-only
>
> I don't recall ever seeinig that message come up when setting a var before.

Yes, that's expected for `enable-multibyte-characters'. (Though I
don't know how it is implemented, not having read the code.) You can
toggle a buffer between multibyte and unibyte with the command
`M-x toggle-enable-multibyte-characters'. But I believe that this
should normally not be necessary. Emacs uses multibyte buffers by
default. Do you start it with the "--unibyte" command line option? Or
do you have `(standard-display-european t)' somewhere in you .emacs?

Toggling with `toggle-e-m-characters' when Gnus displays the article
won't help, because the strange characters and numbers that you see
are probably the UTF-8 representation interpreted as unibyte
characters. So the article was not decoded in the first
place. Toggling multibyte will only help, if the UTF-8 got decoded to
Emacs' internal multibyte representation (emacs-mule).

But I think that all this will just work, if you find out what causes
your Emacs to use a unibyte buffer.

Oliver
--
19 Floréal an 211 de la Révolution
Liberté, Egalité, Fraternité!

Harry Putnam

unread,
May 9, 2003, 12:33:35 AM5/9/03
to
Oliver Scholz <alkib...@gmx.de> writes:

[...]

> do you have `(standard-display-european t)' somewhere in you .emacs?

[...]

Yup.. an overlooked holdover from long ago lurking in site-start.el
Not exactly as you guessed:
(standard-display-european 1)
1 instead of t but I think it does the same eh?

> But I think that all this will just work, if you find out what causes
> your Emacs to use a unibyte buffer.

Removing that line caused the buffer to appear normal now ... thanks

0 new messages