Skip to content

Instantly share code, notes, and snippets.

@uris77
Forked from tjg/helm-clojure-headlines.el
Created October 7, 2015 16:35
Show Gist options
  • Save uris77/1936e60112eac328d06a to your computer and use it in GitHub Desktop.
Save uris77/1936e60112eac328d06a to your computer and use it in GitHub Desktop.
helm-clojure-headlines
(defun helm-headlines (headline buffer-name good-regex exception-regex)
"Display headlines for the current file.
Displays lines where good-regex matches, except for those
which also match exception-regex."
;; Fixes bug where the current buffer sometimes isn't used
(setq helm-current-buffer (current-buffer))
;; https://groups.google.com/forum/#!topic/emacs-helm/YwqsyRRHjY4
(jit-lock-fontify-now)
(helm :sources (helm-build-in-buffer-source headline
:data (with-helm-current-buffer
(goto-char (point-min))
(cl-loop while (re-search-forward
good-regex nil t)
for line = (buffer-substring (point-at-bol)
(point-at-eol))
for pos = (line-number-at-pos)
unless (and exception-regex
(string-match-p exception-regex line))
collect (propertize line 'helm-realvalue pos)))
:get-line 'buffer-substring
:action (lambda (c) (helm-goto-line c)))
:buffer buffer-name))
(defun helm-clojure-headlines ()
"Display headlines for the current Clojure file."
(interactive)
(helm-headlines "Clojure Headlines"
"helm-clojure-headlines"
"^(\\|^;.*[a-zA-Z]+"
"^(.*comment"))
(defun helm-python-headlines ()
"Display headlines for the current Python file."
(interactive)
(helm-headlines "Python Headlines"
"helm-python-headlines"
"^def.*[a-zA-Z]+\\|^#"
nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment