Helm has an interface for browsing both local and global mark-rings: helm-all-mark-rings.
See the mini-guide for a brief description and a screenshot.
And if you prefer Ivy/Swiper/Counsel, see counsel-mark-ring.
There are two cases I can think of: reactivating the region, and adjusting the size of the region.
I most often use this binding to reactivate the region after performing some command that deactivates it, or doing something that sets mark and moves point without activating the region.
For example, do a C-s and search forward for something. Hit RET to ...
Ask Emacs: C-h r i exchange-point-and-mark RET or, better, C-h r i C-x C-x RET. This takes you to the information shown below.
This is what the Emacs manual, node Setting Mark says in answer to your question:
C-x C-x is useful when you are
satisfied with the position of point but want to move the other end of
the region (where the mark is). Using C-...
When you set set-mark-command-repeat-pop to t via
(setq set-mark-command-repeat-pop t)
you can keep pressing C-SPC after the first invocation of C-u C-SPC to jump to previous locations stored in the mark ring.
There is a separate answer for each of the points you listed:
The emacs default binding C-x
h will select the whole buffer regardless of where the cursor is.
The expand-region package will help achieve the second goal of gradually expanding the selection. expand-region will also eventually select the whole buffer as you keep on expanding the region. Have a ...
Save-excursion restores point AND mark (as of emacs 24.4), so it is no help for you here.
You could save the point manually with this idiom:
(let ((pos (point)))
However, in your case it's better to just set the mark at the end of the line:
(defun mark-from-point-to-end-of-line ()
"Marks everything from point to end of line"
I find it easier to use registers to mark locations: C-x r <space> and then a letter to mark, C-x r j and a letter to jump back. I can maintain a number of marks, very useful when alternating between multiple buffers
If the region grows then the cursor changes position. This is because the cursor is always at one end of the region.
If you select all of the buffer text (C-x h and then use C-x C-x to swap point and mark, so the cursor is at the end of the text), and then you type some more text, then you have accomplished what you want: the region has been extended to ...
C-x C-x for exchange-mark-and-point has similar use to C-u C-space. It lets you bounce between a point and the last mark. It's a little weird for bouncing with transient-mark-mode as it activates the mark and selects the region.
Ok, I found the answer almost immediately after posting question. The function name is deactivate-mark if anyone has the same question. Its described here. Updated code:
(defun sandric/swiper-or-region (beg end)
"Swiper region or 'empty string' if none highlighted."
(interactive (if (use-region-p)
(list (region-beginning) (region-end))...
Apart from the other tips you have got here I thought I should mention that C-s sets the mark for you, so there is no need to do it explicitly. Also, many commands that "move a potentially long way" (beginning-of-buffer and end-of-buffer for example) also sets the mark where you started. Together with the other ways to work with the mark (pop, exchange point ...
I use this when I've lost a selection due to some operation that removed it, and I want to restore selection. One such scenario would be:
Undo killing rectangle.
C-x C-x to restore selection to rectangle.
This happens when I want to make an ad hoc backup of a selected area and to experiment on the copy, such as, for example, I ...
The other answers focus on the usefulness of C-x C-x when transient-mark-mode is active. But C-x C-x predates transient-mark-mode, and is useful independently of it.
The main role of C-x C-x is to swap point and mark. This useful when you are editing two points in a single buffer and for some reason don't want to split the current window. Do some editing,...
Because shift translation and temporary activation of the mark is handled by the command loop, you will need to call the interactive versions of the movement functions in order to get the appropriate shift selection behavior from them:
;; (source: http://emacs.stackexchange.com/a/22166/93)
(defun my-mark-current-line ()
It's the secondary selection. Clicking and dragging sets the primary selection, and middle click pastes from that selection. Holding alt while clicking and dragging sets the secondary selection, and M-mouse-2 pastes from it. Very few applications use the secondary selection any more, but it's quite handy when you have two things to copy and paste. See ...
From pop-mark's documentation: ...This does not move point in the buffer
I think you want:
;; do some stuff
But if all you care about is returning to a previous location, and not actually using the mark ring, then you could either
1) save (point) in a variable and return to it
2) use save-excursion which does this for you
Below works with brief testing:
If no region is selected to begin with, the current line will be selected and the cursor will move to the next line (default, if no prefix arg is used).
If a region is already selected, all this command will do is move the cursor to the next line (default, if no prefix arg is used).
With that functionality, hitting C-l once ...
If you use library Dired+ (dired+.el) then you can use command dired-do-grep (bound by default to M-g in Dired mode) to do what you request.
diredp-do-grep is an interactive compiled Lisp function in dired+.el.
Run grep on marked (or next prefix arg) files.
A prefix argument behaves according to the ARG ...
Not as such. You certainly can't prevent things from calling push-mark and set-mark and friends.
There's nothing stopping you from redefining the standard functions to do nothing, however. You would then need to write your own commands for managing the mark ring.
However, rather than trying to prevent Emacs using the mark ring in all possible situations, a ...
(You say "a region", not "the region", so a guess is that you do not really mean the Emacs region.)
If your question is really about the Emacs region then the answer is no. Point (the cursor position) is always at one end of the region, and mark is always at the other end.
See the Emacs manual, node Mark for more information. [I found that node by going to ...
Use a negative prefix argument to mark backwards, for example:
Note that you can also mark a number of words forwards or backwards. For example, mark backwards four words:
M-- M-4 M-@
Note that by default Emacs binds the prefix keys with a variety of modifiers. This makes it easier to specify a prefix when you are holding down some combination of ...
(Your question is pretty open-ended, so it might get closed as being primarily opinion-based.)
What I use: Icicles multi-command icicle-goto-marker (bound to C-- C-SPC) to trip around the marks in any buffer (mark-ring), and icicle-goto-global-marker (C-- C-x C-SPC) to trip among the global marks (global-mark-ring).
The lines of text where the markers are ...
Do not worry about the kill ring ("clipboard") being overwritten: you can recover previous kill ring entries by typing C-y M-y (repeat M-y as many times as you need). See Section 12.2.2 of the Emacs manual for more.
If you really want to disable M-w when the region is inactive ("not highlighted"), which I do not recommend, you can probably do something ...
As mentioned, the expand-region package is great but I also feel its worth mentioning easy-kill. It's billed as a drop in replacement for kill-ring-save that turns the normal M-w "copy" into a dynamic copy command that also acts as a prefix for saving various things. For example, M-w would copy the active region, url, email or current line (in order of easy-...
As noted by abo-abo, the function keyboard-quit explicitly deactivates the mark. While you could in principle edit this function, it is better to advise it so that it conditionally reactivates the mark if it was active before. Since keyboard-quit may exit by signalling a condition, you must do that in an unwind-protect unwind handler: