From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tom Subject: a new way to navigate your org files Date: Sun, 24 Apr 2011 16:06:05 +0000 (UTC) Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:50385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QE1pD-00085n-7X for emacs-orgmode@gnu.org; Sun, 24 Apr 2011 12:06:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QE1pC-0001ki-9b for emacs-orgmode@gnu.org; Sun, 24 Apr 2011 12:06:19 -0400 Received: from lo.gmane.org ([80.91.229.12]:39430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QE1pB-0001kc-Tz for emacs-orgmode@gnu.org; Sun, 24 Apr 2011 12:06:18 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QE1p9-000075-QJ for emacs-orgmode@gnu.org; Sun, 24 Apr 2011 18:06:15 +0200 Received: from 94-21-170-86.pool.digikabel.hu ([94.21.170.86]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 24 Apr 2011 18:06:15 +0200 Received: from adatgyujto by 94-21-170-86.pool.digikabel.hu with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 24 Apr 2011 18:06:15 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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 "") 'oog-next-line) (define-key map (kbd "") 'oog-previous-line) (define-key map (kbd "") 'oog-previous-page) (define-key map (kbd "") '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)))))