Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Standalone Code Tag

by princepawn (Parson)
on Apr 25, 2001 at 17:48 UTC ( #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.

Comment on Standalone Code Tag
Download Code
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

      I'm not sure if you understand me. As a matter of fact, I just looked in the chatterbox and someone made it clear they didn't know what I meant.

      Anyway, let's go through the mechanics of pasting code snippets as perlmonks stands right now.

      1. I type open and close code tags on perlmonks.
      2. And then type a return between them so it's easy to see where my cut and paste will go.
      3. Then I highlight my snippet and cut and paste

      With the addition of a standalone code tag, I only have to type tag tag and paste the code inside:

      <c $/ = 12 >

      It allows for much faster input --- 3 characters versus 13. This is a four-fold increase in efficiency multiplied by many posts. Also think of the disk space savings.

        No, this is not a four-fold increase in efficiency per post.

        Assuming that the typical post contains less than three uses of the code tag, we save up to 30 characters per post on average. With a slow typing speed, this will be about 10-20 seconds per post. I doubt that this will be a significant increase in productivity for the typical post.

        Workaround: Just stop editing in this tiny little window. Use your favorite editor and paste the whole post in. Much better :-) ...

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

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.

      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.

      Could you please be scientific and empirical about this issue? The terms "perfectly fine" and "hardly an imposition" are vague, qualititative and unsubstantiated.

      However, just in case you missed the empirical data and just in case you are amenable to seeing the benefits of such a tag, I re-articulate:

      A short, stand-alone code tag (proposal: the letter C, will require 3 key strokes. The current code tag requires 13. This means for every code tag used on this site, 4 times more characters are being typed. There probably 3000 code tags on this site. That means 12000 times too much disk space has been used AND it also means 12000 times too much time has been used typing the strokes.

      I estimate 30,000 more code tags by the end of December. How much more time and disk space should be eaten up by this task?

      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.
      You are right, the planning and deliberation of the issue has taken some time, but the time and space gains in the long run will prove worth it.

      Is there a formal means of bringing something to a vote?

        This absolutely does not mean 12,0000 times too much disk space has been used. Rather, it means 9,000 more bytes are being used than are, according to your theory, "necessary".

        Why are you freaking out about less than 10K of disk space? PerlMonks would save far more disk space by deleting all the nodes you've posted, than by replacing <CODE></CODE> with <C>. (Not that I'm suggesting such a thing, of course. ;)

        Aside from the fact that your proposal just wouldn't work, because all the occurences of > in the code would have to be encoded, which defeats the purpose of having such a tag in the first place.

Re: Standalone Code Tag
by footpad (Monsignor) 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 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"; }>

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-08-02 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (55 votes), past polls