* Help with a hook
@ 2006-10-17 22:10 Eddward DeVilla
2006-10-18 8:35 ` Carsten Dominik
0 siblings, 1 reply; 2+ messages in thread
From: Eddward DeVilla @ 2006-10-17 22:10 UTC (permalink / raw)
To: emacs-orgmode
Hi.
I assume this is a simple question and I should probably take it
somewhere else. I hope you'll forgive me. I'm still very new to
elisp and emacs code conventions. I'm trying to create a custom hook
to set the buffer name for org-mode buffers. Here's what I have so
far:
(defun my-org-buffer-name ()
(when (string= (file-name-nondirectory buffer-file-name)
"projects.org")
(rename-buffer (format "Org -- %s" (org-get-category)) t)))
(add-hook 'org-mode-hook 'my-org-buffer-name)
The intention is to get the category into the modeline. I tend to
name all of my org file the same. At first I had a directory for
every project, and they all had an info.org. Now I've started using
agenda and I just have a projects.org file and directory tree for
different components/areas of responsibility. The first line of every
org file is "#+CATEGORY: ..." but if I've scrolled down in the buffer
I can easily tell which file I'm looking at.
The hook above seems to work at first, but certain things like
restarting org-mode in a buffer seems to cause it to grab the wrong
category. It grab a valid category, just not (the) one from the
current file. So I'll get Cat<2> or some other number where Cat is
not a category in the current file. It doesn't seem to get it wrong
every time either. It's never corrected itself yet either once it was
wrong. It always picks the same category regardless of the order of
the agenda files. I'm guessing I need to pass something special to
org-get-category.
Any thoughts?
Edd
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Help with a hook
2006-10-17 22:10 Help with a hook Eddward DeVilla
@ 2006-10-18 8:35 ` Carsten Dominik
0 siblings, 0 replies; 2+ messages in thread
From: Carsten Dominik @ 2006-10-18 8:35 UTC (permalink / raw)
To: Eddward DeVilla; +Cc: emacs-orgmode
On Oct 18, 2006, at 0:10, Eddward DeVilla wrote:
> Hi.
>
> I assume this is a simple question and I should probably take it
> somewhere else. I hope you'll forgive me. I'm still very new to
> elisp and emacs code conventions. I'm trying to create a custom hook
> to set the buffer name for org-mode buffers. Here's what I have so
> far:
>
> (defun my-org-buffer-name ()
> (when (string= (file-name-nondirectory buffer-file-name)
> "projects.org")
> (rename-buffer (format "Org -- %s" (org-get-category)) t)))
> (add-hook 'org-mode-hook 'my-org-buffer-name)
Do you have several #+CATEGORY lines in the buffer? If yes, the
function you
use will always use the last category in the file. Its hard to
understand why
it would pick a category from a different file.
Try this:
(defun my-org-buffer-name ()
(when (string= (file-name-nondirectory buffer-file-name)
"projects.org")
(let ((org-category-table (org-get-category-table)))
(rename-buffer (format "Org -- %s" (org-get-category 0)) t))))
(add-hook 'org-mode-hook 'my-org-buffer-name)
- Carsten
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-10-18 8:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-17 22:10 Help with a hook Eddward DeVilla
2006-10-18 8:35 ` Carsten Dominik
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.