Hot answers tagged

35

System Preferences > Keyboard > Shortcuts > Input Sources > Select the previous input source and uncheck saltycraig's tip on C-h k C-SPC did nothing when I typed it. So, thanks to Kaushal Modi for pointing towards the OS level. Saved many hours of messing around with all my packages. For completeness I run it as a GUI app (so will need to go and ...


26

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.


21

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 ...


17

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-...


16

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.


13

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


12

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 ...


11

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))) ... (goto-char pos)) 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" (...


11

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.


10

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 ...


10

That would require some notion of a cursor, which is currently not implemented. So marking by keyboard is not available (except the whole page).


10

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))...


10

I usually use C-M-SPC or, with easy-kill installed, M-w w.


9

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 ...


9

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 () (interactive) (beginning-of-line) ...


8

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: Select rectangle. Kill it. 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 ...


8

Emacs provides buttons to abstract away these steps, I'd suggest looking at the Emacs sources for instances of make-button and insert-button.


8

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,...


8

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 ...


7

One of the installed packages you have there may be overriding the C-SPC keybinding for something else. Try starting emacs without loading your init file: $ emacs -Q Now try doing the key combination: C-h k C-SPC And you should see a buffer telling you what it is mapped to. If you don't then the problem is external to Emacs. In that case, one of the ...


7

You can use the expand-region package to do this and more. Let | be point and (...) indicate that ... is marked. foo-|bar Calling er/expand-region once: foo-(|bar) Calling it again: (|foo-bar)


6

(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 ...


6

From pop-mark's documentation: ...This does not move point in the buffer I think you want: ;; do some stuff (goto-char (mark)) (pop-mark) 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


6

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 ...


6

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. (diredp-do-grep COMMAND-ARGS) Run grep on marked (or next prefix arg) files. A prefix argument behaves according to the ARG ...


6

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 ...


6

I've argued the same thing for a long time: delete-selection-mode should be turned on by default. I argued for turning on transient-mark-mode by default, and after decades that eventually happened. The main reason delete-selection-mode is not on by default is inertia, aka tradition, I think. It is expected by most users of editors and other applications ...


6

(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 ...


5

Use a negative prefix argument to mark backwards, for example: M-- M-@ 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 ...


5

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 ...


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