Questions tagged [region]

The text between the point and mark in a buffer.

Filter by
Sorted by
Tagged with
1 vote
1 answer
27 views

How to preselect initial text in the minibuffer with Elisp?

I'm using read-string to read a string from the minibuffer, with an initial input. How can I highlight the initial input, so that I can start replacing it with one key stroke? IOW, given (read-string &...
user avatar
  • 1,414
0 votes
1 answer
19 views

Mark up to and including the character under the cursor

By default, when I activate mark it just adds everything to the region up to the point which is behind the cursor (image below) What I want to achieve, however, is to also include - as part of my ...
user avatar
  • 111
0 votes
1 answer
35 views

How can I apply black color for bold text in highlighted region?

I am using dracula-theme. Only change I did is adding following line under (faces ': (faces '(;; default / basic faces (region :background ,dracula-yellow :foreground ,dracula-black :extend t) ...
user avatar
  • 1,066
3 votes
2 answers
73 views

Determining number of left and right bracketing marks within region

I want to write a function that uses a selected region and counts the number of left and right bracketing marks (whether (), {}, [], <>). I have started with this (defun veak-count (region-...
user avatar
  • 159
1 vote
0 answers
67 views

Region ("selection") background color doesn't show

Like most Emacs users I have a setup! But there's one thing I try not to set : faces etc. For one thing I'm not that good with color intuitions. Another: all previous experiences of doing this show it ...
user avatar
  • 295
1 vote
2 answers
60 views

Can I have a selected region that doesn't have point (cursor position) at one of its ends?

I have C-a bound to mark-whole-buffer to replicate the "select all" feature of other standard GUI editors (I also use cua-mode), as described in https://stackoverflow.com/questions/22544655/...
user avatar
  • 127
0 votes
0 answers
45 views

How to add new support to `expand-region`?

I'm trying to add new support to expand-region: (defun er/lisp-mode () (interactive) "Enhancement for lisp like #'() ,@()" (when (looking-at "\\(\\(`,?\\)\\|\\('?,?\\)\\|\\(,?@?\\)...
user avatar
1 vote
1 answer
66 views

execute all org-mode code blocks in a region?

Is there a way to highlight a region of a org file and execute all code blocks in the region? What I was looking for is basically to execute all code blocks up to a certain point, where I am writing ...
user avatar
  • 912
1 vote
1 answer
49 views

How can I apply ansi-color to complete buffer?

I am using following code to apply colorize text in emacs, such as for ^[ characters to apply color. In order to use this code I have to select text to apply it reference: https://unix.stackexchange....
user avatar
  • 1,066
6 votes
3 answers
932 views

How to select and delete a column of text in emacs?

I have this text 1 A 2 B 3 C I want to remove the first column to make it A B C Ok so I need to make a rectangle. Reading about rectangles I see "To specify a rectangle for a command to work on,...
user avatar
0 votes
1 answer
84 views

How to write an elisp function to insert some text at the beginning and end of a selected region? [duplicate]

More specifically, I want to do something like this: Select some region, <mark> int foo(int bar) { bar = do_something(bar); return bar + 1; } <point> and then type a command to do ...
user avatar
1 vote
0 answers
29 views

Conditional Formatting foreground and background when highlighting selected text

This is a follow-up question to: Interchange Foreground and Background Colors when highlighting selected text. How can I do some conditional formatting? For example I do not want inverse-video if the ...
user avatar
1 vote
1 answer
37 views

Interchange Foreground and Background Colors when highlighting selected text

I use something like this to control the background color of my selected text: (region ((t (:background ,green)) (t :inverse-video t))) However some foreground colors don't go well with ...
user avatar
0 votes
1 answer
88 views

Elisp function to remove commas in the region

I'm learning writing Elisp functions to perform small tasks and get to a place where executing a function on the region will replace it with the value returned by the function. Below is a short ...
user avatar
  • 169
2 votes
2 answers
94 views

I want when "C-w" is pressed, execute delete-backward-char when no region is selected and kill-region when the region is selected

Similarly, I want to delete word backward when C-u C-w is pressed. I would also value recommendation on cut/paste/kill conventions. I tried to bind C-w to delete-backward-char, but kill-region stopped ...
user avatar
2 votes
1 answer
41 views

How to apply multiple actions to the same active region (using CUA-mode) [duplicate]

Imagine one wants to apply two functions (A and B, where A could be commenting the code with M-; and B convert the text to all-caps with C-x C-u) to the same active region. I would proceed as follows: ...
user avatar
0 votes
0 answers
59 views

Would it be possible to disable flycheck selected region on mark?

When I selected a region Ctrl-space up-arrow key, flycheck errors' font color are remain as it is. Example, flycheck error makes fore-color bold orange: Would it be possible to disable flychecks when ...
user avatar
  • 1,066
1 vote
1 answer
48 views

How can I fix my re-replace-region function in which match data gets clobbered?

I have an ancient function I've been using for decades which performs a regexp replacement in a region: (defun re-replace-region (begin end old new) "Replace occurrences of REGEXP with TO-STRING ...
user avatar
5 votes
1 answer
196 views

Highlight rectangle and non-rectangle selection at the same time

By default, Emacs highlights the non-rectangular selection; alternatively, you can use (rectangle-mark-mode) to show the rectangular selection. Instead, I'd like to always show both, by highlighting ...
user avatar
  • 165
1 vote
0 answers
35 views

Combine `flyspell-region` with`writegood-mode`

I would like to combine flyspell-region with writegood-mode, but writegood-mode does not provide a function to check a region of text. This is what I came up with to work around the limitation: (defun ...
user avatar
1 vote
0 answers
27 views

How to write functions that only operate on characters within a rectangular-region?

I've found emacs has support for rectangular selection, however I didn't see references to API's for only operating on contents within the rectangle mark. How would this be acomplished? Take this ...
user avatar
  • 7,179
1 vote
2 answers
102 views

How to make query-replace automatically fill what I want to replace with marked text?

I want to select some text somewhere in a buffer, call query-replace and then type (or paste from kill-ring) only the second argument, TO-STRING, (and make the selected text count as FROM-STRING). I ...
user avatar
  • 115
0 votes
1 answer
67 views

How to write a portion of text from current file to the beginning of another file?

I have written a function that extracts a portion of text from current file and writes it in another one: (defun foobar () (interactive) ;; re-search "beg" point ;; re-search "...
user avatar
0 votes
1 answer
152 views

How to get the real line number of a selection?

I am trying to figure out the line numbers referring to the actual selection. What I came up with is something like this (let ((start (line-number-at-pos (region-beginning))) (end (line-number-...
user avatar
1 vote
1 answer
113 views

Searching in a subtree in orgmode without narrowing

Is there a way to search in org mode in emacs in a certain subtree without narrowing or "narrowing" and "widening" the way to go?
user avatar
  • 217
2 votes
1 answer
116 views

Any possibility to show multiple narrowed regions at the same time in a buffer?

As title self-explains, I would like to show multiple regions in different places. narrow-to-region could be a possible solution, but as documentation indicated, only one region from begin to end ...
user avatar
  • 2,310
0 votes
0 answers
90 views

How can I provide the first-error and next-error initial positions as region selection in order to save to the kill-ring?

I am running a make command. I'd like to capture the first error and output it to a file. How can I select as a region from the beginning of first-error position to the position right before the next-...
user avatar
  • 123
1 vote
1 answer
190 views

How to code a command to `write-region` to a particular file?

I have a system that I am not allowed permissions to install software but need to copy text from the remote server to the host computer's system clipboard. Because I can't install xclip or xsel and I ...
user avatar
  • 123
3 votes
0 answers
45 views

Is there a way to move region with arrow keys or similar?

Say I have a function int calc(int that, int this); I want to mark int that and then move it right across words by hitting modifier arrow key (or similar) twice to get int calc(int this, int that); ...
user avatar
2 votes
1 answer
88 views

Background color of matching parentheses overlays the region background color

I have set lime as a background color for my region, and I also have enabled to highlight matching parens using (show-paren-mode 1). The issue I have is that when I exactly select the contents ...
user avatar
  • 271
0 votes
1 answer
66 views

How to delete the text between the tags of an XML element?

I need to delete a block of text between 2 tags, including tags themselves. I tried this: (defun my-delete () (interactive) (beginning-of-buffer) (search-forward "<%ARGS>") ...
user avatar
  • 845
1 vote
1 answer
32 views

Add a border around the region by inserting a given character

There's here, for example, given text: WASP-41b 0.94 1.18 3.052404 0.04 1244 transit 590 0.93 5545 WASP-42b 0.527 1.122 4.9816819 0.0561 ...
user avatar
  • 65
5 votes
1 answer
532 views

Is there an emacs package which can mirror a region?

Say, I have a buffer A in which there is a region of text from some position pos1 to an other position pos2. I switch to buffer B, call a function with buffer A, pos1 and pos2 as parameters and it ...
user avatar
  • 1,058
1 vote
3 answers
313 views

How to check if a region is selected by mouse?

Usually a mouse selected region is highlighted and a region set by (set-mark-command) is not highlighted. But I don't know a programmatic way to check it. Could anyone help?
user avatar
3 votes
1 answer
57 views

How to leave mark region highlighted when switching windows

I usually have my Emacs frame split into windows. I'll select something in one window and then switch to another buffer. When I do this Emacs removes the active-region highlghting in the original ...
user avatar
0 votes
1 answer
421 views

Run current line or selection in shell then insert result in Emacs buffer (Acme workflow)

Given lines like these: pwd echo "Hello \ World" in a buffer, I would like to do the following: Put the cursor to the first line, then press C-` Select lines 3-4 then press C-` to send the line ...
user avatar
  • 115
1 vote
0 answers
41 views

(octave-mode) highlighted region remains highlighted after command

I am in octave-mode running an inferior octave shell. Now I mark a region and issue 'octave-send-region'. All commands are executed as expected and echoed in the shell buffer, and the highlighting is ...
user avatar
1 vote
2 answers
455 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 ...
user avatar
  • 1,089
1 vote
0 answers
57 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 ...
user avatar
  • 11
2 votes
1 answer
125 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 ...
user avatar
  • 243
4 votes
1 answer
264 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 ...
user avatar
  • 153
1 vote
1 answer
80 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 ...
user avatar
  • 21
1 vote
1 answer
52 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 ...
user avatar
  • 1,060
1 vote
1 answer
64 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-...
user avatar
1 vote
1 answer
194 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 ...
user avatar
  • 3,885
0 votes
1 answer
355 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 ...
user avatar
1 vote
1 answer
156 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/...
user avatar
0 votes
1 answer
175 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 --- ...
user avatar
  • 308
1 vote
1 answer
84 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 ...
user avatar
  • 645
7 votes
3 answers
902 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 ...
user avatar
  • 345