Questions tagged [region]

The text between the point and mark in a buffer.

Filter by
Sorted by
Tagged with
2
votes
2answers
58 views

What's the most reliable way to get the start and end positions of current symbol under cursor?

What's the most reliable way to get the start and end positions of the symbol at the cursor location (point)?
3
votes
0answers
137 views

Region face foreground color as function of original faces

I know you can set the :foreground of the region face so that it simply uses the :foreground of whatever is selected, while using the region's :background. And I know you can just set the foreground ...
1
vote
1answer
47 views

Incorrect value of region-end in function that calls replace-string

I am writing a function to do replacements on a highlighted region. It appears that while region-end changes after each replace, the value is not correct. That is, it does not point to the last ...
0
votes
2answers
53 views

Function to duplicate and mark duplicated text

In order to be able to chain the following command, I need the yanked text to be marked. That is because the end goal is to call (pop kill-ring) so that I can still use whatever was at the top of the ...
2
votes
2answers
376 views

Undo region spacemacs

I really appreciate the undo in region command in standard emacs, where you can just mark a region and only changes made in that region are undone. This doesn't seem to work in the default spacemacs ...
1
vote
1answer
116 views

Making it so that cursor movement after command will deactivate region

I'm overriding double-mouse-1 to do additional stuff on top of its default behavior. To this end, I have a function that (1) does my additional stuff and then (2) calls another function, ora-mark-like-...
1
vote
0answers
47 views

What is the cause of this inconsistent behaviour of TeX-command-buffer when narrowing?

When editing medium sized .tex files, I often find it convenient to make use of the narrow command C-x n n (narrow-to-region), usually in combination with the mark section command C-c * (LaTeX-mark-...
9
votes
2answers
409 views

Selecting (i.e., as the region) the current match in incremental search

When searching for a string with C-s, I want to be able to hit some key to exit search mode but still maintain the selection of the match. That way I can immediately start typing and replace the last ...
5
votes
2answers
648 views

Copy text as rectangle

This is the block of text that I intend to copy as rectangle (without the line numbers). 1. ALM_KRmet_DCDO_RPMP_START 2. ALM_KRmet_DCDO_RPMP_STOP 3. ALM_KRmet_DIDC_RPMP_TRIP 4. ...
4
votes
2answers
181 views

Use shift-up/down keys to mark/unmark lines in dired?

The default in dired is to mark files and folders with m, and to unmark them with u. Instead of this, I'd rather like to use shift-up and shift-down for marking or unmarking lines (in a DWIM fashion). ...
3
votes
2answers
200 views

How to move the cursor to the beginning/end of a shift-selected region by a left/right motion?

In most modern editors, after canceling a selection by a left/right motion, the cursor will be moved to the beginning/end of the previously-selected region correspondingly. Similarly, if we cancel a ...
5
votes
2answers
212 views

How many bytes are in the region?

After far too many years of counting the number of characters in the region by doing M-: (- (point) (mark)), I just discovered M-= (count-words-region). Much better! But now I'm looking for a way to ...
2
votes
1answer
75 views

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

Idea I will like to construct a simple emacs function that copies the yy functionality in vim. The function should yank a visual-line into kill ring without deleting the line. Function Here is ...
-1
votes
1answer
172 views

Non-shell command on region?

I know about shell-command-on-region. Is there any way to pipe a region through a non-shell command? The start-process and call-process functions invoke executables directly, without using the shell. ...
0
votes
2answers
74 views

Tab key getting bounded to forward-button

Launching emacs with the -Q option (default settings) shows TAB being correctly bound to indent-for-tab-command. If I launch emacs without the -Q, TAB is always being bound to forward-button which is ...
1
vote
0answers
49 views

Launch functions one after another

I wrote a function that pastes in the currently selected color from the palette to the buffer: (defun palette-paste-in-current-color () (interactive) (cua-paste (palette-current-rgb-to-kill-ring))...
3
votes
1answer
1k views

How to unmark selection in elisp?

I wish to remove selection programatically, what is the proper way of doing this? Specifically I wish to write a function to make swiper search in buffer with selected text, but it needs to remove ...
2
votes
0answers
22 views

Is it possible to highlight the region uniformly across different sizes/fonts?

Highlighting the region when it includes text with different heights/fonts shows gaps and different highlighting heights as follows: Is there any way of highlighting continuously (no gaps) and ...
2
votes
0answers
41 views

Are there any packages or configuration snippets for better whitespace traversal?

Whitespace traversal in Emacs is atrocious. By "traversal" I mean: Moving the point with C-<direction> Expanding a selection (with either a package or region mark) Deleting with C- or M- ...
2
votes
1answer
121 views

How to prevent the active region from setting the primary selection?

After switching to 24.5.11 from some ancient version, Emacs started to spam my primary selection: Whenever I mark a region, or even move the point using e.g. arrow keys when the mark is active, a new ...
1
vote
1answer
65 views

How to retain selection after command run (indent-code-rigidly)?

I found a neat code snippet for ~/.emacs configuration: (global-set-key (kbd "C->") (lambda (b e &optional n) (interactive "r") (...
1
vote
1answer
70 views

highlight blank spaces only under the marked region

Is there a way to only highlight blank spaces/tabs under the marked region? Basically if I have whitespace-mode turned off and if a select a region all the spaces and tabs get highlighted.
0
votes
1answer
93 views

defun completion and region

Is it possible to write a function with completion that act on region? A mix of: (defun function-style (style) (interactive (list (completing-read "Style: " styles-list))) ... And (...
3
votes
1answer
100 views

How to use one binding to call different functions depending on whether the region is active?

As I only use kill-ring-save after I used set-mark-command, I wanted to try using its binding also for another command. However I'm not able to get this to work with an additional if. I don't know how ...
0
votes
1answer
84 views

Unable to deactivate the selection mode with C-SPC

Sometimes I can't deactivate the mode of selecting text which is C-SPC. Even if I press it a second time and move the cursor, the text still gets selected. I press C-SPC one more time, it activates ...
1
vote
2answers
445 views

Highlight text equivalent to the marked region and search and replace on the fly

Edit: Highlight text that matches the marked region, without the use of any key, but just by having a region marked. Then have two commands to directly move across the highlighted text, forward and ...
3
votes
1answer
67 views

kill-region deletes entire buffer content instead of selected text

In emacs, i have a small text selected as shown in the picture. When i do eval-buffer, i like the kill-region to remove only the highlighted text. But this code empties the buffer. ;;this is a ...
1
vote
2answers
269 views

er/expand-region not working as previously under Emacs 25.1

I've got er/expand-region behaving very strangely and I don't understand what I did wrong (besides upgrading to Emacs 25.1.50). If I've got this in an elisp file: (defun foo (p) (* 2 2) p) (that ...
2
votes
1answer
193 views

Highlighting selected region in same buffer, displayed in multiple windows

Q:  I am seeking a proposed modification of simple.el at lines 5251 to 5308 of the master branch relating to highlighting a selected region to achieve a better visual representation when the same ...
10
votes
1answer
414 views

How to copy text without losing selection?

When I copy some selected text (kill-ring-save with M-w), I automatically lose my selection. I have tried with Transient Mark Mode with no luck. (Note that I'm not using CUA Mode.)
4
votes
2answers
120 views

Activating the region without altering the mark ring

Setting the mark and moving point activates the region, which appears highlighted (assuming transient-mark-mode is enabled). Once the mark is set it's location is sent to the mark ring, thus changing ...
3
votes
1answer
167 views

Right-click to select one character under the mouse pointer?

I'm using GUI emacs 24.4.9.0, so I can click to move the cursor, and double-click to select a word under the mouse pointer as a region. How can I configure emacs so that right-click selects a ...
4
votes
2answers
119 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
495 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
300 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
313 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
91 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 ...
6
votes
2answers
2k 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
99 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
128 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
234 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 ...
4
votes
3answers
5k 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
202 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
113 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-...
16
votes
4answers
1k 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
356 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 ...
17
votes
1answer
1k 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
103 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 ...
31
votes
8answers
2k 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 ...