Skip to content

Instantly share code, notes, and snippets.

@joodie
Created November 9, 2012 09:38
Show Gist options
  • Save joodie/4044829 to your computer and use it in GitHub Desktop.
Save joodie/4044829 to your computer and use it in GitHub Desktop.
navigate to parent and show path in yaml files
(defun yaml-nav-parent-line
()
(interactive)
(let* ((current-i (current-indentation))
(target-i (- current-i yaml-indent-offset)))
(if (= 0 current-i)
nil
(search-backward-regexp (concat "^ \\{" (format "%d" target-i) "\\}[^ #\n]"))
(forward-char target-i)
1)))
(defun yaml-nav-current-key
()
(save-excursion
(move-beginning-of-line nil)
(search-forward-regexp "[^ ]")
(backward-char 1)
(search-forward-regexp "[^:]+")
(match-string 0)))
(defun yaml-nav-show-current-key
()
(interactive)
(message "%s" (yaml-nav-current-key)))
(defun yaml-nav-current-path
()
(let ((p (list (yaml-nav-current-key))))
(save-excursion
(while (yaml-nav-parent-line)
(setq p (cons (yaml-nav-current-key) p))))
(strings-join "." p)))
(defun yaml-nav-show-current-path
()
(interactive)
(message "%s" (yaml-nav-current-path)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment