From: Tom <adatgyujto@gmail.com>
To: emacs-orgmode@gnu.org
Subject: a new way to navigate your org files
Date: Sun, 24 Apr 2011 16:06:05 +0000 (UTC) [thread overview]
Message-ID: <loom.20110424T175406-354@post.gmane.org> (raw)
I use org goto to jump quckly to headings, but the other day
I forgot the name of the heading, but I remembered its contents.
I thought it could be useful if I could navigate org files by content
too, so I quickly created this package as a sunday afternoon fun.
It is a wrapper around the multi-occur interface, so you can
simply type your search pattern and the occur results from your org
buffers are updated dynamically as you type.
Here it is:
;;; org-occur-goto.el -- search open org buffers with an occur interface
;;; Usage: M-x oog, then start typing
;;;
;;; select from the occur matches with up/down/pgup/pgdown and press enter
;;;
;;; the search string must be at least 3 characters long (by default)
;;;
(require 'cl)
(defvar oog-idle-delay 0.5)
(defvar oog-minimum-input-length 3)
(defvar oog-map
(let ((map (copy-keymap minibuffer-local-map)))
(define-key map (kbd "<down>") 'oog-next-line)
(define-key map (kbd "<up>") 'oog-previous-line)
(define-key map (kbd "<prior>") 'oog-previous-page)
(define-key map (kbd "<next>") 'oog-next-page)
map))
(defun oog-previous-line ()
(interactive)
(oog-move-selection 'next-line -1))
(defun oog-next-line ()
(interactive)
(oog-move-selection 'next-line 1))
(defun oog-previous-page ()
(interactive)
(oog-move-selection 'scroll-down nil))
(defun oog-next-page ()
(interactive)
(oog-move-selection 'scroll-up nil))
(defun oog-move-selection (movefunc movearg)
(let ((win (get-buffer-window "*Occur*")))
(if win
(with-selected-window win
(condition-case nil
(funcall movefunc movearg)
(beginning-of-buffer (goto-char (point-min)))
(end-of-buffer (goto-char (point-max))))))))
(defun oog-check-input ()
(when (sit-for oog-idle-delay)
(unless (equal (minibuffer-contents) oog-current-input)
(setq oog-current-input (minibuffer-contents))
(if (< (length oog-current-input) oog-minimum-input-length)
(let ((win (get-buffer-window "*Occur*")))
(if win
(with-selected-window win
(setq buffer-read-only nil)
(erase-buffer))))
(save-excursion
(flet ((message (&rest args) nil)) ;; suppress occur messages
(multi-occur
(remove nil (mapcar (lambda (buffer)
(with-current-buffer buffer
(if (eq major-mode 'org-mode)
buffer)))
(buffer-list)))
oog-current-input))
(unless (get-buffer "*Occur*")
(message "No matches.")))))))
(defun oog ()
(interactive)
(let (marker)
(save-window-excursion
(add-hook 'post-command-hook 'oog-check-input)
(setq oog-current-input nil)
(unwind-protect
(let ((minibuffer-local-map oog-map))
(read-string "string: "))
(remove-hook 'post-command-hook 'oog-check-input))
(let ((buf (get-buffer "*Occur*")))
(if buf
(with-current-buffer buf
(unless (= (buffer-size) 0)
(setq marker (occur-mode-find-occurrence)))))))
(switch-to-buffer (marker-buffer marker))
(goto-char marker)
(when (outline-invisible-p)
(save-excursion
(outline-previous-visible-heading 1)
(org-show-subtree)))))
next reply other threads:[~2011-04-24 16:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-24 16:06 Tom [this message]
2011-04-24 18:18 ` a new way to navigate your org files Matt Lundin
2011-04-24 20:24 ` Suvayu Ali
2011-04-25 19:25 ` Tom
2011-04-26 11:12 ` Suvayu Ali
2011-08-27 13:26 ` Nathan Neff
2011-08-28 8:44 ` Stelian Iancu
2011-08-28 8:53 ` suvayu ali
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=loom.20110424T175406-354@post.gmane.org \
--to=adatgyujto@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).