Questions tagged [region]

The text between the point and mark in a buffer.

A region is all text in a buffer between the point (the text-cursor position) and the mark (if it exists). With transient-mark-mode on, the region text is highlighted.

169 questions
33
votes
8 answers

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 this functionality is as follows: Assume that I have…
Name
  • 7,849
  • 4
  • 41
  • 87
8
votes
1 answer

How to set the region (selection) programmatically in Emacs Lisp using indices?

Given 2 absolute numbers (compatible with region-beginning, region-end). How can these numbers be used to set the selection? Edit: If you use evil mode you may want to check this question, at the time of asking I wasn't aware this required a…
ideasman42
  • 8,786
  • 1
  • 32
  • 114
6
votes
2 answers

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
Name
  • 7,849
  • 4
  • 41
  • 87
5
votes
1 answer

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 copies the referred region to buffer B at point and…
Tom
  • 1,260
  • 8
  • 16
4
votes
1 answer

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 dubious "enhancements": When I set a mark, copy and…
U. Windl
  • 215
  • 2
  • 11
4
votes
1 answer

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 (beginning end) (interactive "r") (while (< (point)…
Realraptor
  • 1,283
  • 7
  • 17
4
votes
1 answer

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 highlighted code and paste to web like stackoverflow…
tom
  • 365
  • 2
  • 7
3
votes
2 answers

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{question} more text here that i want…
Brian Fitzpatrick
  • 2,325
  • 1
  • 20
  • 42
2
votes
1 answer

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 that I can call (yank) to pull the region string…
George Mauer
  • 407
  • 3
  • 9
1
vote
1 answer

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 result (and that's good) but I also want region…
A.King
  • 53
  • 3
0
votes
1 answer

How do I remove a protected region or line?

Apparently I cannot find the correct word for this problem. I tried searching for: protected non-editable blocked but none of those bring up anything. I was writing some code when my cat jumped on my keyboard. I'm not sure what keys they hit, but…
0
votes
0 answers

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 "\\(\\(`,?\\)\\|\\('?,?\\)\\|\\(,?@?\\)\\|\\(#?'?\\)\\)?(") (cond ((er/looking-back-on-line…
C-Entropy
  • 143
  • 5
0
votes
1 answer

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

More specifically, I want to do something like this: Select some region, int foo(int bar) { bar = do_something(bar); return bar + 1; } and then type a command to do like this: #if 0 int foo(int bar) { bar =…
user36468
0
votes
1 answer

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>") (move-beginning-of-line nil) (set-mark-command…
user4035
  • 1,059
  • 13
  • 24