[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Narrow/widen in folding.el
From: |
Tassilo Horn |
Subject: |
Re: Narrow/widen in folding.el |
Date: |
Tue, 21 Dec 2010 19:42:34 +0100 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) |
Andrea Crotti <andrea.crotti.0@gmail.com> writes:
Hi!
>> I use folding.el a lot, and find it useful, but its interaction with
>> isearch is decidedly suboptimal: if you start with a folded buffer,
>> search for something, and land in a fold, the buffer will be narrowed
>> to this fold, and to get out you have to hit C-x n w. This becomes a
>> pain when I have to do lots of small quick searches/edits in a folded
>> document. Is there a way to fix this behavior?..
>
> I suggest to try org-mode, you can do the same things that you're doing
> now but is much more powerful.
But org-mode doesn't work for source code files, e.g. it's not the right
thing for using folding in C++ files.
> If I use isearch it expands when it finds something and doesn't narrow
> it back if I press for example C-a, C-e
org builds upon outline mode, and outline provides a nice
outline-minor-mode that can be used to use outlining in any files. It
also temporally unhides hidden parts when isearching.
I have a small config snippet that calculates the right
`outline-regexp'. Basically, it's the current buffer's comment syntax
followed by at least one *. The more *s, the higher the level.
--8<---------------cut here---------------start------------->8---
(require 'outline)
(defvar th-outline-minor-mode-font-lock-keywords
'((eval . (list (concat "^\\(?:" outline-regexp "\\).*")
0 '(outline-font-lock-face) t t)))
"Additional expressions to highlight in Orgstruct Mode and Outline minor mode.
The difference to `outline-font-lock-keywords' is that this will
overwrite other highlighting.")
(defun th-outline-regexp ()
"Calculate the outline regexp for the current mode."
(let ((comment-starter (replace-regexp-in-string
"[[:space:]]+" "" comment-start)))
(when (string= comment-starter ";")
(setq comment-starter ";;"))
(concat comment-starter "[*]+ ")))
(defun th-outline-minor-mode-init ()
(interactive)
(unless (eq major-mode 'latex-mode)
(setq outline-regexp (th-outline-regexp))
(font-lock-add-keywords
nil
th-outline-minor-mode-font-lock-keywords)))
(add-hook 'outline-minor-mode-hook
'th-outline-minor-mode-init)
--8<---------------cut here---------------end--------------->8---
So in Lisp, I can do:
;;* Headline 1
;;** Headline 1.1
;;** Headline 1.2
and in C I can do
//* Headline 1
//** Headline 1.1
//** Headline 1.2
I also bind TAB to a function that calls `org-cycle' if I'm on an
outline heading, and in all other cases does what TAB would do normally.
Bye,
Tassilo
- Narrow/widen in folding.el, Leo Alekseyev, 2010/12/21
- Re: Narrow/widen in folding.el, Andrea Crotti, 2010/12/21
- Re: Narrow/widen in folding.el,
Tassilo Horn <=
- Re: Narrow/widen in folding.el, Andrea Crotti, 2010/12/21
- Re: Narrow/widen in folding.el, Tassilo Horn, 2010/12/22
- Re: Narrow/widen in folding.el, Andrea Crotti, 2010/12/22
- Re: Narrow/widen in folding.el, Leo Alekseyev, 2010/12/22
- Re: Narrow/widen in folding.el, Tassilo Horn, 2010/12/22
- Re: Narrow/widen in folding.el, Leo Alekseyev, 2010/12/22
- Message not available
- Re: Narrow/widen in folding.el, Tim X, 2010/12/23
- Re: Narrow/widen in folding.el, Leo Alekseyev, 2010/12/24
- Re: Narrow/widen in folding.el, Leo Alekseyev, 2010/12/24
- Re: Narrow/widen in folding.el, Leo Alekseyev, 2010/12/24