gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Blog listings formatting function


From: Rupert
Subject: Blog listings formatting function
Date: 1 Apr 2007 01:11:02 -0700
User-agent: G2/1.0

Well, heres a quick function that creates a "blog-listings" buffer
with every (regular) file in a directory of your choosing listed
between <code> tags, but with <,>,& escaped.

I used it for putting up a small c++ program in a blog:
M-x make-blog-listings
Type in directory name.

Bam! Done!

Note that it's wise to get rid of e.g. *.o and maybe semantic.db and
*~ first - no-one wants to read them :)

(defun make-blog-listings (dirname)
  (interactive "D")
  "Make a new buffer with the contents of each of the files in
  the directory, enclosed in <code></code> tags, escaped properly
  and titled with the name of the file."
  (let ((files (directory-files (expand-file-name dirname)))
        (blbuf (generate-new-buffer "blog-listings")))
    (set-buffer blbuf)
    (dolist (file files)
      (if (file-regular-p (expand-file-name file (expand-file-name
dirname)))
          (progn
            (insert file ":\n<pre>\n")
            (insert-file-contents
             (expand-file-name file (expand-file-name dirname)))
            (save-restriction
              (narrow-to-region (point) (point-max))
              ; Now we replace horrible stuff with escaping. Yay.
              (replace-string "<" "&lt;")
              (replace-string ">" "&gt;")
              (replace-string "&" "&amp;")
              (replace-string "'" "&apos;")
              (replace-string "\"" "&quot;"))
            (goto-char (point-max))
            (insert "</pre>\n\n"))))
    (switch-to-buffer blbuf)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]