Expand Cut Tags

No cut tags
cbrachyrhynchos: (Default)
[personal profile] cbrachyrhynchos

I've been fooling around with writing up some convenience functions for writing hugo posts. A lot of my earlier work from last year is described in this post.

Problem 1: Finding the root folder

There's an emacs function for that locate-dominating-file.

(defun locate-hugo-root ()
  "Search up from current file to find the root of the hugo directory."
   (let ((fPath
         (if (equal major-mode 'dired-mode)
     (locate-dominating-file fPath "config.toml")))

Problem 2: Creating a new post

Prompt with ido find file. Check if the buffer is empty, if the buffer is empty run a header skeleton.

(defun hugo-new-post ()
  "Prompt for a filename and then create a new post using hugo-yaml-skeleton."
  (ido-find-file-in-dir default-directory) 

  (when (= 0 (buffer-size))

Problem 3: Better searching

Built-in emacs searching doesn't really have good defaults for this to accommodate older versions of grep, and I can't be certain of having ag, the silver searcher everywhere. So I run grep with a custom command string, using the (almost) common lisp format to build my command string. For grep, I include --include='*.md' to ensure I'm only searching markdown files.

(require 'cl)
(defun hugo-search-markdown (search-string directory)
  "Search markdown files for search-string in directory."
  (interactive "sSearch string: \nDDirectory: ")
   (format "grep -r -nH --include='*.md' --include='*.markdown' '%s' %s" search-string directory)))

Problem 4: Starting a server

Start a hugo server to preview the blog before publication.

(defun hugo-start-server ()
  "Start a server in the root of the current working directory."
  (if (locate-hugo-root)

       (concat "hugo server -s "
    (message "Can't find hugo config file at %s" default-directory)))


cbrachyrhynchos: (Default)

July 2017

234 5678
91011 1213 1415
16 17 1819202122
23 2425 26272829

Most Popular Tags

Style Credit

Page generated Jul. 28th, 2017 07:01 pm
Powered by Dreamwidth Studios