me, thinking out loud…

Posts tagged ‘emacs’

Some fun from #org-mode

2010-10-02 Sat 20:26

This is a conversation from #org-mode, published without permission from plovs, BerntH and bremner. If any of you want any of the content removed, I will do so.

<punchagan> hi all

<BerntH> hi punchagan [18:36]

<punchagan> BerntH: ever used/tried blorg or blorgit? [18:47]

<punchagan> I like the way org-publish works, but blorg exports one org file as a blog. If blorg were to be re-written on top of org-publish, how should it be done? use one file per post or just one file for the whole blog? [18:52]

<bremner> punchagan: another option is to use ikiwiki and use the org-mode plugin to render pages. This is what i do, although only a bit of the site is in org. [19:44]

<punchagan> bremner: can I have a look at your site? [19:45]

<bremner> sure, it ain’t pretty, but: http://www.cs.unb.ca/~bremner [19:46]

<punchagan> thanks. I’ll keep this in mind. [19:47]

<punchagan> I just loved the way this site looks and behaves – http://julien.danjou.info/projects.html

<bremner> well, the side bar at least is possible with ikiwiki. Other than that I suppose it is mainly a matter of css [19:48]

<BerntH> punchagan: nope [19:49]

<punchagan> ok BerntH [19:50]

<plovs> punchagan ikiwiki does have an org-mode plugin [19:56]

<punchagan> plovs: yes, bremner told me that and I’ve seen on Worg too. :)

<plovs> punchagan ah, yes, sorry

<punchagan> plovs: it’s alright. [19:59]

<plovs> punchagan another possibility is org2blog, which uses wordpress

<punchagan> plovs: I’m the author of it. :D

<plovs> lol, ik, that punchagan [20:17]

<punchagan> lol

<punchagan> plovs: were you kidding? or serious? [20:19]

<plovs> punchagan sorry to say i was serious, but it will not happen again :-)

<plovs> i really like org2blog, played with it yesterday

<punchagan> plovs: no. I was just wondering if you were playing around with me. :P

<punchagan> I’m happy some one thinks it is useful.

<plovs> lol, no, i just didn’t recognized your name, although it is kind of hard to miss [20:21]

<punchagan> I hope you don’t mind, if I make this anecdote public?

Advertisements

A couple of counting functions

I had a strict character limit of 180 chars for something I was writing. I just wrote a simple function to count characters in a region or a buffer. Another function to count the words.

(defun count-chars ()
  "Count the number of chars in a buffer or region."
  (interactive)
  (let* ((beg (if (region-active-p) (region-beginning) (point-min)))
         (end (if (region-active-p) (region-end) (point-max))))
         (message (number-to-string (- end beg)))))
(defun count-words ()
  "Count the number of words in a buffer or region."
  (interactive)
  (let* ((beg (if (region-active-p) (region-beginning) (point-min)))
         (end (if (region-active-p) (region-end) (point-max)))
         (count 0))
    (save-excursion
      (goto-char beg)
      (while (< (point) end)
        (forward-word)
        (setq count (1+ count))))
    (message (int-to-string count))))

Advice – Programming in Elisp

2010-08-06 Fri 14:37

Below is a mail sent by Eric Schulte to the org-mode mailing list answering a query on how to write elisp for org-mode. I am reproducing it here, since it is useful advice for me. The actual thread is here.


The way that I learned how to program in emacs lisp was mainly using two commands `elisp-index-search’ bound to `C-h e’ on my system, and most importantly `describe-function’ bound to `C-h f’. With `describe-function’ you can look at the source code of functions whose behavior you are familiar with, you can then copy portions of the code to your scratch buffer where they can be edited and evaluated with `eval-defun’ bound to `C-M-x’. Now with Babel, instead of doing this in the scratch buffer you could do this in emacs-lisp code blocks in an org file, enabling notes and hierarchical organization – it can be nice to have your noodling all collected in one file for later reference.

If you are going to do any serious work with lisp, I would emphatically recommend using paredit-mode, and becoming friends with the Sexp movement functions

C-M-f runs the command paredit-forward C-M-b runs the command paredit-backward C-M-u runs the command backward-up-list C-M-k runs the command kill-sexp C-y runs the command yank

They allow you to manipulate lisp code on the level of logical expressions, the utility of which can not be over stated.

As for working with Org-mode in particular, I’d recommend looking at the documentation and source-code of Org-mode functions with `describe-function’, and then looking for how these functions are actually used in the Org-mode code base with `rgrep’.

For a more structured learning experience, I’ve heard very good things about http://www.gnu.org/software/emacs/emacs-lisp-intro/, although I haven’t used it myself.

Hope this helps. Happy Hacking – Eric


Refile to date-tree

Useful to refile notes to the journal file, which is a date-tree. org-refile isn’t convenient to refile stuff to a date-tree.

(defun my/org-refile-to-journal ()
  "Refile an entry to journal file's date-tree"
  (interactive)
  (require 'org-datetree)
  (let ((journal "/data/life-in-plain-text/journal.org")
        post-date)
    (setq post-date (or (org-entry-get (point) "TIMESTAMP_IA")
                        (org-entry-get (point) "TIMESTAMP")))
    (setq post-date (nthcdr 3 (parse-time-string post-date)))
    (setq post-date (list (cadr post-date) 
                          (car post-date) 
                          (caddr post-date)))
    (org-cut-subtree)
    (with-current-buffer (or (find-buffer-visiting journal)
                             (find-file-noselect file))
      (save-excursion
        (org-datetree-file-entry-under (current-kill 0) post-date)
        (bookmark-set "org-refile-last-stored")))
    (message "Refiled to %s" journal)))

(defun my/org-agenda-refile-to-journal ()
  "Refile the item at point to journal."
  (interactive)
  (let* ((marker (or (org-get-at-bol 'org-hd-marker)
                     (org-agenda-error)))
         (buffer (marker-buffer marker))
         (pos (marker-position marker)))
    (with-current-buffer buffer
      (save-excursion
        (save-restriction
          (widen)
          (goto-char marker)
          (org-remove-subtree-entries-from-agenda)
          (my/org-refile-to-journal)))))
  (org-agenda-redo))

(org-defkey org-agenda-mode-map (kbd "C-c C-S-w") 'my/org-agenda-refile-to-journal)
(org-defkey org-mode-map (kbd "C-c C-S-w") 'my/org-refile-to-journal)

Vimperator and Firemacs!

For the uninitiated, vimperator is an emacs plugin to get Firefox working with vim keybindings and firemacs1 is for emacs keybindings.

I’m obsessed with emacs (as should already be evident) and can’t really edit text without it’s key-bindings. There are others like me, and hence the firemacs plugin. It’s a blessing for my tribe.

Firemacs is great, except for the one great feature that it lacks – being able to jump to links/textareas without using the mouse. I’ve seen Nishanth do it with ease, using Vimperator. I wanted to add this feature to Firemacs, by copying some code from Vimperator to Firemacs. I directly started looking at the code, but couldn’t make head or tail of it. I got a few doubts about how Vimperator works, since I’d never used it. Nishanth asked me to simply install it and try it out.

And then we had our EUREKA! moment. Vimperator and Emacs both enabled together work seamlessly well. Two obsessed people are happy and satisfied! And hopefully many more. :D

Footnotes:

1 Key-bindings are a religious thing, in the world of editors!

Weblogger.el configured!

If you see this post, it means weblogger has been successfully configured in emacs.
Emacs Rocks. \m/

UPDATE [2010-09-02]: I now use org2blog, a small extension to emacs orgmode to post to my blog.

Mid-Term ‘Psycho’Analysis

Its been 10 days on my sabbatical[1][2]. I have done reasonably well during the first week, but now its getting on my nerves. I have realized how addicted I am to chat, IRC and the Internet. I have to soon find some remedies for this.
Well, here is the first step. I approached ELIZA[3] (or Doctor Fill, that’s actually the emacs mode) , the Emacs Psychotherapist to help me. An enjoyable chat this one! ;)
ELIZA (Doctor Fill) abbreviated as DF (pun intended, for those who get it)

DF: I am the psychotherapist. Please, describe your problems. Each time
you are finished talking, type RET twice.

Hi. Nice meeting you.

DF: How do you do? What brings you to see me?

(more…)

Tag Cloud

%d bloggers like this: