Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Standalone Code Tag

by princepawn (Parson)
on Apr 25, 2001 at 17:48 UTC ( [id://75445]=monkdiscuss: print w/replies, xml ) Need Help??

Right now, we have the container code tag. However, for efficiency, I would like to type something like
(codequote $x = 5 )
So that all I have to do is type the tag, move the cursor inside the tag and copy and paste to point.

It would save some time on this oft-done operation.

Replies are listed 'Best First'.
Re: Standalone Code Tag
by chipmunk (Parson) on Apr 25, 2001 at 20:07 UTC
    Using a single tag like <codequote code goes here> will not work, because the trailing delimiter is a single-character. You would have to escape whatever character is used when it appears in the code, which defeats the whole purpose of the code tag.

    <code> if ($x > 7) { print "yay!\n"; }</code>

    <c if ($x &gt; 7) { print "yay!\n"; }>

Re: Standalone Code Tag
by footpad (Abbot) on Apr 25, 2001 at 19:12 UTC

    I can see where this would be desireable (after all, no one wants to type more than necessary), but two thoughts come to mind:

    • Any good editor provides shortcuts that can help.

      If you compose off-line, as I often do, try using your editor to design a short macro/template/whatever that a) adds <CODE> </CODE> tags, b) positions the cursor between them, and c) binds the results to a control sequence. You'd get the same benefit without adding work to Fearless's ToDo list.

    • Given the shift toward a more strict SGML base in HTML and so on, closing tags are a good habit to get into. For example, certain browsers will not apply styles to paragraphs unless you supply the </P> tag.

      At the very least, closing tags help make nodes a little easier to process using XML.

    Saving time is a good thing. However, we often tell people to use warnings and to use strict for very good reasons. It's extra code (or extra work in the macros/templates/etc), but good practice. To my mind, closing tags are just as good practice.

    --f

Re: Standalone Code Tag
by clemburg (Curate) on Apr 25, 2001 at 18:13 UTC

    For your .emacs (try out in scratch buffer):

    (defun codequote (code)
      (interactive "sCode: ")
      (insert (concat "<code>" code "</code>")))
    (local-set-key [f5] 'codequote)
    

    He, found a nice bug of code tag during this: Code should not contain the sequence "</code>". Anybody know how to escape this (no, HTML entities don't work)?

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Standalone Code Tag
by turnstep (Parson) on Apr 25, 2001 at 18:42 UTC

    Why should we invent new HTML tags when the ones we have are perfectly fine? Having to type a closing CODE tag is hardly an imposition imposed upon members of the monastery. Matter of fact, you probably spent more time typing this post and your reply than it took you to type </CODE> for all your posts in the last year.

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: monkdiscuss [id://75445]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found