Questions tagged [region]

The text between the point and mark in a buffer.

Filter by
Sorted by
Tagged with
3
votes
2answers
2k views

How to count the number of lines in the region?

Is there a command similar to count-words-region to count the total number of lines of a selected region?
1
vote
2answers
26 views

Select to the sentence of line in a shortcut

C-k and M-k could delete forward to the end of line and sentence respectively. How could only select to the end in a shortcut? Usually select a sentence and append it to a file for further ...
1
vote
1answer
57 views

Mark isearch result

I'd like to mark the current isearch result so that it can be copied or cut (killed) via M-w and C-w. Is there a ready-made function for this? The solution below provided by @danielpoe over here ...
2
votes
0answers
37 views

show white spaces only when region is selected

whitespace-mode will show the whitespace all the time in entire buffer, Is there the way to show whitespaces only when the region is selected. which is pretty cool to have, does there mode exist for ...
1
vote
0answers
25 views

Add whitespace as indentation with `indent-region`

When using indent-region, emacs will indent code and leave bank spaces untouched. It seems to me that the majority prefer to delete whitespace. However I prefer white space indented with the code. An ...
1
vote
1answer
40 views

How to prevent deactivating the region after a command?

When a function is called on a region, I want a visual indication of affected area (a blink for ex.). Say, I've written a function upcasing previous word, and after evaluation I immediately get the ...
1
vote
1answer
58 views

How to stop backspace from doing kill-region?

(I'm using Emacs for more than 25 years, starting in version 18.58 I think) Recently Emacs received changes that make an old-time user quite desperate, and I wonder how to revert some of those ...
-1
votes
1answer
69 views

mark-whole-buffer followed by kill-ring-save not working correctly

I'm using Emacs 26.1 on MacOS. Instead of copying the entire buffer I get a warning: Saved text until "text where is stopped saving with whitespace seemingly to the end of the buffer " I'm ...
1
vote
1answer
33 views

Searching text between markers as in Nota Bene

The Word Processor Nota Bene has a feature which I would like if possible to emulate within Emacs. One can insert into a document non-printing markers which are then used to delineate areas of text or ...
1
vote
1answer
23 views

Command that does different things based on whether something is selected

I am trying to make emacs function somewhat like sublime text, where C-x cuts text that is selected and cuts the whole line when nothing is selected. I got the full-line cut to work using (global-set-...
1
vote
1answer
24 views

Search within column or rectangle

Is there a simple way to search within the current column or within a rectangle? I am navigating a CSV file and would like to find the value "10" in a particular column. Searching the entire file is ...
0
votes
1answer
67 views

Set value of a variable to region text

I would like to write a script where I can select some text as the region, extract the selected region as a string, modify it, and pass it to another program. I am playing around with ielm and see ...
1
vote
1answer
31 views

(goto-char (region-end)) doesn't set the point to the end of the region

I have written a small elisp script which should put oneline or multiline comments based on the current buffer's major mode. The source file is here: https://github.com/amirteymuri/Com/blob/master/...
0
votes
1answer
49 views

How can I apply a keyboard macro to every line that starts with rectangle mark region

Lets suppose I would like to edit my text and to add comments to the column in the text. This is my text: something-text1 foobar1 something-text1 something-text2 foobar2 something-text2 --- ...
4
votes
3answers
123 views

changing todo state of multiple headings at once

I've got a list of todo's, and I'd like to change all of the todo's in that list with a single command, instead of moving point to each item and changing the status manually. For example. * TODO Item ...
3
votes
2answers
64 views

Is it possible to apply a function to every region between two “marker” lines?

I have a .tex file that looks something like this: $ cat foo.tex \begin{document} \begin{question} lots of multiline text with several paragraphs of information \end{question} other text \begin{...
3
votes
1answer
55 views

Making a region without point

From my understanding, Emacs creates a region my setting a mark and then anything between 'mark' and 'point' is the current region. I'm wondering if there is a way to create a region with only marks, ...
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
2answers
39 views

Shortcut to put the selected region in an ordinary LaTeX environment (not with begin-end style) using auctex

In auctex if one has a selected region and then apply the command c-c c-e (LaTeX-environment) then by selecting an environment, the selected region will be folded between that environment. Is there a ...
1
vote
2answers
55 views

Sort lines in a string

Given I have a string that maybe came from a buffer, or a clipboard, or wherever; how do I sort-lines in it? Given that sort-lines only works with a region, I assume I have to put it to a temporary ...
0
votes
2answers
186 views

Change foreground color of a region (temporarily)

I need to change the "OBJECT" string foreground color (let's say "red") in all the occurrences of the string "\command{OBJECT}" in my buffer and I need to restore the original foreground color at the ...
0
votes
1answer
26 views

How faster show multicursors on the end of all lines?

Som teext 1111111111 2 33333 4444444444444 5555 9999 6666 aaaa aaaaaa zzzzzzzzz hello prev do this My steps: Put cursor to the beginning of first line (1111111111) Press C-> (mc/mark-next-...
2
votes
2answers
234 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 ...
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 ...
5
votes
3answers
178 views

How to select (and highlight) non-consecutive blocks? [duplicate]

The title says it all. I'm looking for a C- or M- built-in way to select non-consecutive lines and blocks of text, like usual consecutive lines with Shift or C-SPC. I.e. I need a switch that turn ...
2
votes
1answer
94 views

making specific regions of a buffer read-only

I know it's possible to make a "portion" of a buffer read-only. As an effect, the whole line becomes uneditable. What I would like it to make a specific region uneditable, for exemple a rectangle ...
1
vote
1answer
72 views

Custom function to apply bold face to a region

I know there is a function called: facemenu-set-bold, which is bound to M-o b, but I'm trying to write my own as an exercise. Here is my code: (defun my-function() "this is my function" (...
1
vote
2answers
74 views

Count the number of paragraphs

There are plenty of ways to count lines, words, and characters in Emacs. For instance, invoking M-= (AKA count-words-region) does that very thing on a given region. However, I am having trouble ...
3
votes
1answer
124 views

Unfill `mu4e` message before sending

I would like to unfill all paragraphs before sending a message with mu4e. This is because format=flowed is not respected by all platforms (particularly Gmail). I figure that message-send-hook is the ...
1
vote
0answers
68 views

How to delete a long region by setting a mark and then searching for the location of the end of the region?

I have a long document. I placed two unique identifiers, in the form of short strings of printable English letter, in two positions in the document. The identifiers are far apart. My task is to delete ...
1
vote
1answer
36 views

Make region transient in elisp function

I'm trying to write a function that exits isearch leaving the current match selected "transiently", so that the mark is deactivated by any unshifted movement command. I've tried to modify this ...
4
votes
1answer
26 views

Idiomatic handling of region boundaries while modifying its content

I want to write a function to indent SQL embedded in a markdown file. It seems to make sense to use the region for this. However, the looping form I am using is: (defun rr/sql-indent-region (...
0
votes
2answers
71 views

Commands or shortcuts to put a selected region between parentheses or brackets in auctex

If some region is selected region, then applying a command (such as the commands which insert an environment) provided by auctex results in putting the region in the corresponding environment. Is ...
0
votes
1answer
76 views

How to convert paragraph into the line?

I've need a function which convert a paragraph into the line, sort each space separated set of characters and fill it back to paragraph. In: Supposedly there are over one million words in the ...
5
votes
0answers
46 views

Point belongs to window - mark belongs to buffer

In Emacs the point belongs to a window: this allows a buffer to be displayed in two different windows at the same time. The mark belongs however to the buffer. Conceptually the mark and a point ...
12
votes
3answers
934 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, ...
0
votes
0answers
64 views

Interactively matching beginning of region

Short version: If i bound the scope of a search/replace to a region in the buffer (via the second/third optional argument of search-forward and its derivates), how can i match the beginning of that ...
2
votes
1answer
33 views

Allow C-w to kill a region only if it is selected

Sometimes (rarely I would say) I press C-w by mistake and if the mark defines a non empty region, it gets deleted. The few times this happened I just pressed undo, but I am afraid that sooner or ...
1
vote
0answers
80 views

How can I execute a python script on a given region of my buffer?

I have a .tex source and a python script called comments.py. This script reads my .tex source as input, does some operations on it and write a .com file as output. Then I have to reneame .com as .tex ...
2
votes
1answer
104 views

Insert text or overwrite region

In an Emacs Lisp function, I would like to insert some text at point or - if the region is active - overwrite it with such text. How to do it?
0
votes
1answer
147 views

How to use flush-lines in a script?

I want to use flush-lines in a selected region, but I have troubles. Here it is my code: (defun delete-empty-lines () "Delete empty lines in bibliography." (interactive) ;; set point-min (...
3
votes
1answer
165 views

Move selected sentence, word left/right by equivalent unit?

More broadly, should work by the selected semantic unit (incl. paragraphs in text mode, and the relevant units in other modes). I.e., if a sentence is selected, then the notional "move-left" would ...
0
votes
0answers
54 views

C-S-a doesn't select text to the line beginning

The Key combination Ctrl + Shift + a doesn't work in my GUI-Emacs to select a region from the position of pointer to the line start. Doing C-h k and the above key combination shows no documentation.
1
vote
1answer
47 views

Cannot mark text when inserting into buffer within post-command-hook

When I add this post-command-hook: (defun insert-into-a-buffer () (with-current-buffer (get-buffer-create "some-buffer") (insert "a"))) (add-hook 'post-command-hook 'insert-into-a-buffer ...
0
votes
1answer
49 views

Call helm on region

I just found out about helm-surfraw by reading Tuhdo's Helm guide. For those familiar with Helm, is there a way for me to call helm-surfraw on a selected region, i.e., using the region as the input ...
5
votes
1answer
194 views

Asynchronous version of shell-command-on-region?

I have a problem which is very similar to this one. I have some text that I'd like to listen to with macOS's say utility. Unfortunately, Emacs locks up when I use shell-command-on-region because it is ...
2
votes
4answers
267 views

Search/replace inside a rectangular region, without CUA mode

I want to use search/replace (string or regexp) inside a rectangular region (aka column selection?). Consider this question: Search and replace inside a rectangle in emacs That's what I want, except ...
0
votes
1answer
38 views

How to find all active bindings which act on a region?

As explained https://emacs.stackexchange.com/a/733/ C-h b lists all bindings available in a buffer. Is there a way to list all bindings which act on a region? For example C-w (kill-region) is one of ...
0
votes
1answer
71 views

Cover the active region with a character

Called with an active region, it will replace all spaces in that region with the character corresponding to the subsequent key press. E.g., if cover-active-region is bound to C-c /, then C-c / h will ...
5
votes
1answer
611 views

Reversing the order of letters/characters of a selected region

How can one reverse the letters/characters in a selected region? xyz --> zyx ab cde --> edc ba