Книга: Learning GNU Emacs, 3rd Edition

4.5.3 Read-Only Buffers

4.5.3 Read-Only Buffers

While you're working, you may need to read some file that you don't want to change: you just want to browse through it and look at its contents. Of course, it is easy to touch the keyboard accidentally and make spurious modifications. We've discussed several ways to restore the original file, but it would be better to prevent this from happening at all. How?

You can make any buffer read-only by pressing C-x C-q. Try this on a practice buffer and you'll notice that two percent signs (%%) appear on the left side of the mode line, in the same place where asterisks (**) appear if you've changed a buffer. The percent signs indicate that the buffer is read-only.[22] If you try to type in a read-only buffer, Emacs just beeps at you and displays an error message (Buffer is read-only) in the minibuffer. What happens when you change your mind and want to start editing the read-only buffer again? Just type C-x C-q again. This command toggles the buffer's read-only status—that is, typing C-x C-q repeatedly makes the buffer alternate between read-only and read-write.

Of course, toggling read-only status doesn't change the permissions on a file. If you are editing a buffer containing someone else's file, C-x C-q does not change the read-only status. One way to edit someone else's file is to make a copy of your own using the write-file command, and then make changes. Let's say you want to change a proposal that is owned by someone else. Read the file, write the file as one you own using C-x C-w, then change it from read-only to writable status by pressing C-x C-q. None of this, of course, modifies the original file; it just gives you a copy to work with. If you want to move a minor amount of text from a read-only file to another, you can mark the text then press M-w to copy it. Move to the place you want to put the text and press C-y to paste it.

You can open a file as read-only in a new window by typing C-x 4 r or in a new frame by typing C-x 5 r. This is one of a number of commands in which 4 means window and 5 means frame.

Оглавление книги

Генерация: 1.108. Запросов К БД/Cache: 3 / 0
Вверх Вниз