Skip to content

Instantly share code, notes, and snippets.

@punchagan
Last active December 23, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save punchagan/6629020 to your computer and use it in GitHub Desktop.
Save punchagan/6629020 to your computer and use it in GitHub Desktop.
Tag completion for Nikola in emacs
;; Get tags used in the nikola site, using the tags plugin.
(defun nikola-tags-get ()
"Get the current tags in the site, given the site path."
(let* ((nikola-command
"/home/punchagan/.virtualenvs/ultimatesport/bin/nikola")
(nikola-site (file-name-directory
(directory-file-name
(file-name-directory
(or (buffer-file-name (current-buffer)) "/")))))
(tags (shell-command-to-string
(format "cd %s && %s tags -l" nikola-site nikola-command))))
(unless (search "ERROR" tags)
(cdr (split-string tags "\n" t "\s+")))))
(defun nikola-tags-insert ()
"Insert a nikola tag at point."
(interactive)
(let* ((word-match (or (current-word t) ""))
(tags (completing-read-multiple "Tag: " (nikola-tags-get) nil nil word-match)))
(when (and word-match tags)
(delete-backward-char (length word-match)))
(mapc (lambda (tag) (insert (format "%s, " tag))) tags)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment