Re: [O] More helm awesomeness

2015-01-19 Thread John Kitchin
Here is a more advanced function that works on your agenda files: You
run the second one:
M-x helm-query-agenda

and enter your search query in org syntax, e.g. TODO="PREPARATION" will
give you a helm menu of headlines with that TODO state.

I am not that sophisticated a user of org queries like this, so I can't
vouch it works for all of them ;)

#+BEGIN_SRC emacs-lisp
(defun helm-agenda-candidates (query)
  (let ((results '()))
(mapc (lambda (f)
  (with-current-buffer (find-file-noselect f)
(org-map-entries
 (lambda ()
   (add-to-list 'results
(cons
 (concat
  (file-name-nondirectory f) " | "
  (make-string (nth 1 (org-heading-components)) ?*)
  " "
  (org-get-heading))
 (point-marker
 query))) (org-agenda-files))
results))


(defun helm-query-agenda (query)
  "Helm interface to headlines with TODO status in current buffer."
  (interactive "sQuery: ")
  (let ((candidates (helm-agenda-candidates query)))
(helm :sources '(((name . "TODO headlines")
  (candidates . candidates)
  (action . (("open" . (lambda (m)
 (switch-to-buffer (marker-buffer 
m))
 (goto-char m)
 (show-children))
#+END_SRC


Simon Thum writes:

> Hi John,
>
> thank you for the fast response! That's more than I had hoped for, I'm
> sure I'll get through now. I'll report back when something tangible is
> there.
>
> Cheers,
>
> Simon
>
> On 01/19/2015 04:57 PM, John Kitchin wrote:
>> You can do something like this to get just the TODO headlines in the
>> current buffer. If you make the helm-todo-candidates map over all the
>> files in (org-agenda-files) you can make it give all the TODO
>> headings. You can change the match criteria in org-map-entries to be
>> more selective.
>>
>> #+BEGIN_SRC emacs-lisp :results raw
>> (defun helm-todo-candidates ()
>>(let ((results '()))
>>  (org-map-entries
>>   (lambda ()
>> (add-to-list 'results
>>  (cons
>>   (concat (make-string (nth 1 (org-heading-components)) 
>> ?*)
>>   " TODO "
>>   (nth 4 (org-heading-components)))
>>   (point-marker
>>   "TODO=\"TODO\"")
>>  results))
>> #+END_SRC
>>
>> #+RESULTS:
>> ((** post it . #) (** work it out . #> 941 in blog.org>))
>>
>> Now to run helm, there is a subtle point. We need to map the current buffer 
>> /before/ running helm, otherwise we will map an empty helm buffer.
>>
>> #+BEGIN_SRC emacs-lisp
>> (defun helm-todo ()
>>"Helm interface to headlines with TODO status in current buffer."
>>(interactive)
>>(let ((candidates (helm-todo-candidates)))
>>  (setq helm-todo-source '((name . "TODO headlines")
>>   (candidates . candidates)
>>   (action . (("open" . goto-char)
>>  (helm :sources '(helm-todo-source
>>
>> (helm-todo)
>> Simon Thum writes:
>>
>>> Hi all,
>>>
>>> I recently updated my helm install so it includes
>>> helm-org-agenda-headings which is just AWESOME (to me at least). A bit
>>> like org-goto but across all agenda files at once, with goto, refile,
>>> linking built in. If you haven't tried it, I definitely recommend to do so.
>>>
>>>
>>> Yet I'm missing a few things so far, I would like to have different
>>> datasources differentiated by tags, in particular the ARCHIVE tag, and
>>> the infamous FILETAGS so I cannot just regex my way through as the
>>> current approach does.
>>>
>>> This requires making more use of org-ode when filling helm's buffers. My
>>> elisp isn't great but I might be able to get there if the approach is sane.
>>>
>>> Any pointers are welcome! If you might help me please read on.
>>>
>>> I would like to ask what would be the best approach for better utilising
>>> org infrastructure so I may have separate helm sources for
>>> live/archived, private/work, the clocking history, stuff like that.
>>>
>>> The helm-org definition looks deceptively simple:
>>>
>>> https://github.com/emacs-helm/helm/blob/master/helm-org.el
>>>
>>> (defun helm-org-agenda-files-headings ()
>>> (interactive)
>>> (helm :sources (helm-source-org-headings-for-files (org-agenda-files))
>>> :candidate-number-limit 9
>>> :buffer "*helm org headings*"))
>>>
>>>
>>> FWICT, in effect helm-org is chewing itself through the buffers:
>>>
>>> (defun helm-get-org-candidates-in-file (filename min-depth max-depth
>>> &optional fontify)
>>> (with-current-buffer (find-file-noselect filename)
>>> (and fontify (jit-lock-fontify-now))
>>> (let ((match-fn (if fontify 'match-string 'match-string-no-properties)))
>>> (save-excursion
>>> (goto-char (p

Re: [O] More helm awesomeness

2015-01-19 Thread Simon Thum

Hi John,

thank you for the fast response! That's more than I had hoped for, I'm 
sure I'll get through now. I'll report back when something tangible is 
there.


Cheers,

Simon

On 01/19/2015 04:57 PM, John Kitchin wrote:

You can do something like this to get just the TODO headlines in the
current buffer. If you make the helm-todo-candidates map over all the
files in (org-agenda-files) you can make it give all the TODO
headings. You can change the match criteria in org-map-entries to be
more selective.

#+BEGIN_SRC emacs-lisp :results raw
(defun helm-todo-candidates ()
   (let ((results '()))
 (org-map-entries
  (lambda ()
(add-to-list 'results
 (cons
  (concat (make-string (nth 1 (org-heading-components)) ?*)
  " TODO "
  (nth 4 (org-heading-components)))
  (point-marker
  "TODO=\"TODO\"")
 results))
#+END_SRC

#+RESULTS:
((** post it . #) (** work it out . #))

Now to run helm, there is a subtle point. We need to map the current buffer 
/before/ running helm, otherwise we will map an empty helm buffer.

#+BEGIN_SRC emacs-lisp
(defun helm-todo ()
   "Helm interface to headlines with TODO status in current buffer."
   (interactive)
   (let ((candidates (helm-todo-candidates)))
 (setq helm-todo-source '((name . "TODO headlines")
  (candidates . candidates)
  (action . (("open" . goto-char)
 (helm :sources '(helm-todo-source

(helm-todo)
Simon Thum writes:


Hi all,

I recently updated my helm install so it includes
helm-org-agenda-headings which is just AWESOME (to me at least). A bit
like org-goto but across all agenda files at once, with goto, refile,
linking built in. If you haven't tried it, I definitely recommend to do so.


Yet I'm missing a few things so far, I would like to have different
datasources differentiated by tags, in particular the ARCHIVE tag, and
the infamous FILETAGS so I cannot just regex my way through as the
current approach does.

This requires making more use of org-ode when filling helm's buffers. My
elisp isn't great but I might be able to get there if the approach is sane.

Any pointers are welcome! If you might help me please read on.

I would like to ask what would be the best approach for better utilising
org infrastructure so I may have separate helm sources for
live/archived, private/work, the clocking history, stuff like that.

The helm-org definition looks deceptively simple:

https://github.com/emacs-helm/helm/blob/master/helm-org.el

(defun helm-org-agenda-files-headings ()
(interactive)
(helm :sources (helm-source-org-headings-for-files (org-agenda-files))
:candidate-number-limit 9
:buffer "*helm org headings*"))


FWICT, in effect helm-org is chewing itself through the buffers:

(defun helm-get-org-candidates-in-file (filename min-depth max-depth
&optional fontify)
(with-current-buffer (find-file-noselect filename)
(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)))

I don't really get what it does but I have a hunch that org-element or
other org-mode functions could be used to achieve the same with more
precision. That's what I would need to do. FWIW I'd be happy to take a
performance hit.

Thanks in advance,

Simon


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu





Re: [O] More helm awesomeness

2015-01-19 Thread John Kitchin
You can do something like this to get just the TODO headlines in the
current buffer. If you make the helm-todo-candidates map over all the
files in (org-agenda-files) you can make it give all the TODO
headings. You can change the match criteria in org-map-entries to be
more selective.

#+BEGIN_SRC emacs-lisp :results raw
(defun helm-todo-candidates ()
  (let ((results '()))
(org-map-entries
 (lambda ()
   (add-to-list 'results
(cons
 (concat (make-string (nth 1 (org-heading-components)) ?*)
 " TODO "
 (nth 4 (org-heading-components)))
 (point-marker
 "TODO=\"TODO\"")
results))
#+END_SRC

#+RESULTS:
((** post it . #) (** work it out . #))

Now to run helm, there is a subtle point. We need to map the current buffer 
/before/ running helm, otherwise we will map an empty helm buffer.

#+BEGIN_SRC emacs-lisp
(defun helm-todo ()
  "Helm interface to headlines with TODO status in current buffer."
  (interactive)
  (let ((candidates (helm-todo-candidates)))
(setq helm-todo-source '((name . "TODO headlines")
 (candidates . candidates)
 (action . (("open" . goto-char)
(helm :sources '(helm-todo-source

(helm-todo)
Simon Thum writes:

> Hi all,
>
> I recently updated my helm install so it includes
> helm-org-agenda-headings which is just AWESOME (to me at least). A bit
> like org-goto but across all agenda files at once, with goto, refile,
> linking built in. If you haven't tried it, I definitely recommend to do so.
>
>
> Yet I'm missing a few things so far, I would like to have different
> datasources differentiated by tags, in particular the ARCHIVE tag, and
> the infamous FILETAGS so I cannot just regex my way through as the
> current approach does.
>
> This requires making more use of org-ode when filling helm's buffers. My
> elisp isn't great but I might be able to get there if the approach is sane.
>
> Any pointers are welcome! If you might help me please read on.
>
> I would like to ask what would be the best approach for better utilising
> org infrastructure so I may have separate helm sources for
> live/archived, private/work, the clocking history, stuff like that.
>
> The helm-org definition looks deceptively simple:
>
> https://github.com/emacs-helm/helm/blob/master/helm-org.el
>
> (defun helm-org-agenda-files-headings ()
> (interactive)
> (helm :sources (helm-source-org-headings-for-files (org-agenda-files))
> :candidate-number-limit 9
> :buffer "*helm org headings*"))
>
>
> FWICT, in effect helm-org is chewing itself through the buffers:
>
> (defun helm-get-org-candidates-in-file (filename min-depth max-depth
> &optional fontify)
> (with-current-buffer (find-file-noselect filename)
> (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)))
>
> I don't really get what it does but I have a hunch that org-element or
> other org-mode functions could be used to achieve the same with more
> precision. That's what I would need to do. FWIW I'd be happy to take a
> performance hit.
>
> Thanks in advance,
>
> Simon

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



[O] More helm awesomeness

2015-01-18 Thread Simon Thum

Hi all,

I recently updated my helm install so it includes 
helm-org-agenda-headings which is just AWESOME (to me at least). A bit 
like org-goto but across all agenda files at once, with goto, refile, 
linking built in. If you haven't tried it, I definitely recommend to do so.



Yet I'm missing a few things so far, I would like to have different 
datasources differentiated by tags, in particular the ARCHIVE tag, and 
the infamous FILETAGS so I cannot just regex my way through as the 
current approach does.


This requires making more use of org-ode when filling helm's buffers. My 
elisp isn't great but I might be able to get there if the approach is sane.


Any pointers are welcome! If you might help me please read on.

I would like to ask what would be the best approach for better utilising 
org infrastructure so I may have separate helm sources for 
live/archived, private/work, the clocking history, stuff like that.


The helm-org definition looks deceptively simple:

https://github.com/emacs-helm/helm/blob/master/helm-org.el

(defun helm-org-agenda-files-headings ()
(interactive)
(helm :sources (helm-source-org-headings-for-files (org-agenda-files))
:candidate-number-limit 9
:buffer "*helm org headings*"))


FWICT, in effect helm-org is chewing itself through the buffers:

(defun helm-get-org-candidates-in-file (filename min-depth max-depth
&optional fontify)
(with-current-buffer (find-file-noselect filename)
(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)))

I don't really get what it does but I have a hunch that org-element or 
other org-mode functions could be used to achieve the same with more 
precision. That's what I would need to do. FWIW I'd be happy to take a 
performance hit.


Thanks in advance,

Simon