26
votes
Accepted
How to count the number of lines in the region?
M-= (command count-words-region).
(The region does not even need to be activated, but activating it lets you see it.)
20
votes
Accepted
How to select and delete a column of text in emacs?
C-w kills the text between point and mark; it’s the normal command you would use to kill text. C-x r k kills the rectangle between point and mark. This is the one you want to use.
19
votes
How to select and delete a column of text in emacs?
If you select the rectangle, which in Emacs terms means make it an active rectangular region, then C-w does just what you expect.
Use C-x SPC to activate a rectangular region that you want to kill. ...
16
votes
How to unmark selection in elisp?
Ok, I found the answer almost immediately after posting question. The function name is deactivate-mark if anyone has the same question. Its described here. Updated code:
(defun sandric/swiper-or-...
10
votes
Accepted
changing todo state of multiple headings at once
The Org documentation says
Many commands in Org work on the region if the region is active.
And indeed defining a region followed by C-c C-t acts on all headlines in that region. Note that ...
9
votes
Accepted
How to set the region (selection) programmatically in Emacs Lisp using indices?
The region is defined as the span of text between point and mark, therefore it's sufficient to adjust both to the numbers in question. The following uses point-min and point-max for that purpose:
(...
8
votes
Accepted
Copy text as rectangle
My crystal ball tells me you're using Emacs-24.5, which indeed had this limitation. This has been fixed in Emacs-25 where rectangle-mark-mode has been improved so you can move the cursor past the "...
7
votes
Accepted
Selecting (i.e., as the region) the current match in incremental search
Here's one approach:
(defun isearch-exit-mark-match ()
"Exit isearch and mark the current match."
(interactive)
(isearch-exit)
(push-mark isearch-other-end)
(activate-mark))
(define-key ...
7
votes
Send region to shell in another buffer
Emacs provides the function process-send-region to do this. If your buffer always has the same name, you can hard-code it in:
(defun my-send (beg end)
(interactive "r")
(process-send-region "...
7
votes
Accepted
Highlight rectangle and non-rectangle selection at the same time
There’s no simple variable you can set to control this, but you can do it with some programming if you want.
There is a variable called redisplay-highlight-region-function whose value is a function to ...
6
votes
Accepted
What's the most reliable way to get the start and end positions of current symbol under cursor?
The thingatpt.el API works as follows:
(thing-at-point 'symbol) ;=> foo
(beginning-of-thing 'symbol) ;=> 42
(end-of-thing 'symbol) ;=> 45
(bounds-of-thing-at-point 'symbol) ;=> (42 . 45)
...
6
votes
Insert text or overwrite region
For Emacs setting:
(delete-selection-mode t) ; delete seleted text when typing
For lisp code, add following line before insert:
(if (region-active-p) (delete-region (region-beginning) (region-end))...
6
votes
Accepted
Making a region without point
(You say "a region", not "the region", so a guess is that you do not really mean the Emacs region.)
If your question is really about the Emacs region then the answer is no. Point (the cursor position)...
6
votes
Accepted
Is there an emacs package which can mirror a region?
The documentation string for the command text-clone-create:
(text-clone-create START END &optional SPREADP SYNTAX)
Create a text clone of START...END at point.
Text clones are chunks of ...
5
votes
Accepted
What is the problem with this yank function in elisp in emacs?
Why mark-end-of-sentence?
I'd do it like this:
(defun vim-line-yank-func()
(interactive)
(save-excursion
(beginning-of-visual-line)
(copy-region-as-kill (point)
(...
5
votes
How to count the number of lines in the region?
Count lines does the trick, it is defined in simple.el
(count-lines (point-min) (point-max))
5
votes
Allow C-w to kill a region only if it is selected
I think you're looking for:
(setq mark-even-if-inactive nil)
5
votes
Accepted
How to leave mark region highlighted when switching windows
highlight-nonselected-windows is a variable defined in xdisp.c. Its default value is nil. A non-nil value means highlight region even in nonselected windows. You can customize this variable, e.g.:
...
5
votes
Accepted
execute all org-mode code blocks in a region?
You can use narrow-to-region, then run org-babel-execute-buffer, then widen again:
(defun org-babel-execute-region (beg end &optional arg)
(interactive "r")
(narrow-to-region beg ...
4
votes
How many bytes are in the region?
While Drew's answer will work correctly in many cases (where utf-8 is pervasive and if you don't use DOS-style EOLs), if you want to make it work reliably for "all" buffers, you could do something ...
4
votes
Accepted
How many bytes are in the region?
Sounds like you are asking for something like this:
(defun region-bytes ()
(interactive)
(let ((strg (if (use-region-p)
(buffer-substring-no-properties (region-beginning) (...
4
votes
Use shift-up/down keys to mark/unmark lines in dired?
If you use Dired+ then you get similar behavior out of the box.
Command diredp-mark-region-files marks the files in the active region. (Similarly, diredp-unmark-region-files unmarks them.)
And shift-...
4
votes
Selecting (i.e., as the region) the current match in incremental search
Library Isearch+ lets you do that easily, and even toggle it on/off on the fly.
Non-nil option isearchp-set-region-flag automatically sets the region (selection) around the last search target when ...
4
votes
Accepted
Asynchronous version of shell-command-on-region?
Something in this spirit should do the trick. I tried it with espeak under Ubuntu; I guess it would work with say as well.
(defun my-read-words-on-region ()
"Send the region to `espeak'."
(...
4
votes
Accepted
How faster show multicursors on the end of all lines?
The command mc/edit-ends-of-lines adds a cursor to the end of the every line in the region. There are many ways to set the region. If you want to mark every line in a file, you can set the region to ...
4
votes
Accepted
(interactive "r") can't be used directly after Emacs startup
The use-region-p test should be within the interactive spec.
"r" is for functions that always use the region. You probably want to use something like:
(defun try-region (&optional begin end)
(...
4
votes
Sort lines in a string
Here is one possible way to implement this using a temporary buffer:
(defun sort-string (string &optional reverse)
"sorts an input string, using a temporary buffer"
;;(interactive "sto be ...
4
votes
Accepted
Set value of a variable to region text
This code should do what you want:
(setq your-variable (buffer-substring (region-beginning) (region-end)))
If you want a command, try this:
(defun my-set-var-to-selection (variable beg end)
"Set ...
4
votes
Accepted
How to stop backspace from doing kill-region?
The first backspace kills the whole region.
You'll want to set delete-active-region to nil (it was introduced in 24.1).
delete-backward-char is an interactive compiled Lisp function in ‘simple.el’.
[...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
region × 173mark × 30
key-bindings × 11
point × 10
faces × 9
search × 9
rectangle × 9
highlighting × 8
selection × 8
commands × 7
org-mode × 6
replace × 6
isearch × 6
interactive × 6
kill-ring × 6
buffers × 5
regular-expressions × 5
copy-paste × 5
mouse × 5
narrowing × 5
text-editing × 4
shell-command × 4
motion × 4
insert × 4
multiple-cursors × 4