Re: [O] Go to heading using LISP

2013-06-19 Thread Alexander Wingård
On Mon, Jun 10, 2013 at 11:14 PM, Alexander Wingård 
alexander.wing...@gmail.com wrote:


 Maybe some day I will learn some LISP and teach it to navigate the
 hierarchical structure.


I actually got curious and gave this a try and here's what I came up with:
test.org:
* a
** b
*** h
** b
*** q
 h
** c
*** d

Elisp:
(defun goto-notes ()
  (interactive)
  (find-file ~/test.org)
  (org-goto-subtree '(a b q h))
  (org-show-context)
  (org-show-entry)
  (show-children))

(defun org-goto-subtree (path)
  (let ((level 1))
(org-element-map
(org-element-parse-buffer 'headline)
'headline
(lambda (x)
  (if ( (org-element-property :level x) level)
  (setq level (org-element-property :level x)))
  (if (and (= level (org-element-property :level x))
   (string= (nth (- level 1) path) (org-element-property
:raw-value x)))
  (progn (setq level (+ level 1))
 (if ( level (list-length path))
 (goto-char (org-element-property :begin x))
nil t)))

https://gist.github.com/AlexanderWingard/5814843

My very first attempt at programming Elisp so any feedback is appreciated.

Best regards
Alexander


Re: [O] Go to heading using LISP

2013-06-10 Thread Alexander Wingård

On 10 jun 2013, at 21:00, Myles English mylesengl...@gmail.com wrote:

 
 Hi Alexander,
 
 Alexander Wingård writes:
 
 I want to create special key-bindings that use the org-refile goto
 interface to jump to specific headings.
 
 It doesn't use org-refile but this is what I use:
 
 (defun my-goto-heading(file heading-text)
  Visit file `file' and goto headline `heading-text'
  (find-file file)
  (org-element-map (org-element-parse-buffer 'headline) 'headline
  (lambda (x)
  (if (string= (org-element-property :raw-value x) heading-text)
  (goto-char (org-element-property :begin x))
  nil))
   nil t)) ;; stop at first find
 

Thanks alot! This is exactly what I was asking for. This will suffice for me 
now.
Maybe some day I will learn some LISP and teach it to navigate the hierarchical 
structure.

Best Regards /Alexander


Re: [O] Go to heading using LISP

2013-06-09 Thread Alexander Wingård
Eric Abrahamsen eric at ericabrahamsen.net writes:

 
 Alexander Wingård alexander.wingard at gmail.com writes:
 
  Hi!
 
  I want to create special key-bindings that use the org-refile goto
  interface to jump to specific headings.
More specific example, let's say I want to bind keys in my .emacs file:

C-c b - find gtd.org and jump to Projects/Work/Bugs
C-c m - find gtd.org and jump to Projects/Work/Meetings
 
  My initial attempt was:
  (org-refile 4 gtd.org Projects/Work/Bugs)
 
  But it seems specifying RFLOC is not that simple.
 
  Someone have any idea how to achieve this or another way to jump to a
  heading?
 
 Is the `org-goto' interface close enough? It only does the current
 buffer, but you can set org-goto-interface to make it behave a fair bit
 like refile...
I've looked at that function aswell but it seems even harder to achieve 
what I want with: Call it from lisp without any user interaction. If you think
that is possible I would love an example.
 
 Yours
 Eric
 
 





[O] Go to heading using LISP

2013-06-08 Thread Alexander Wingård
Hi!

I want to create special key-bindings that use the org-refile goto
interface to jump to specific headings.

My initial attempt was:
(org-refile 4 gtd.org Projects/Work/Bugs)

But it seems specifying RFLOC is not that simple.

Someone have any idea how to achieve this or another way to jump to a
heading?

Best Regards /Alexander


[O] Time range between now and timestamp

2011-09-15 Thread Alexander Wingård
Hi!

I really would want to have a command that given the cursor is over a timestamp 
would output the time-range from the current time to that timestamp.

I've been searching a lot for this but no luck and I even did an attempt to 
implement some hacked version of org-evaluate-time-range and org-days-to-time 
but since my experience with lisp is absolutely zero I failed miserably.

I imagine someone here could help me whip this up in a couple of lines or maybe 
such feature can already be achieved?

Best Regards /Alexander

Ps. I love org-mode


Re: [O] Time range between now and timestamp

2011-09-15 Thread Alexander Wingård
Let's say I have this:

2011-09-15 Thu--2011-09-16 Fri

and I put my cursor over this and press C-c C-y my minibuffer will
spit out 1 day.

I would like a command that does the same thing if i execute it over
just 2011-09-16 Fri.

Sometimes I'm interested in how much time there is left to a specific
appointment.

Best Regards /Alexander

On Thu, Sep 15, 2011 at 4:37 PM, Nick Dokos nicholas.do...@hp.com wrote:
 Alexander Wingård alexander.wing...@gmail.com wrote:

 Hi!

 I really would want to have a command that given the cursor is over a
 timestamp would output the time-range from the current time to that
 timestamp.


 Can you please provide an example? I can interpret this
 in a couple of different ways and I'm not sure what you
 want.

 Also, when you say output, do you mean that the function
 should return e.g. a string representation of whatever it is
 you want? Or print the result in the minibuffer?
 Or insert it in the buffer you are editing? (and, if the last,
 where?)

 Nick




Re: [O] Time range between now and timestamp

2011-09-15 Thread Alexander Wingård
Wonderful, thanks alot!

I can already see this becoming of great use to me.

Best Regards /Alexander

On Thu, Sep 15, 2011 at 6:02 PM, Nick Dokos nicholas.do...@hp.com wrote:
 Alexander Wingård alexander.wing...@gmail.com wrote:

 Let's say I have this:

 2011-09-15 Thu--2011-09-16 Fri

 and I put my cursor over this and press C-c C-y my minibuffer will
 spit out 1 day.

 I would like a command that does the same thing if i execute it over
 just 2011-09-16 Fri.

 Sometimes I'm interested in how much time there is left to a specific
 appointment.


 Here is one way to do it:

 --8---cut here---start-8---
 (defun aw/org-evaluate-time-range (optional to-buffer)
  (interactive)
  (if (org-at-date-range-p t)
      (org-evaluate-time-range to-buffer)
    ;; otherwise, make a time range in a temp buffer and run o-e-t-r there
    (let ((headline (buffer-substring (point-at-bol) (point-at-eol
      (with-temp-buffer
        (insert headline)
        (goto-char (point-at-bol))
        (re-search-forward org-ts-regexp (point-at-eol) t)
        (if (not (org-at-timestamp-p t))
            (error No timestamp here))
        (goto-char (match-beginning 0))
        (org-insert-time-stamp (current-time) nil nil)
        (insert --)
        (org-evaluate-time-range to-buffer)
 --8---cut here---end---8---

 There are probably better implementations; also, you might be able to advise
 o-e-t-r, instead of writing a new function, which would have the advantage
 of preserving the key binding.

 AFAICT, the above works with dates in the past as well, but it always gives
 the absolute value of the difference.

 Nick


 On Thu, Sep 15, 2011 at 4:37 PM, Nick Dokos nicholas.do...@hp.com wrote:
  Alexander Wingård alexander.wing...@gmail.com wrote:
 
  Hi!
 
  I really would want to have a command that given the cursor is over a
  timestamp would output the time-range from the current time to that
  timestamp.
 
 
  Can you please provide an example? I can interpret this
  in a couple of different ways and I'm not sure what you
  want.
 
  Also, when you say output, do you mean that the function
  should return e.g. a string representation of whatever it is
  you want? Or print the result in the minibuffer?
  Or insert it in the buffer you are editing? (and, if the last,
  where?)
 
  Nick