* programmatic jump to headline
@ 2011-03-25 9:38 Eric Abrahamsen
2011-03-25 11:47 ` Bernt Hansen
0 siblings, 1 reply; 3+ messages in thread
From: Eric Abrahamsen @ 2011-03-25 9:38 UTC (permalink / raw
To: emacs-orgmode
I'm writing a little helper function for use when I'm starting work on a
particular long-term writing project. Basically I found myself doing the
same little ritual of commands two or three times a day, and I got tired
of it. Here's what I've got so far, it's pretty self-explanatory. The "my-"
variables are set elsewhere.
#+BEGIN_SRC emacs-lisp
(defun my-project-start ()
(interactive)
(delete-other-windows)
(find-file my-project-file)
;; here's where I go to the most recent Chapter heading
(org-narrow-to-subtree)
(split-window-horizontally)
(other-window 1)
(goto-char (point-max))
(read-abbrev-file my-project-abbrev-file)
)
#+END_SRC
The bit I'm missing is in the comment above. The file is full of
different headings, most (but not all) of which look like
* Chapter XXX
I've looked at the code for org-goto, but it's a wee bit complicated,
and I don't need to do things like pushing to the mark ring. My question
is, what's the simplest way to either:
1. Jump to the "Chapter" heading with the largest number
2. Jump to the bottom-most "Chapter" heading (the bottom-most heading is
not a Chapter)
Additionally, in this case is there any practical difference between
using narrowing or using an indirect buffer? I'm not doing anything but
writing…
Thanks!
Eric
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: programmatic jump to headline
2011-03-25 9:38 programmatic jump to headline Eric Abrahamsen
@ 2011-03-25 11:47 ` Bernt Hansen
2011-03-26 7:07 ` Eric Abrahamsen
0 siblings, 1 reply; 3+ messages in thread
From: Bernt Hansen @ 2011-03-25 11:47 UTC (permalink / raw
To: Eric Abrahamsen; +Cc: emacs-orgmode
Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> I'm writing a little helper function for use when I'm starting work on a
> particular long-term writing project. Basically I found myself doing the
> same little ritual of commands two or three times a day, and I got tired
> of it. Here's what I've got so far, it's pretty self-explanatory. The "my-"
> variables are set elsewhere.
>
> #+BEGIN_SRC emacs-lisp
> (defun my-project-start ()
> (interactive)
> (delete-other-windows)
> (find-file my-project-file)
> ;; here's where I go to the most recent Chapter heading
> (org-narrow-to-subtree)
> (split-window-horizontally)
> (other-window 1)
> (goto-char (point-max))
> (read-abbrev-file my-project-abbrev-file)
> )
> #+END_SRC
>
> The bit I'm missing is in the comment above. The file is full of
> different headings, most (but not all) of which look like
>
> * Chapter XXX
>
> I've looked at the code for org-goto, but it's a wee bit complicated,
> and I don't need to do things like pushing to the mark ring. My question
> is, what's the simplest way to either:
>
> 1. Jump to the "Chapter" heading with the largest number
> 2. Jump to the bottom-most "Chapter" heading (the bottom-most heading is
> not a Chapter)
>
> Additionally, in this case is there any practical difference between
> using narrowing or using an indirect buffer? I'm not doing anything but
> writing…
Hi Eric,
If your chapters are always level 1 headings you can do something like
this:
--8<---------------cut here---------------start------------->8---
(defun bh/jump-to-last-level-1-heading ()
(interactive)
(goto-char (point-max))
(while (org-up-heading-safe)))
--8<---------------cut here---------------end--------------->8---
HTH,
--
Bernt
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: programmatic jump to headline
2011-03-25 11:47 ` Bernt Hansen
@ 2011-03-26 7:07 ` Eric Abrahamsen
0 siblings, 0 replies; 3+ messages in thread
From: Eric Abrahamsen @ 2011-03-26 7:07 UTC (permalink / raw
To: emacs-orgmode
Bernt Hansen <bernt@norang.ca> writes:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> I'm writing a little helper function for use when I'm starting work on a
>> particular long-term writing project. Basically I found myself doing the
>> same little ritual of commands two or three times a day, and I got tired
>> of it. Here's what I've got so far, it's pretty self-explanatory. The "my-"
>> variables are set elsewhere.
[...]
> Hi Eric,
>
> If your chapters are always level 1 headings you can do something like
> this:
>
> (defun bh/jump-to-last-level-1-heading ()
> (interactive)
> (goto-char (point-max))
> (while (org-up-heading-safe)))
Thanks for the pointers! A =while= form with no body wasn't
something that had occured to me, that's pretty useful. The final
command, which does just what I want, is below.
Eric
#+begin_src emacs-lisp
(defun my-project-start ()
(interactive)
(delete-other-windows)
(find-file my-project-file)
(goto-char (point-max))
(while (org-up-heading-safe))
(while (not (looking-at "\\* Chapter"))
(org-backward-same-level 1))
(org-narrow-to-subtree)
(split-window-horizontally)
(other-window 1)
(show-subtree)
(goto-char (point-max))
(abbrev-mode 1)
(read-abbrev-file my-project-abbrev-file)
)
#+end_src
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-26 7:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-25 9:38 programmatic jump to headline Eric Abrahamsen
2011-03-25 11:47 ` Bernt Hansen
2011-03-26 7:07 ` Eric Abrahamsen
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.