3

I'm using outline-mode (org-mode mostly) in emacs, and use grep-mode to search. What annoys me is when I follow the links in the grep buffer, the folded texts do not unfold. Is there a way to automate that?

A similar problem is to auto-unfold when goto-line is called, this can be achieved by define an advice to the goto-line function, however, defadvice for goto-line and goto-char does not work for mouse-events.

More generally, what happens when I click a link in emacs ? I tried to track down the function stack but can not find the source due to the event-mode used in emacs.

charles
  • 85
  • 2
  • 6
  • 1
    problem solved. I overlooked the message by **F1-K**, which tells that mouse-click event is mapped to **compile-goto-error** function. – charles Jul 02 '11 at 02:52
  • It's better to add the "problem solved" remark as an answer and mark it correct for other people not to bother ;) – Mirzhan Irkegulov Oct 26 '11 at 13:13

2 Answers2

2

For the very first part of your question, here is the trickery I use. Comments follow.

(setq org-directory "~/TOPDIR-OF-ORG-FILES")

(global-set-key "\C-cog" 'fp-org-grep)

(defun fp-org-grep (regexp)
  (interactive "MOrg grep? ")
  (if (string-equal regexp "")
      (error "Rien à trouver!")
    (require 'grep)
    (unless grep-find-template
      (grep-compute-defaults))
    (let ((grep-find-ignored-directories nil)
          (grep-find-ignored-files nil))
      (rgrep regexp "*.org" org-directory))
    (setq fp-org-isearch-string regexp)
    (save-excursion
      (set-buffer "*grep*")
      (setq next-error-function 'fp-org-grep-next-error))))

(defun fp-org-grep-next-error (n &optional reset)
  (compilation-next-error-function n reset)
  (org-reveal)
  (setq isearch-string fp-org-isearch-string)
  (when (or (null search-ring)
            (not (string-equal (car search-ring) fp-org-isearch-string)))
    (push fp-org-isearch-string search-ring)))

(defvar fp-org-isearch-string "")

For speed, I only keep three Org files to my agenda, but define a "C-c o g" command to grep recursively through all my Org files. When you go to any entry through the usual means, the Org surrounding context gets revealed. You may also hit "C-s" to highlight the searched text.

François

icule
  • 76
  • 5
1

I know you said “problem solved”, but if you are mainly using org-mode you should look at org-sparse-tree (C-c /) which lets you show a sparse tree of items that match regexps (or TODO states, or workflows, etc.).

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
SkydiveMike
  • 111
  • 3