From 168b97d5a300727e742a921c0f1ddb48c108af46 Mon Sep 17 00:00:00 2001 From: Thierry Volpiatto Date: Sun, 14 Dec 2014 12:35:00 +0100 Subject: Allow fontifying helm-org-headings. * helm-org.el (helm-org-headings-fontify): New user var. (helm-get-org-candidates-in-file, helm-org-get-candidates): Use it. --- helm-org.el | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'helm-org.el') diff --git a/helm-org.el b/helm-org.el index 85caab84..d51ed134 100644 --- a/helm-org.el +++ b/helm-org.el @@ -18,15 +18,26 @@ ;;; Code: (require 'cl-lib) (require 'helm) -(require 'helm-plugin) (require 'org) +(defgroup helm-org nil + "Org related functions for helm." + :group 'helm) + +(defcustom helm-org-headings-fontify nil + "Fontify org buffers before parsing them. +This reflect fontification in helm-buffer when non--nil. +NOTE: This will be slow on large org buffers." + :group 'helm-org + :type 'boolean) + ;;; Org headings ;; ;; (defun helm-org-goto-marker (marker) (switch-to-buffer (marker-buffer marker)) (goto-char (marker-position marker)) + (org-show-context) (org-show-entry)) (cl-defun helm-source-org-headings-for-files (filenames @@ -63,17 +74,20 @@ (apply #'append (mapcar (lambda (filename) (helm-get-org-candidates-in-file - filename min-depth max-depth)) + filename min-depth max-depth helm-org-headings-fontify)) filenames))) -(defun helm-get-org-candidates-in-file (filename min-depth max-depth) +(defun helm-get-org-candidates-in-file (filename min-depth max-depth + &optional fontify) (with-current-buffer (find-file-noselect filename) - (save-excursion - (goto-char (point-min)) - (cl-loop while (re-search-forward org-complex-heading-regexp nil t) - if (let ((num-stars (length (match-string-no-properties 1)))) - (and (>= num-stars min-depth) (<= num-stars max-depth))) - collect `(,(match-string-no-properties 0) . ,(point-marker)))))) + (and fontify (jit-lock-fontify-now)) + (let ((match-fn (if fontify 'match-string 'match-string-no-properties))) + (save-excursion + (goto-char (point-min)) + (cl-loop while (re-search-forward org-complex-heading-regexp nil t) + if (let ((num-stars (length (match-string-no-properties 1)))) + (and (>= num-stars min-depth) (<= num-stars max-depth))) + collect `(,(funcall match-fn 0) . ,(point-marker))))))) ;;;###autoload (defun helm-org-agenda-files-headings () @@ -90,17 +104,6 @@ :candidate-number-limit 99999 :buffer "*helm org inbuffer*")) -;; (defvar helm-documentation-filecache nil) -;; (defvar helm-documentation-directory "~/.emacs.d/helm-documentation/") -;; (defun helm-documentation () -;; (interactive) -;; (unless helm-documentation-filecache -;; (setq helm-documentation-filecache -;; (directory-files helm-documentation-directory t "\\.org\\'"))) -;; (helm :sources (helm-source-org-headings-for-files -;; helm-documentation-filecache) -;; :candidate-number-limit 99999 -;; :buffer "*helm org doc*")) (provide 'helm-org) -- cgit v1.2.3