Mistress of My Domain

Hacking Emacs for Jekyll Stuff

I am very fortunate that my sweetie can hack Emacs for me. Oh, sure, I could learn elisp and do it for myself, but the time it would take to level up my proficiency... I take the easy way out. (๑´ㅂ`๑ )

Change Emacs auto-save file names so Jekyll rebuilds don't trigger

So far, I've asked for 2 things to help with my Jekyll issues. The first is to rename Emacs auto-save files so that they don't trigger Jekyll re-builds every time you touch a file. Sure, I tried to configure Jekyll to ignore files of that format (filenames starting with a "#") but nothing I tried worked. And so, this:

;; change auto-save file names so Jekyll doesn't trigger
(defun auto-save-file-name-p (filename)
            "Return non-nil if FILENAME can be yielded by..."
            (string-match "^#.*#~$" filename))

(defun make-auto-save-file-name ()
            "Return file name to use for auto-saves of current buffer.."
            (if buffer-file-name
                (concat
                 (file-name-directory buffer-file-name)
                 "#"
                 (file-name-nondirectory buffer-file-name)
                 "#~")
              (expand-file-name
               (concat "#%" (buffer-name) "#~"))))
And now the file names end with a "~" and Jekyll is happy to ignore them.

Generate a base 62 ID code with Emacs

While working with imported comments from Drupal, I figured the best thing to do going forward if one wanted to continue with comments on blog posts was to add in a nid (node ID) field to post front matter. Drupal uses a database, though and their NID is a number that increments. I didn't want to use a database or even an incrementing number stored somewhere. The easiest thing to do would be to use system time since now that the import phase is essentially over, I'm going to be generating my posts by hand so there's no chance of ID collision with a key that is in time in seconds.

Having said that, and for no particularly good reason, I didn't like the raw time, it felt too long. I wanted to convert it to duosexagesimal format (base 62, alphanumeric using both upper and lower case letters). So, here that is, including my keybindings:

;; generate an alphanumeric node ID based on current time
(defun basen (n b)
  (let ((numerals "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
    (if (< n b)
	(string (aref numerals n))
      (concat
       (basen (/ n b) b)
       (string (aref numerals (% n b)))))))

(defun time-to-base62 (&optional arg)
  (interactive "P")
  (let ((time-code (basen (string-to-number (format-time-string "%s" (current-time))) 62)))
    (insert-and-inherit
     (if (null arg)
	 time-code
       (concat "nid: " time-code)))))

(global-set-key (kbd "C-c C-c d") 'time-to-base62)
(global-set-key (kbd "C-c C-c D") (lambda () (interactive) (time-to-base62 t)))

And here's an example ID "1HdFYp".

This has been Fun with Emacs. ୧( “̮ )୨✧

Post a New Comment






?

Note: for security reasons, a mailto link is being used. If configured on your end, this is the safest way for both parties. This activates your mailer to send the data entered. See here or here for why that might not work and what to do about it.