Last active
December 23, 2015 11:29
-
-
Save punchagan/6629020 to your computer and use it in GitHub Desktop.
Tag completion for Nikola in emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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