unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Re: multiple inserts within skeletons
       [not found] <mailman.5300.1051558114.21513.help-gnu-emacs@gnu.org>
@ 2003-04-29  9:58 ` Oliver Scholz
  2003-04-29 10:52   ` Oliver Lohmann
  2003-04-29 14:51   ` Harry Putnam
  0 siblings, 2 replies; 9+ messages in thread
From: Oliver Scholz @ 2003-04-29  9:58 UTC (permalink / raw)


Oliver Lohmann <nagash2270@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é!

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

* Re: multiple inserts within skeletons
  2003-04-29  9:58 ` multiple inserts within skeletons Oliver Scholz
@ 2003-04-29 10:52   ` Oliver Lohmann
  2003-04-29 14:51   ` Harry Putnam
  1 sibling, 0 replies; 9+ messages in thread
From: Oliver Lohmann @ 2003-04-29 10:52 UTC (permalink / raw)


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 

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

* Re: multiple inserts within skeletons
  2003-04-29  9:58 ` multiple inserts within skeletons Oliver Scholz
  2003-04-29 10:52   ` Oliver Lohmann
@ 2003-04-29 14:51   ` Harry Putnam
  2003-04-29 16:22     ` Oliver Scholz
  1 sibling, 1 reply; 9+ messages in thread
From: Harry Putnam @ 2003-04-29 14:51 UTC (permalink / raw)


Oliver Scholz <alkibiades@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 

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

* Re: multiple inserts within skeletons
  2003-04-29 14:51   ` Harry Putnam
@ 2003-04-29 16:22     ` Oliver Scholz
  2003-04-29 23:13       ` Harry Putnam
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Scholz @ 2003-04-29 16:22 UTC (permalink / raw)


[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 <hgp@sbcglobal.net> writes:

> Oliver Scholz <alkibiades@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. :-)

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

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

* Re: multiple inserts within skeletons
  2003-04-29 16:22     ` Oliver Scholz
@ 2003-04-29 23:13       ` Harry Putnam
  2003-04-30  9:23         ` Oliver Scholz
  0 siblings, 1 reply; 9+ messages in thread
From: Harry Putnam @ 2003-04-29 23:13 UTC (permalink / raw)


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

Oliver Scholz <alkibiades@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.

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

* Re: multiple inserts within skeletons
  2003-04-29 23:13       ` Harry Putnam
@ 2003-04-30  9:23         ` Oliver Scholz
  2003-05-07 20:24           ` Multibyte chars [was Re: multiple inserts within skeletons] Harry Putnam
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Scholz @ 2003-04-30  9:23 UTC (permalink / raw)


Harry Putnam <hgp@sbcglobal.net> writes:

> Oliver Scholz <alkibiades@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é!

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

* Multibyte chars [was Re: multiple inserts within skeletons]
  2003-04-30  9:23         ` Oliver Scholz
@ 2003-05-07 20:24           ` Harry Putnam
  2003-05-08  7:34             ` Multibyte chars Oliver Scholz
  0 siblings, 1 reply; 9+ messages in thread
From: Harry Putnam @ 2003-05-07 20:24 UTC (permalink / raw)


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

Oliver Scholz <alkibiades@gmx.de> writes:

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

> Harry Putnam <hgp@sbcglobal.net> writes:
>
>> Oliver Scholz <alkibiades@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: <usms1uvdb.fsf@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

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

* Re: Multibyte chars
  2003-05-07 20:24           ` Multibyte chars [was Re: multiple inserts within skeletons] Harry Putnam
@ 2003-05-08  7:34             ` Oliver Scholz
  2003-05-09  4:33               ` Harry Putnam
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Scholz @ 2003-05-08  7:34 UTC (permalink / raw)


Harry Putnam <hgp@sbcglobal.net> writes:

> Oliver Scholz <alkibiades@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: <usms1uvdb.fsf@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é!

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

* Re: Multibyte chars
  2003-05-08  7:34             ` Multibyte chars Oliver Scholz
@ 2003-05-09  4:33               ` Harry Putnam
  0 siblings, 0 replies; 9+ messages in thread
From: Harry Putnam @ 2003-05-09  4:33 UTC (permalink / raw)


Oliver Scholz <alkibiades@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

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

end of thread, other threads:[~2003-05-09  4:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.5300.1051558114.21513.help-gnu-emacs@gnu.org>
2003-04-29  9:58 ` multiple inserts within skeletons Oliver Scholz
2003-04-29 10:52   ` Oliver Lohmann
2003-04-29 14:51   ` Harry Putnam
2003-04-29 16:22     ` Oliver Scholz
2003-04-29 23:13       ` Harry Putnam
2003-04-30  9:23         ` Oliver Scholz
2003-05-07 20:24           ` Multibyte chars [was Re: multiple inserts within skeletons] Harry Putnam
2003-05-08  7:34             ` Multibyte chars Oliver Scholz
2003-05-09  4:33               ` Harry Putnam

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