A couple of handy Emacs functions

First, a short function to attach a file when editing a Markdown page in ikiwiki:

(defun x-hugh-wiki-attach-file-to-wiki-page (filename)
  "This is my way of doing things."
  (interactive "fAttach file: ")
  ;; doubled slash, but this makes it clear
  (let* ((page-name (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))
         (local-attachments-dir (format "%s/attachments/%s" (file-name-directory (buffer-file-name)) page-name))
     (attachment-file (file-name-nondirectory filename))
     (attachment-url (format "https://wiki.example.org/wiki/attachments/%s/%s" page-name attachment-file)))
(make-directory local-attachments-dir 1)
(copy-file filename local-attachments-dir 1)
(insert-string (format "[[%s|%s]]" attachment-file attachment-url))))

Note the way I'm organizing things: there's a directory in the wiki/tree called "attachments"; a subdirectory is created for each page; and the file is dumped there.

Second, a stupid copy-file-template function for Cfengine:

(defun x-hugh-cf3-insert-file-template (file)
  "Insert a copy-file template."
  (interactive "sFile to copy: ")
  (newline-and-indent)
  (insert-string (format "\"%s\"" file))
  (newline-and-indent)
  (insert-string (format "  comment => \"Copy %s into place.\"," file))
  (newline-and-indent)
  (insert-string (format "  perms   => mog(\"0755\", \"root\", \"wheel\"),"))
  (newline-and-indent)
  (insert-string (format "  copy_from => secure_cp(\"$(g.masterfiles)/centos/5%s\", \"$(g.masterserver)\";" file)))

Both are mostly learning exercises and excuses to post.