Skip to content

Instantly share code, notes, and snippets.

@cehter
Last active December 30, 2015 22:09
Show Gist options
  • Save cehter/7892706 to your computer and use it in GitHub Desktop.
Save cehter/7892706 to your computer and use it in GitHub Desktop.
To generate a shopping-list for the recipes I want to cook.
(defun flush-blank-lines ()
"Removes all blank lines from buffer or region"
(interactive)
(save-excursion
(let (min max)
(if (equal (region-active-p) nil)
(mark-whole-buffer))
(setq min (region-beginning) max (region-end))
(flush-lines "^ *$" min max t))))
(defun food/gen-shopping-list ()
(interactive)
(goto-line 0)
(let ((start-shopping-list (search-forward "* Einkaufsliste" nil t)))
(while (search-forward "** TOCOOK" nil t)
(show-subtree)
(outline-next-visible-heading 1)
(next-line)
(let ((start (point)))
(outline-next-visible-heading 1)
;;(previous-line)
(copy-region-as-kill start (point)))
(save-excursion
(goto-char start-shopping-list)
(newline)
(yank)
(show-subtree)
(delete-blank-lines)))
(goto-char start-shopping-list)
(org-mark-subtree)
(next-line)
(flush-blank-lines))
(org-table-align)
(previous-line)
(org-shifttab))
(defun food/clear-shopping-list ()
(interactive)
(save-excursion
(goto-line 0)
(let ((start-shopping-list (search-forward "* Einkaufsliste" nil t)))
(show-subtree)
(outline-next-visible-heading 1)
(previous-line)
(end-of-line)
(kill-region start-shopping-list (point)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment