[OS X Emacs] Select all: how to *not* jump to the beginning of the file + how to not change the selection?

Elliott Roper elliott at yrl.co.uk
Wed Sep 21 04:52:49 EDT 2011


On 20 Sep 2011, at 21:37, Jack Repenning wrote:

> On Sep 20, 2011, at 2:30 AM, Hofert Jan Marius wrote:
> 
>> If I either hit Command-A or C-x h to select all text in a buffer, the cursor jumps to the beginning of a file. This is quite annoying when you want to, e.g., indent the whole file (or apply some other function) and then want to continue to work on where you were before. How can I select the whole buffer content without jumping the the first line of the buffer?
> 
> You can't do that: Emacs' idea of "the selection" is "the stuff between the cursor (called point) and another magic location (called mark)." So by (Emacs') definition, the cursor is *always* at one end or the other of any selection.
> 
> What you might be able to do is return to where you came from. At the Elisp programming level, Emacs provides an assortment of features for this, such as "save-excursion" and "set-window-configuration." I don't think there are any direct bindings to these functions (can anyone prove me wrong?), but I've used the below code, in my Preferences.el or equivalent for ages. This makes C-u C-M-z save the current window state, and C-M-z restore the previous state. So you can for instance do some sequence like this:
> 
>  C-u M-C-z (save state)
>  M-h (mark paragraph)
>  M-q (indent region)
>  C-M-z (restore cursor to where you were)
> 
> I admit that C-u C-M-z is a pretty complicated keystroke. A problem with Emacs is that all the good keystrokes are already taken! But you can change the "global-set-key" below to something you like better.
<snip>
If all that elisp is too daunting, you could use a register to remember your position.
(It scares the b'Jasus out of this Emacs newbie)

C-x r <spc> 1 will remember point in register 1
C-x r j 1 will get point back where you left it.

But thanks Jack for that code. I didn't know about pushing and popping your whole window configuration. I really must get my head round elisp.


Elliott Roper




More information about the MacOSX-Emacs mailing list