onilog

posts tagged "org-mode"

Some quick git diff tips

11 August 2013 0:54 AM (git | org-mode | diff | tips | magit | emacs | lisp | hy | elisp)

A couple of quick tips. As you possibly know you can specify some options to be used for diffs (and other things) per file type. The one I'm interested in is the function name.

For org-mode

The primary way of identifying which part of an org-mode document a change occurs in seems to me to be the heading. So, in your $HOME/.gitconfig put:

[diff "org"]
      xfuncname = "^\\*+.*"

Which should show any lines starting with one or more * characters. And then in $XDG_CONFIG_HOME/git/attributes or $HOME/.config/git/attributes put:

*.org   diff=org

For lisp and lisp-like langauges

For anything that resembles lisp (so Common Lisp, Emacs Lisp, Hy, scheme, etc.) I would think that the easiest thing to do is just see the closes top-level form. So, in your $HOME/.gitconfig put:

[diff "lisp"]
      xfuncname = "^\\([^ ]+ [^ ]+"

Which should show the opening parenthesis and the first two words. For example:

(defun some-function-name
(defclass my-awesome-class
(define-route this-strange-route

And then put in your $XDG_CONFIG_HOME/git/attributes or $HOME/.config/git/attributes:

*.lisp  diff=lisp
*.el    diff=lisp
*.hy    diff=lisp
*.scm   diff=lisp

And possibly any other lisp-like language files you can think of.

Org examples on github

20 January 2013 2:09 PM (github | org-mode | emacs)

github has an org-mode parser for their README files, but I always thought it didn't handle #+BEGIN_SRC and #+BEGIN_EXAMPLE style blocks. And I'm not wrong, but it does handle : blocks.

So this won't work:

#+BEGIN_EXAMPLE
  This is an example
#+END_EXAMPLE

But this will:

: This is an example

That was a nice surprise for me, because I prefer org-mode for almost all of my documents.

Different roles

10 January 2013 3:49 AM (org-mode | emacs | todo)

The other day I noticed that when I'm working I find it very annoying to have tasks for my personal projects appear in either my agenda or my todo list, so I was thinking if I couldn't make it somewhat more flexible.

First I've added some separation between my org files, I've split them into personal-org-agenda-files, work-org-agenda-files and common-org-agenda-files, since there are also some tasks that I would like to know about in either situation.

(defvar oni:personal-agenda-files
  (list (expand-file-name "~/documents/org/tasks"))
  "My personal agenda, should only show up at times I don't have
  to work.")

(defvar oni:work-agenda-files
  (list (expand-file-name "~/documents/org/work"))
  "My work agenda, should only show up at times I work.")

(defvar oni:common-agenda-files
  (list (expand-file-name "~/documents/org/misc"))
  "Agenda files that are work-agnostic, should always show up.")

At first I only seperated them with org-agenda-custom-commands:

(setq org-agenda-custom-commands
      '(("P" . "Personal only")
        ("Pa" "Personal agenda" agenda ""
         ((org-agenda-files (append oni:personal-agenda-files
                                    oni:common-agenda-files))))
        ("Pt" "Personal todo" agenda ""
         ((org-agenda-files (append oni:personal-agenda-files
                                    oni:common-agenda-files))))
        ("W" . "Work only")
        ("Wa" "Work agenda" agenda ""
         ((org-agenda-files (append oni:work-agenda-files
                                    oni:common-agenda-files))))
        ("Wt" "Work todo" todo ""
         ((org-agenda-files (append oni:work-agenda-files
                                    oni:common-agenda-files))))))

But it's clunky to have to use a separate command just to see a clean todo list. Then I thought, and tried, to have a function that checks the time to see which it should use, since I work from 09:00 to 17:00, if the current time is between those times I should only look at my work todo list, most of the time, outside of those hours I don't really care what I have to do for work.

(defun oni:set-org-agenda-files ()
  (interactive)
  (let ((current-time (current-time-string))
        (start-time (format-time-string "%a %b %e 09:00:00 %Y"))
        (end-time (format-time-string "%a %b %e 17:00:00 %Y")))
    (if (or (and (string< current-time start-time)
                 (string< current-time end-time))
            (and (string< start-time current-time)
                 (string< end-time current-time)))
        (setq org-agenda-files
              (append oni:personal-agenda-files
                      oni:common-agenda-files))
      (setq org-agenda-files
            (append oni:work-agenda-files
                    oni:common-agenda-files)))))

It's weird, but since Emacs doesn't have any real datetime functions for creation/comparison, for as far as I know, it seemed easiest to just create some strings representing the time and compare these.

Then it should be, if the current time is either before both start and end time or after both start and end time it should return my personal todo list, otherwise it should return my work todo list.

Now, it would be silly to have to call that manually every so-often, so I've set it up to do so automatically.

(oni:set-org-agenda-files)
(run-at-time "09:01" nil 'oni:set-org-agenda-files)
(run-at-time "17:01" nil 'oni:set-org-agenda-files)

First, I set my agenda files to whatevers they should be right now. Then I have this function run at 09:01 and 17:01, if either or both have already passed, they won't be executed today. This effectively tells Emacs to switch to my work "role" after 09:00 and back to my personal "role" after 17:00.

It's not perfect yet, but I felt like writing something. The things I would change might include:

  • Check the times for either < or = the start/end times, so I don't
    have to check for :01 every time, but Emacs doesn't have a string<=
    function so I'll have to mimic it.

  • Always set it to my personal "role" during weekends.

  • Have them repeat every 24 hours, just in case I don't turn off my
    PC for a few days.

I'll fix those soon, they're not hard to do, but this works for now. It has worked well for me today, but I might throw it out again tomorrow, as I sometimes tend to do.

org-agenda-prefix-format

4 December 2012 1:33 AM (emacs | org-mode | config)

I've been looking for a way to clearly identify my projects from within an org-mode agenda todo buffer, and a little while ago I finally came across a nice way to do this: org-agenda-prefix-format.

The problems with other options I could think of were that the category just doesn't feel like the right place to put it, that should be an indication of what kind of todo item it is, not what it's for. Tags get messy very quickly and separate files are shown when no category has been given and using a lot of files can slow list generation down.

Setting it to a value like, for example:

((agenda . " %i %-12:c%?-12t% s")
 (timeline . "  % s")
 (todo .
  " %i %-12:c %(concat \"[ \"(org-format-outline-path (org-get-outline-path)) \" ]\") ")
 (tags .
  " %i %-12:c %(concat \"[ \"(org-format-outline-path (org-get-outline-path)) \" ]\") ")
 (search . " %i %-12:c"))

Will give me lines like:

task:        [ Blog ] TODO Blog about something
task:        [ Blog ] TODO Blog about something else

Where task is the category, Blog is the project, which is defined by being its one and only parent, and TODO is, of course, its todo state. The rest being the headline for the task.

Of course, with these settings you need to have exactly 2 levels of tasks, otherwise, I think, you'll get [ Blog/heading ], which might also be useful, but will grow big quickly.

I also only use this setting with todo and tags, because I don't usually need it for the items that show up in agenda and I don't really use timeline or search too much, but have a look at the documentation for org-agenda-prefix-format, you might think of something to do with it.

Guess what's back

3 October 2012 10:24 PM (org-mode | tekuti | meta | emacs | elisp | coding | blogging)

A while ago I wrote a couple of functions in GNU Emacs to help me with blogging using tekuti. I don't know how, but I somehow accidentally deleted the file these functions were in and didn't have the energy to retrieve it.

Today I wanted to blog a little again and so I rewrote the functions from last time, but this time hopefully a little better. I'm now fully dependent on org-mode and use its comment/property syntax to manage tekuti's metadata.

I've already put it in a temporary spot for safe keeping, I'll move it somewhere else when I have a little more of it.

The functions I'll still want to add include:

  • Editing the posts I've written in org, showing the options I used
    for them in the usual way.

  • Automatic committing, this shouldn't be too hard since I've also
    written an emacs minor mode that does this.

  • Easy saving, listing and continuing of drafts, right now I'm just
    placing org files in my $HOME directory.

And anything else that I can come up with later.

New config project

28 June 2012 9:28 PM (org-mode | literate programming | config | project)

After reading that it was very easy to use Literate Programming for one's emacs init file and discovering that it's also a lot of fun to do, I was thinking that I could easily use this for all my configuration files.

Of course, not all programs have org-babel, so they can't all have something like this in their init file:

(require 'org)
(require 'ob-tangle)

(org-babel-load-file "~/.emacs.d/rinit.org")

Which, for emacs, tangles (extracts the code) and then loads the generated file. So something else has to be done.

On the other side of things, I, fairly recently, had a run-in with some Makefiles, which got me thinking that make is a very interesting tool and that it could be used to help with a lot of other tasks as well, much like I perceive Rake does. I just wasn't able to find where exactly it would fit (other than, of course, as compilation instructions for my projects).

Now, yesterday I got the idea of using org-mode to literate-program all my configuration files and then use make to tangle and install them. This would mean that I could easily keep documentation about decisions in configuration files and such in an easy to read format, easily export these files to somewhere on the web and practice my make skills to make everything easy.

Here is the result. I'm still working on it, as you can see my emacs init file still has a long way to go, my focus is on getting it in org-mode first and actually get it well-documented later. I've published it here, what I have at least, in case you would like to read about my mostly uninteresting configuration files.

Literate Emacs init

9 June 2012 1:19 AM (emacs | literate programming | org-mode)

A little while back I saw Sacha Chua mention using org-mode for literate programming. I'd heard of literate programming, but its use escaped me. Still, reading that and looking at what noweb is I started thinking that it would indeed be a great way of documenting code, especially something like my emacs init file, since that is not a serious software project and some weird stuff goes on in there.

I still didn't really get the hang of it. It seemed like a lot of work to get into it and how exactly it fit together with using org-mode didn't really hit me so I pushed it aside for the moment.

Today I see her presenting her new literately programmed init file with some links to other resources and I just had to try it too.

I haven't gotten very far yet, but what I have so far I have put here. It's just the generated HTML file, no org source, and I'm still messing around with the colors and stuff, but it's fun to see the result already.

I don't know if I'm actually going to use it, since my init file's sloc count is 1038 and its total line count is 1280 lines I fear that adding even more documentation (= lines) would make my init file very bulky. It is still fun to see and experiment with, though.

Another way to get a selection

3 May 2012 10:04 AM (emacs | elisp | org-mode | coding)

When I was first looking into improving my mailbox selection function I was looking at how to just ask the user for input with completions. Though now that I came across tmm-prompt I really prefer this way of working, at least in this case.

However, today another function was mentioned, in response to someone pointing out org-completing-read: completing-read. Wow that's a far leap.

Anyway:

(completing-read "Your favorite color: "
                 '("red" "green" "blue" "yellow"))

This will ask for user input and provide these options as completions, but it won't show a list of options, of provide shortcuts, like tmm-prompt does.

It's good to know these things, and I really should read both the emacs manual and the emacs lisp reference manual at some point.