Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Nice idea. I used it in my .emacs but slightly differently. This evals the contents of the current region w/ perl-run-snippet-command and inserts it afterward as comments.

    (defvar perl-run-snippet-command
      "Command for running perl for `perl-run-snippet'")
    (defun perl-run-snippet (start end)
      "Execute `perl-run-snippet-command' on the current region. Insert the results as comments."
      (interactive "r")
      (let ((buffer (current-buffer))
            (snippet-result (generate-new-buffer "*perl-snippet*")))
          ;; Run the snippet
            start end
            snippet-result nil snippet-result)
          ;; Comment it out
          (set-buffer snippet-result)
          (goto-char (point-min))
          (while (re-search-forward "^" nil t)
            (replace-match "# "))
          (set-buffer buffer)
          ;; Insert    the snippet
          (goto-char (max start end))
          (insert-buffer snippet-result)
          ;; Clean up
          (kill-buffer snippet-result))))

    I find it a little more likely I'd rather just turn a snippet into example data for immediate use inline than something far removed at an __END__ tag. FWIW, to do something like that, you'd use commands like the below instead:

    ;; Either:
    ;; * goto the line after __END__
    ;; * goto the end and add an __END__ marker
    (if (re-search-forward "^__END__\n" nil t)
      (goto-char (point-max))
      (if (not (bolp)) (insert "\n"))
      (insert "__END__\n"))