Questions tagged [region]

The text between the point and mark in a buffer.

Filter by
Sorted by
Tagged with
5
votes
2answers
157 views

Keep region activated upon completion of my command

I'm using the following functions to speed up some regexps replacements I frequently use. jc-replace-regexp-in-region can be called by several functions like jc-dollar-to-paren. At the moment, when ...
2
votes
1answer
665 views

how to modify the active region highlighting color

Gray text highlighting no longer works on my Debian/stretch system. While this is particularly annoying in Emacs, it's not a specific Emacs problem; gray background is also gone from other ...
0
votes
4answers
350 views

elisp pattern for handling region || buffer || file

summary Elisp newbie has been given interactive code (aka commands, called with M-x whatever) that "does stuff" on the currently-selected region in the current buffer. What is an/the "elispish way" ...
4
votes
1answer
387 views

How do I expand the region-beginning and region-end?

Solution: With the help of @Drew, I figure out a solution. I am not good at elisp. The code may not be a good design but at least is working. I use this code to add 4 white space so I can copy a ...
1
vote
2answers
105 views

delete-c-electric-paren deletes active region in CC mode with delete-selection-mode enabled

I've the delete-selection-mode enabled. In programming modes like Python and Lua, or in general modes like Fundamental or Text, when there's an active region, pressing ( rightly wraps the region with ...
7
votes
2answers
3k views

How to auto copy when a region is selected?

Chrome browser has an excellent extension called autocopy, which copies text whenever some text is selected/highlighted. To copy a region in emacs, I have to select the region and then press M-w to ...
1
vote
5answers
108 views

Leave point in original position when C-g is pressed?

I am writing a function to select a region (say 2 lines). (defun select-some-region () (interactive) (push-mark (point) nil t) (forward-line 2)) When point is in a buffer like this |...
2
votes
1answer
135 views

What changed with Mark/Region behavior between GNU Emacs 24.3.1 and 24.5.1?

I wrote a little search function a long time ago, binded to ctrl-f. It has been working perfectly until I tried Emacs 24.4. The purpose of the function is to highlight (region) the found word. ...
3
votes
2answers
1k views

How to select text found by `re-search-forward`?

The following function searches buffer text for string STR, in the same way as search-forward. How to modify it in order that it selects the text found? (defun my-search-forward (str) (interactive "...
8
votes
1answer
296 views

Fold region of org file

Is there a way to fold a region in org-mode? (Not the whole file, and not an individual item, but a region containing multiple items.) Often I want to collapse only a portion of an org file, say ...
6
votes
3answers
6k views

How to replace words in a region using iedit?

I want to replace some words inside a region. I would like to use iedit more than query-replace, but found the following problems (probably because I don't understand its documentation): If I select ...
2
votes
2answers
275 views

Any way to select a region using `S-down-mouse-1` without saving the region as a kill?

Using emacsw32. The usual suggested way to make a selection using S-down-mouse-1 is to bind that to mouse-save-then-kill. Is there a similar command which selects a region, but does not save the ...
2
votes
1answer
120 views

Using replace-regexp with a shell command

I'm trying to format some text that matches a regexp using an external shell command. I've been able to use C-u M-| successfully on a region, but I can't figure out how to do that within replace-...
17
votes
4answers
2k views

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

The exchange-point-and-mark command is bound to C-x C-x, but I cannot think of any use cases that would make it deserving of such a prominent binding. How can I use the exchange-point-and-mark to ...
6
votes
3answers
418 views

In shift selection, retain the mark if it's already active

Under shift-select-mode, cursor keys behave like many other text editing environments: Shift+motion starts selecting (sets and activates the mark, in Emacs terms), and motion without Shift stops ...
22
votes
1answer
2k views

Elisp for applying command to only the selected region

Say, I have some code like this: (defun some-function () (interactive) ;; do something ) Now I want some-function to operate only on the selected region in the buffer ? How can I do that ? ...
1
vote
1answer
122 views

Delete marked region with py-electric-backspace py-electric-delete

In my python-mode the backspace and delete keys gets remapped to py-electric-backspace, etc. This breaks the behaviour set by the variable delete-active-region. Is there a way to unify the behaviour ...
32
votes
8answers
3k views

How to select non-contiguous regions in Emacs?

Suppose that I have already selected some text in the current buffer. Is it possible to select another stretch of text, while keeping the previous selection (and so on)? Added: One motivation for ...
8
votes
3answers
1k views

Sum numbers in region

How can I sum a set of numbers interspersed with text in the region (not a rectangular region). For example, if the region contains this text: Widgets 234 Sprockets 44 Nubbins 12 Fork handles 4 4 ...
8
votes
2answers
3k views

Remove parentheses around region

Is there a better alternative to this function I use to remove parens around a region? I'm looking for an Emacs builtin, or something better written, something that will remove any pairs around the ...
7
votes
3answers
1k views

select text to end of line, without moving point

I often want to quickly mark everything from point to the end of line, leaving point at the same place. I tried to write simple function for that purpose: (defun mark-from-point-to-end-of-line () "...
8
votes
2answers
235 views

Narrow to previous restriction

Is there a convenient way to restore the previous restriction? So after the following sequence of events: Mark a region Call narrow-to-region and do some work. Call widen to jump around and look for ...
1
vote
1answer
273 views

Use multiple cursor if region is active, otherwise use CUA, how?

I’m trying to implement this when I press C-return: If there’s an active region, it activates multiple cursors by calling mc/edit-lines If there’s no active region, it initiates rectangular selection ...
9
votes
3answers
230 views

Set region to include enclosing parentheses

Starting with the point or active region, how do I quickly (in one keystroke / command) 'expand' to include the next set of enclosing parentheses? If I start with: (| means point) (defn foo [x] (+ x ...
12
votes
3answers
1k views

Fontify a region of a buffer with another major mode

I have a buffer that shows documentation for Ansible modules. This buffer has its own major mode which provides all the standard stuff. Notably, it fontifies the buffer to highlight inline markup, ...
1
vote
1answer
305 views

How to avoid losing selection with Helm

Whenever I select a region and execute an extended command (M-x), Helm opens and I immediately lose the ring selection highlighting. Is there a way of stopping Helm from doing so? My Helm ...
5
votes
1answer
196 views

How to make sure currently selected text gets deleted when typing new text?

When editing text, editors' usual behaviour is to replace selected text with the next text. In Emacs, when text is selected and you enter new characters, the new text gets inserted at point, leaving ...
15
votes
2answers
5k views

Shift+Up isn't recognized by Emacs in a terminal

Very often I use Shift+Up/Down to select a region in Emacs. It works fine in GUI mode, but when emacs is invoked with -nw option I can select lines only with Shift+Down. The Shift+Up doesn't work, I ...
8
votes
6answers
1k views

Selecting text without moving the cursor

I would like to grow a selection without moving point (the cursor) from its location. I know I can always use C-u C-spc to move to the previous location, but I would like to avoid that. More ...
8
votes
2answers
85 views

Why is my function not identifying the end of the region correctly?

I have the following function, adapted slightly from here: ;; Insert text around a region. In this case, it's ;; the LaTeX code environment from the listings package (defun wrap-code (start end) "...

1 2
3