all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Narrow/widen in folding.el
Date: Tue, 21 Dec 2010 19:42:34 +0100	[thread overview]
Message-ID: <87mxnz9dd1.fsf@member.fsf.org> (raw)
In-Reply-To: m1vd2nf38h.fsf@ip1-201.halifax.rwth-aachen.de

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




  reply	other threads:[~2010-12-21 18:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-20 21:41 Narrow/widen in folding.el Leo Alekseyev
2010-12-21 17:24 ` Andrea Crotti
2010-12-21 18:42   ` Tassilo Horn [this message]
2010-12-21 22:00     ` Andrea Crotti
2010-12-22  8:16       ` Tassilo Horn
2010-12-22  9:01         ` Andrea Crotti
2010-12-22  9:14         ` Leo Alekseyev
2010-12-22 11:02           ` Tassilo Horn
2010-12-22 12:26             ` Leo Alekseyev
     [not found]         ` <mailman.7.1293008512.15562.help-gnu-emacs@gnu.org>
2010-12-23 23:49           ` Tim X
2010-12-25  2:18     ` Leo Alekseyev
2010-12-25  3:08       ` Leo Alekseyev
2010-12-25  4:45     ` Leo Alekseyev
     [not found]     ` <mailman.9.1293252343.14161.help-gnu-emacs@gnu.org>
2010-12-25 22:48       ` Tim X
2010-12-27  9:19         ` Tassilo Horn
     [not found]         ` <mailman.0.1293441599.18751.help-gnu-emacs@gnu.org>
2010-12-27 22:37           ` Tim X

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mxnz9dd1.fsf@member.fsf.org \
    --to=tassilo@member.fsf.org \
    --cc=help-gnu-emacs@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 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.