[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[emacs-wiki-discuss] Some planner.el convenience hacks.
From: |
Joe Steeve |
Subject: |
[emacs-wiki-discuss] Some planner.el convenience hacks. |
Date: |
Thu, 14 Apr 2005 15:02:42 +0530 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Well, I'm not a elisp programmer. I recently decided to write some
code for some convenience features that I wanted. I've included
the code and some little comments on how to use the code., but
please make sure it does not affect anything else. I'm using this
on a relatively old emacs-wiki+planner code (some release from
February). So I've no guarantee of the code. Make use of it if it
fits your purpose. Sometime I've to properly document these and
put it on my webpage. Check my homepage http://joe.bsdnerds.org/
to see how these hacks are implemented there. :)
Sorry this is going to be a real loooooong mail. :)
1. I did not like the planner-notes-index generating complete
links to the notes. The problem is that, there is no link to
the plan-page from the notes-index. I dont know whether it is
intentional to be like this. I kinda did not like it., so I
wrote the following. I actually took the original
planner-notes-index-insert-as-list function and modified it.
(defun joe-planner-notes-index-insert-as-list (page-headlines &optional
limit prefix suffix)
"This is a replacement for planner-notes-index-insert-as-list. This
does some cleaner formatting"
(when (and limit (stringp limit)) (setq limit (string-to-number limit)))
(let ((page (car page-headlines)))
(setq page-headlines (cdr page-headlines))
(while (and page-headlines (if limit (> limit 0) t))
(when prefix (insert prefix))
(insert (concat
(cdr (car page-headlines))
(concat "(" page (caar page-headlines) ")")))
(when suffix (insert suffix))
(setq page-headlines (cdr page-headlines))
(when limit (setq limit (1- limit))))))
(defalias 'planner-notes-index-insert-as-list
'joe-planner-notes-index-insert-as-list)
2. I wanted planner to automatically generate a page with a
monthly notes-index for each month. This page needs to be
updated everytime I add a note so that the new notes-index can
be published with the links to new notes on it. For this
purpose, I came up with this. :) This generates a
<year>.<month> file every time I publish. This file has a
notes-index for that month in it.
(setq joe-month-year-regexp
"\\`\\([1-9][0-9][0-9][0-9]\\)\\.\\([0-9]+\\).*\\'")
(defun joe-generate-archives ()
"Publish monthly archives"
(let (curr-date archive-file archive-month)
(setq curr-date (decode-time (current-time)))
(setq archive-month
(format "%04d.%02d" (elt curr-date 5)(elt curr-date 4)))
(setq archive-file (concat planner-directory "/" archive-month))
(save-excursion
(save-window-excursion
(find-file archive-file)
(delete-region (point-min) (point-max))
(goto-char (point-min))
(insert "\n\n\n* Archive\n\n<planner-notes-index from=\"")
(insert archive-month)
(insert ".01\" to=\"")
(insert archive-month)
(insert ".31\">\n\n")
(save-buffer)
(kill-buffer (buffer-name))))
(emacs-wiki-publish-files (list archive-file) t)
(message "Archives generated")))
3. And, many other blogs have this feature where the latest posts
are available in the reverse choronological order. This can
make your blog-readers come straight there to see what you've
updated. This was kinda lacking on emacs-wiki+planner. I'm not
sure whether there are other ways of doing this. However, I
wrote some code to do this. This code is called every time a
new note is created. It puts a link to the note (the note
title + link to day-page + link to plan-page) on a page called
`RecentPosts`.
This code is also replacement for
remember-planner-add-xref. remember-planner-add-xref puts a
copy of the note on the plan-page. When there are a number of
notes (something like a changelog or worklog), you'll end up
having a huuuuuuuuuuge plan page which takes a lot of time to
load. This code will add only a link to the actual note to the
plan page. The actual note will remain in the day-page.
(defun joe-remember-add-xref-recent-post ()
"Leave the main text in the day page and add a cross-reference to
the plan page. Also add the title and link of the note to the
RecentPosts page "
(when (string-match planner-date-regexp (planner-page-name))
(goto-char (point-min))
(when (looking-at "^.#\\([0-9]+\\)\\s-+\\(.*\\)")
(let* (plan-number
(day-number (match-string-no-properties 1))
(day-page (planner-today))
(title (match-string-no-properties 2))
(planner-default-page (or remember-planner-page (planner-today)))
(body (buffer-substring-no-properties (line-end-position)
(point-max)))
(plan-page (planner-read-name (planner-file-alist))))
(unless (or (not plan-page) (equal plan-page (planner-today)))
(save-window-excursion
(setq plan-number (number-to-string
(planner-create-note plan-page)))
(insert title
" ([[" day-page "#" day-number "]"
"[" day-page ":" day-number "]]) ")
(when remember-save-after-remembering
(save-buffer)))
(goto-char (line-end-position))
(insert
" ([[" plan-page "#" plan-number "]"
"[" plan-page ":" plan-number "]]) "
))
;; Add the note to the RecentPosts
(save-excursion
(save-window-excursion
(find-file "RecentPosts")
(goto-char (point-min))
(planner-seek-to-first "Recent logs")
(goto-char (line-beginning-position))
;; Limit the number of items in the RecentPosts page to 30
(joe-recent-posts-limit-items 30)
(insert "- " title
" ([[" day-page "#" day-number "]"
"[" day-page ":" day-number "]])")
(unless (or (not plan-page) (equal plan-page (planner-today)))
(insert
"([[" plan-page "#" plan-number "]"
"[" plan-page ":" plan-number "]])"))
(insert "\n\n")
(save-buffer)
))))))
(defun joe-recent-posts-limit-items (limit)
"Delete items past the LIMIT-th item."
(save-excursion
(save-window-excursion
(when limit
(widen)
(goto-char (point-min))
(while (and (> limit -1) (re-search-forward "- " nil t))
(setq limit (1- limit)))
(when (= limit -1)
(let ((start (- (match-beginning 0) 2)))
(delete-region start (point-max))))))))
Thats all folks., I'd love to hear your comments and
improvements. :)
--
.O. A proud GNU user
..O http://www.joesteeve.tk/
OOO http://joe.bsdnerds.org/
pgp1qrKhXbm_J.pgp
Description: PGP signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [emacs-wiki-discuss] Some planner.el convenience hacks.,
Joe Steeve <=