Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Suppose I define a custom macro in emacs in my .emacs file. Is there a way to ensure that it works only on the region I marked in a buffer before executing my command, without going into details of the macro definiton?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

I don't think this is possible at the level of macros, it's going to depend on the commands inside the macro. That being said, macros have gotten more flexible since I learned Emacs, so it's possible that I'm missing something.

Emacs offers another possibility to work on part of a file: narrowing. Select the region you want to work with, and press C-x n n (narrow-to-region) to narrow the buffer to the selected region. Now the part outside the region is hidden, and all commands will affect only the visible part. Press C-x n w (widen) to go back to working on the whole file.

A feature that's often convenient together with narrowing is indirect buffers. Run M-x clone-indirect-buffer or C-x 4 c to get a second buffer editing the same file. The two buffers have the same content, and saving either saves the file, but the buffers have separate regions, modes, and visibilities, so you can use narrowing in one and keep the whole file view in the other.

share|improve this answer
    
@student Yes, all the narrowing-related commands are on the C-x n prefix. –  Gilles May 19 '12 at 13:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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