Hot answers tagged

42 votes
Accepted

set-mark-command (C-SPC) not recognised/broken

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 ...
  • 913
21 votes
Accepted

What is the usefulness of `exchange-point-and-mark`?

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 ...
  • 19.8k
17 votes

What is the usefulness of `exchange-point-and-mark`?

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 ...
  • 72.5k
13 votes

How to unmark selection in elisp?

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-...
  • 1,201
13 votes

Best way to select a word

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

select text to end of line, without moving point

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 ...
  • 536
10 votes
Accepted

mark text with keyboard in PDFView (pdf-tools) mode

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

How to set mark in elisp and have shift selection?

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 ...
  • 8,003
8 votes
Accepted

Is there a package to simplify clickable text?

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

What is the usefulness of `exchange-point-and-mark`?

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 ...
  • 5,610
8 votes

What is the usefulness of `exchange-point-and-mark`?

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 ...
  • 11.1k
8 votes
Accepted

Mysterious highlight in emacs

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-...
  • 13.9k
7 votes

set-mark-command (C-SPC) not recognised/broken

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

Best way to select a word

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 votes
Accepted

How to mark current line and move cursor to next line?

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 ...
  • 24.8k
6 votes
Accepted

pop-mark not working as expected

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 ...
  • 176
6 votes

How to grep marked files in the dired mode of emacs?

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 ...
  • 72.5k
6 votes

Is it possible to disable automatic "mark"ing in emacs?

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 ...
  • 45.3k
6 votes
Accepted

delete-selection-mode not a default?

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. ...
  • 72.5k
6 votes
Accepted

Making a region without point

(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)...
  • 72.5k
5 votes
Accepted

Can you mark-word backwards?

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 ...
  • 19.8k
5 votes
Accepted

Activating the region without altering the mark ring

It's possible, and in fact it's dead simple, as long as you're okay with where mark already is. There's no pre-existing command for it, but you could use this: (defun my/activate-region-only () "...
  • 2,614
5 votes
Accepted

What is the problem with this yank function in elisp in emacs?

Why mark-end-of-sentence? I'd do it like this: (defun vim-line-yank-func() (interactive) (save-excursion (beginning-of-visual-line) (copy-region-as-kill (point) (...
  • 25.8k
5 votes
Accepted

What are the differences mark-ring and global-mark-ring?

You should pose only one question per question here. For your first question: *What are the differences between the mark-ring and the global-mark-ring: This is answered very well in the Emacs manual,...
  • 72.5k
5 votes
Accepted

emacs mark from point to start of buffer?

I would do this: C-SPC to set the mark M-< to go to the beginning of the buffer Or, if you want to finish with point where you started: M-< to go to the beginning of the buffer (which sets ...
  • 19.8k
5 votes

Best way to select a word

M-@ is mark-word, but it does not grab the part of the word that is before point. You can write a command (or create a keyboard macro) that does M-<left> (which is command left-word) followed ...
  • 72.5k
4 votes

Keep region activated upon completion of my command

You need to add this at the end of your command: (setq deactivate-mark nil) C-h v deactivate-mark tells you this: deactivate-mark is a variable defined in ‘C source code’. Its value is nil ...
  • 72.5k
4 votes
Accepted

How to jump to a mark using Elisp

Save the mark as a marker: (setq my-var (mark-marker)) Then: (goto-char my-var) This works regardless of the buffer where you set the variable to the marker: (let ((buf (marker-buffer foo))) (...
  • 72.5k
4 votes

Is there a package to simplify clickable text?

If your clickable text can be defined by a regular expression, the button-lock library combines buttons with font-lock, and can define clickable patterns in one step. Example: (button-lock-set-...
  • 41
4 votes
Accepted

Highlighting and keyboard-quit

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 ...
  • 5,610

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