Skip to main content
21 votes
Accepted

Can I have two views on a file - one narrowed one not?

I think you're looking for clone-indirect-buffer-other-window (bound to C-x 4 c by default). Note that this makes a linked clone of the buffer so you'll need to remember to kill the cloned buffer as ...
Stuart Hickinbottom's user avatar
9 votes

Can I have two views on a file - one narrowed one not?

Since you're using Org Mode, C-c C-x b (org-tree-to-indirect-buffer) may be the best solution. It creates an indirect (new) buffer and narrows it to current subtree, leaving the rest of the document ...
Quarky Quanta's user avatar
7 votes
Accepted

How to display absolute line numbers of a full, widened buffer when narrowing to just part of it?

Specifically for the built-in line-number support in Emacs 26.1: display-line-numbers-widen is a variable defined in `xdisp.c'. Its value is nil Automatically becomes buffer-local when set. ...
rpluim's user avatar
  • 5,325
6 votes
Accepted

Narrowing two consecutive trees in org-mode

If you have org speed commands setup, you can put your cursor at the beginning of a headline, press C-spc to start a mark, then press n to select subsequent headlines, and then C-x nn to narrow to the ...
John Kitchin's user avatar
  • 11.9k
5 votes
Accepted

Frame specific narrowing

Try library narrow-indirect.el. See Narrow Indirect for a description. Indirect buffers let you have any number of different views of the same buffer/file. Each view is a different buffer, whose ...
Drew's user avatar
  • 78k
5 votes

Can I have two views on a file - one narrowed one not?

That is precisely the purpose of library Narrow Indirect (narrow-indirect.el). It gives you narrowing commands that create an indirect buffer that is a clone of the current buffer and that is ...
Drew's user avatar
  • 78k
5 votes
Accepted

Preserve original line numbering for a narrowed region

A little late, but here's what I have in my .emacs. It does change the numbering for all linum-mode enabled buffers, but that's what I generally want: (require 'linum) (defvar my-linum-base-line nil)...
mrtimdog's user avatar
  • 166
4 votes

How to show part of buffer in different buffer?

See library Narrow Indirect (code: narrow-indirect.el). It lets you create an indirect buffer that is a clone of the current buffer and that is narrowed to a particular portion of it. Such an ...
Drew's user avatar
  • 78k
4 votes
Accepted

Why advice won't work if the function is called from another compiled function?

This (narrow-to-region) is the exact example covered by Chris Wellon's article The Limits of Emacs Advice. As @xuchunyang has already pointed out, the issue is that this function has its own byte ...
phils's user avatar
  • 51.6k
3 votes

Any possibility to show multiple narrowed regions at the same time in a buffer?

You can hide multiple regions, or you can have separate indirect buffers for them (one per narrowing). If you want to hide multiple regions, e.g. make them invisible, you can use libraries zones.el (...
Drew's user avatar
  • 78k
2 votes
Accepted

What is the mode or the command to selectively display selected region?

As @Dan commented, you are referring to "narrowing" the buffer. For details read the Narrowing section in the Emacs Manual. The command narrow-to-region (bound to C-x n n by default) will do what you ...
glucas's user avatar
  • 20.6k
2 votes
Accepted

Delighting narrow-to-region possible?

No, delight can't affect the appearance of "Narrow" in the mode line, because it is not a mode name/lighter (despite appearing in the same section of the mode line). Only major mode names and minor ...
phils's user avatar
  • 51.6k
2 votes
Accepted

How narrow from cursor to end of buffer?

The doc-string of narrow-to-region tells us that the mandatory arguments are START and END: "When calling from a program, pass two arguments; positions (integers or markers) bounding the text that ...
lawlist's user avatar
  • 19.2k
2 votes

How to widen all live buffers?

Iterate among all buffers that are displayed (i.e., have a window), widening each: (defun foo () "..." (interactive) (dolist (buf (buffer-list)) (when (get-buffer-window buf 0) ...
Drew's user avatar
  • 78k
2 votes
Accepted

Narrow and move between latex environments

Here's a quick & dirty function that meets your requirements: (defun my-frame-dwim () (interactive) (if (not (buffer-narrowed-p)) (if (search-forward "\\begin{frame}" nil t) (...
Tyler's user avatar
  • 22.4k
2 votes
Accepted

How to create buffer for custom source code region (e.g for each function)?

Library Narrow Indirect (narrow-indirect.el) gives you an easy way to create an indirect buffer that is a clone of the current buffer and that is narrowed to a particular portion of it. Library ...
Drew's user avatar
  • 78k
2 votes
Accepted

Emacs ruby-mode how to prevent narrowed buffer from widening when manual save is triggered

I also tried [ (remove-hook 'after-save-hook 'ruby-mode-set-encoding) ], but it didn't work since, I think, the hook is buffer local? Both add-hook and remove-hook have a LOCAL argument for modifying ...
phils's user avatar
  • 51.6k
1 vote
Accepted

Put “save-excursion” Outermost When Using Both “save-excursion” And “save-restriction”

The Emacs Lisp Reference Manual says: ‘save-restriction’ does _not_ restore point; use ‘save-excursion’ for that. If you use both ‘save-restriction’ and ‘save-excursion’ together, ‘...
NickD's user avatar
  • 30.8k
1 vote

Emacs ruby-mode how to prevent narrowed buffer from widening when manual save is triggered

I eventually traced this to ruby-mode-set-encoding in ruby-mode.el. I worked around it with the following in my .emacs: (with-eval-after-load 'ruby-mode (defun ruby-mode-set-encoding () "...
may's user avatar
  • 125
1 vote

How to display absolute line numbers of a full, widened buffer when narrowing to just part of it?

Stefan's answer leads the way. But you should absolutely not globally advise line-number-at-pos. The consequences of advising line-number-at-pos are unforeseeable! When you are hit by the ...
Tobias's user avatar
  • 33.3k
1 vote

How to display absolute line numbers of a full, widened buffer when narrowing to just part of it?

For both linum and nlinum you can probably get what you want by advising line-number-at-pos to force its absolute arg to be non-nil. Of course, that will affect more than just linum and nlinum. But ...
Stefan's user avatar
  • 26.5k
1 vote

Delighting narrow-to-region possible?

Similar to @phils's answer, but skipping the explaining, which he's done well. (defun remove-Narrow-lighter () "Remove `Narrow' lighter from mode line." (let ((%n-cons (regexp-car-member "%n\\(.*...
Drew's user avatar
  • 78k
1 vote

Switch back to default font on widening

You can use library narrow-indirect.el to help here. Use command ni-narrow-to-region-indirect-other-window (I bind it to C-x 4 n n) to open an indirect buffer that shows just the current region (e.g. ...
Drew's user avatar
  • 78k
1 vote

Query-replace in multiple LaTeX environments, narrowing each in turn

I suggest you try something like this: (defun narrowtable () "Narrowing on table or figure environments." (interactive) (save-excursion (goto-char (point-min)) (while (search-forward-...
Arash Esbati's user avatar
  • 2,020
1 vote

How to show part of buffer in different buffer?

There is also edit-indirect. It lets you create an completely independent buffer which might use a different major-mode, too. You can edit this buffer and commit you changes back to the original ...
clemera's user avatar
  • 3,486
1 vote
Accepted

How to indicate if narrow-to-region is currently in effect

I agree with npostavs' suggestion. Something like: (add-hook 'post-command-hook 'my-narrowed-fringe-status) (defun my-narrowed-fringe-status () "Make the fringe background reflect the buffer's ...
phils's user avatar
  • 51.6k
1 vote
Accepted

How to save a desktop with narrowed indirect buffers?

Bookmark+ lets you combine multiple bookmarks as a sequence bookmark. You could try a sequence bookmark that first restores the desktop (using a desktop bookmark) and then restores a particular ...
Drew's user avatar
  • 78k
1 vote

How do I search in search results

With Isearch+: C-M-s .+function.+, to search for whole lines that contain function. C-z . followed by a regexp for something you want to look for in the lines that contain function. (Optional) ...
Drew's user avatar
  • 78k

Only top scored, non community-wiki answers of a minimum length are eligible