1

The Word Processor Nota Bene has a feature which I would like if possible to emulate within Emacs. One can insert into a document non-printing markers which are then used to delineate areas of text or individual keywords to be indexed in text files. For example in the paragraph below the area in double brackets would be the area that would be searched in a document, as opposed to the whole document.

[[Emacs is the extensible]], customizable, self-documenting real-time display editor. This manual describes how to edit with Emacs and some of the ways to customize it; it corresponds to GNU Emacs version 26.3.

If one then did a search through the Nota Bene search tool Orbis, one would search for (say) the word "extensible" and only the text between the markers would be searched. This allows one to more easily find specific information in a file, rather than having to search through dozens of possible hits.

  • I failed to make it clear in my post that the above searching in Nota Bene is done on closed files not buffers. This makes it easy to find files containing specific text. – devcom Oct 5 '19 at 16:52
1

Yes. Here are some ways.

  1. With just vanilla Emacs you can narrow the buffer to the text between your two "markers", using C-x n n. You need only one marker - the mark, at one end of that bit of text, and point (the cursor position) at the other end of that bit of text.

  2. With library Isearch+ you can just search the active region - no need to narrow the buffer to it. This is controlled by option isearchp-restrict-to-region-flag.

  3. If you use library Zones, as well as library Isearch+ then you can you can search a set of buffer zones that are defined by their limits (markers or numbers) – like multiple regions, using commands isearchp-zones-forward and isearchp-zones-forward-regexp.

    The set can contain just a single zone (pair of markers), if you want. There's no need to first activate the zone as the region.

You can of course use any of these approaches from Lisp, as well, e.g., if you don't want to search interactively. Your question doesn't make clear whether you want to do what you ask interactively or from Lisp. (I added tag isearch.)

If you just want to search, from Lisp, between two positions (whether or not there are markers there), then you can do that directly using functions re-search-forward and search-forward (and the backward functions). Just start the search at the first of the two limits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.